sequence

This paper mainly summarizes ZAP from log4j2 perspective

log4j2

configuration

The configuration file is divided into the following parts:

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

use

In use, we mainly consider the following points:

  • The log of the input
    • The MDC’s input
    • Kv structure input
    • Tracing injection
  • The output of the log
    • The output format
      • Json format
      • Specifies the pattern layout
    • Output way
      • synchronous
      • asynchronous
    • Where the output
      • console
      • file
      • Kafka/logstash, etc
  • The log file
    • How to rolling
    • How to compress
    • How to output files by level

zap

  • Zap seems to have no file configuration, all through the API configuration
  • To customize layout for ZAP, you need to customize encoder. Zap supports JSON format by default
    • Zap can add a global field using logger’s With method; You can also add fields dynamically using the Field parameter provided by methods like Info; The latter can be combined with golang’s context to derive an effect similar to log4j2’s MDC
  • Zap output uses Sink/WriteSyncer. For example, to export to ElasticSearch or MQ, you can specify a Sink. Zap supports console and file output by default
    • Zap can use LumberJack as WriteSyncer for compression of log files and things like Rolling
    • For log level filtering, you can use levelFilterCore. If you want to separate files by level, you can combine levelFilterCore with levelFilterCore to create different levels of core and then use zapcore.newtee to connect them
    • If you want the output to a variety of different places at the same time, can use zapcore. NewMultiWriteSyncer to packaged into a new core

summary

Zap currently seems to have no async log similar to log4j2. Encoder needs to be customized for layout, Sink/WriteSyncer needs to be customized for output, and output to a variety of different places at the same time. Can use zapcore. NewMultiWriteSyncer to packaged into a new core.

doc

  • zap