您的位置 首页 golang

从log4j2的角度看golang的zap

本文主要从log4j2的角度对zap做一下小结

从log4j2的角度看golang的zap

log4j2

配置

从配置文件上看,分为如下几个部分:

  • properties
  • appenders filter pattern layout mdc policies SizeBasedTriggeringPolicy TimeBasedTriggeringPolicy rollover strategy
  • loggers root logger async logger async root

使用

在使用上主要是考虑几点:

  • log的输入 mdc的输入 kv结构的输入 tracing注入
  • log的输出 输出格式 json格式 指定pattern layout 输出方式 同步 异步 输出地方 console file kafka/logstash等
  • log文件 如何rolling 如何压缩 如何按level分文件输出

zap

  • zap貌似没有文件配置,都是通过api进行配置
  • zap要自定义layout的话,需要自己定制encoder,zap默认支持json格式 zap可以使用logger的With方法添加全局的field;也可以使用Info之类方法提供的Field参数动态添加field;后者可以结合golang的context衍生出类似log4j2的mdc的效果
  • zap的输出使用的是Sink/WriteSyncer,比如要输出到elasticsearch或者mq之类,可以自定义一个sink;zap默认支持console、file输出 对于log文件的压缩以及rolling之类,zap可以借助lumberjack作为WriteSyncer来实现 对于日志级别的过滤,可以借助levelFilterCore;如果要按level分文件,可以结合levelFilterCore创建不同level的core,然后通过zapcore.NewTee来衔接 如果想要同时输出到多种不同的地方,可以使用zapcore.NewMultiWriteSyncer来包装成一个新的core

小结

zap目前貌似没有类似log4j2的async的log,针对layout需要自己定制encoder,针对输出需要自己定制Sink/WriteSyncer,要同时输出到多种不同的地方,可以使用zapcore.NewMultiWriteSyncer来包装成一个新的core。

doc

  • zap

文章来源:智云一二三科技

文章标题:从log4j2的角度看golang的zap

文章地址:https://www.zhihuclub.com/98050.shtml

关于作者: 智云科技

热门文章

评论已关闭

32条评论

  1. The effect of ShenQi FuZheng injection in combination with chemotherapy versus chemotherapy alone on the improvement of efficacy and immune function in patients with advanced non small cell lung cancer A meta analysis Relajante uterino Relajante uterino Relajante uterino

  2. 971581274826 cytotec misoprostol dubai sharjah ajman abu dhabi Cytotec in abu dhabi 971581274826 Abortion Pills Cytotec Available In Dubai Uae 971581274826 Quality Abortion services provided by specialists

  3. The modulators vinblastine, mefloquine, and tamoxifen thus appear to co operate with one another in pairs to bring about reversal of P glycoprotein

  4. The evidence supports higher rates of breast conserving therapy with the use of a preoperative anthracycline chemotherapy regimen than with postoperative use, but no improvement in survival was noted with the preoperative strategy

  5. Australia will be running this cycle for 8 weeks, first 6 weeks australia Dbol, then finish out the online 2 weeks with just the test cycle Epub 2004 May 21

  6. Many testing companies and labs now have associated genetic counselors, and there are some independent companies offering telephone counseling services

  7. Oral penicillin, amoxicillin, ampicillin, and oral cephalosporins and penicillins have not been shown to interact with warfarin

  8. MAC values are taken largely from the list of the ACGIH, as well as from the Federal Republic of Germany and NIOSH And on the opposite side of things, if they have very low risk, then you can just say, You know, maybe you re the one who should stop because maybe your benefit is not outweighing your risk from the treatment

  9. He eventually moved to Sparta Prague, where his 10 goals during the 2009 10 season helped the Czech side win the league for the first time since 2007

  10. A common variant of HMGA2 is associated with adult and childhood height in the general population

  11. Patients with primarily gastrointestinal GI complaints may benefit from a consultation with a gastroenterologist to rule out a primary GI source prior to surgical exploration

  12. Certainly, the Sertoli cell population determines the efficiency of spermatogenesis 110, and there is a strong correlation between the number of Sertoli cells, the number of germ cells interacting with them, sperm production and finally the testicular volume cephalexin will decrease the level or effect of pyridoxine by altering intestinal flora

  13. 122 c, there are limitations on requesting or requiring genetic testing PCR amplifying repetitive nematode DNA sequences taken from skin snips reveals greater sensitivity in patients with low infection level Fink et al

  14. The DOSE AHF reassures us that high dose intravenous furosemide versus low dose regimen shows no differences in renal function over 60 days; rather, the former strategy offers greater diuresis without any significant renal impairment 43

  15. Various immune cells are frequently found accummulated in tumors relative to the surrounding tissue Immediately after the scratching and media addition, the wounds were imaged using the Cytation 5

  16. Our overall findings demonstrate that miR 486 overexpression in skeletal muscle can delay or prevent many of the histological, biochemical, and physiological deficits associated with dystrophin deficiency in mice

  17. com 20 E2 AD 90 20Acquisto 20Viagra 20San 20Marino 20 20Arginina 20E 20Viagra 20Insieme acquisto viagra san marino I ve given 12 years in every single department of the club, skills development coach in the academy, reserve team, technical coach for individual first team players and then as a first team coach 6 reduction in tumor weight as compared to monotherapy with 1

  18. Smith ML, Ory MG, Ahn S, Bazzarre TL, Resnick B Staged excision has become the option of choice for many authors

  19. Similar to our study they found the DCIS Score showed correlation with grade but concluded that the DCIS score provided recurrence risk information independent of these features

  20. Photos and descriptions of the items are available now on the SOT Thoracentesis is frequently performed in ICU patients for evaluating pleural fluid, and bleeding associated with thoracentesis is usually minor and resolves without further interventions

网站地图