Logger components :
Logger
- Gathers the events associated to it
- Verifies that these events are suitable to be logged( right logging level, filters)
- Passes them to the appropriate appender to be formatted (layout) and written to the appropriate target.
Filter
- Allows log events to be evaluated according to some conditions.
- For log4j2 it can be set at four levels :
- Context wide
- Logger
- Appender
- Appender reference(determine if a log event should be routed to another)
Log events
- Contains information that will be used for logging such as :
- Message
- Level
- Timestamp
- Name of logger
- Location
- Thread name
Layout
- Objects used for formatting log events
- Returns an array of bytes-> most layouts should have the Charset property set
Appender
- Has the responsibility of delivering log events to the appropriate target.
- These objects can wrap other appenders to route the log events to them.
Log4j2 new stuff:
- Requires at least java 6
- Filters at every level
- Removing the need for verifying if the logging level is enabled or disabled
- Message is saved as array of bytes, not as String
- Async Appenders and Loggers
- Requires disruptor.jar(lock free inter-thread communication library) and log4jContextSelector set (Log4jContextSelector=org.apache.logging.log4j.core.async.AsyncLoggerContextSelector)
- Can be used both async loggers and sync loggers in the same configuration
- Benefits : lower latency, higher throughput(6-68 times more messages than the sync logger), flush the disk at the end of a batch.
- Drawbacks : exceptions occurring during the logging process are lost
- Plugins :
- annotations are used to define new filters, appenders, loggers, layouts
- Json and xml configuration files, reconfiguration using jconsole and GUI client
- To configure log4j using json files, the following jars are needed :
- jackson-core-2.2.1.jar
- jackson-databind-2.2.1.jar
- Log4j2 vs Log4j1 vs Logback performance
Niciun comentariu:
Trimiteți un comentariu