Log4j2 New Features,Compare with Log4j and other Logging Framework

Log4j2 New Features

  • Java 8-style lambda support for lazy logging.
  • Log4j2 is garbage-free or least low-garbage since version 2.6
  • Log4j2 support configuration via XML, JSON, YAML, properties configuration files or programmatically.
  • Async Loggers – performance similar to logging switched off on multithreaded.
  • Concurrency improvements: log4j2 uses java.util.concurrent libraries to perform locking at the lowest level possible. Log4j-1.x has known deadlock issues.
  • Filtering: filtering based on context data,  regular expressions, markers and other components in the Log event. Filters can be associated with Loggers. You can use a common Filter class in any of these circumstances.
  • Custom Log Level
  • Plugin Architecture – easy to extend by building custom components
    Supported APIs: SLF4J, Commons Logging, Log4j-1.x and java.util.logging.

Why people are moving?

  • Community support: Log4j2 has an active community where question, answered, features are added and bugs are fixed.
  • Automatically reload it’s configuration upon modification without losing log events while reconfiguring.

Drawback

  • log4j 2.0 is very different than log4j 1.x, and the API is mostly incompatible.
  • Java 6 required for version 2.0 to 2.3. Java 7 is required for Log4j 2.4 and later.

Steps to upgrade Log4j1 to Log4j2

  1. add log4j2 dependency  log4j-api-2.6.2.jar and log4j-core-2.6.2.jar in your class path or pom.xml .
  2. Log4j2 looks for file log4j2.xml in config file. Add log4j2.xml file either in the class path or specify path with log4j configuration file system properties.
  3. To debug the log4j.xml configuration use in the beginning of configuration file.
  4. To add more configuration for Console, File and RollingFile appenders follow Log4j2 Tutorial and Configuration.

Comparison with other Logging Framework

Follow the below link to compare different logging framework on benchmark.

https://www.loggly.com/blog/benchmarking-java-logging-frameworks/

Advertisements

This site uses Akismet to reduce spam. Learn how your comment data is processed.