Advantages of Log4j2 over Log4j | Log4j vs Log4j 2

If you’re not using Log4j 2, this is what you’re missing out on:

  • Improved reliability. Messages are not lost while reconfiguring the framework like in Log4j 1 or Logback
  • Extensibility: Log4j 2 supports a plugin system to let users define and configure custom components
  • Simplified configuration syntax, with support for XML, JSON, YAML and properties configurations
  • Improved Filters which can be defined globally or on any configuration element to give you fine-grained control over which log messages should be processed by which Loggers and Appenders.
  • Property lookup support for values defined in arbitrary places including, but not limited to, the configuration file, system properties, environment variables, the application container, the ThreadContext Map, and other attributes of the log event
  • Support for multiple APIs: Log4j 2 can be used with applications using the Log4j 2, Log4j 1.2, SLF4J, Commons Logging and java.util.logging (JUL) APIs
  • Custom Log Levels
  • Java 8-style lambda support for “lazy logging”
  • Markers
  • Support for user-defined Message objects
  • Garbage-free or low garbage” in common configurations
  • Improved speed overall. Worth mentioning especially is the performance of the Asynchronous Loggers. Log4j 2 makes use of the LMAX Disruptor. The library reduces the need for kernel locking and increases the logging performance by a factor 12. For example, in the same environment Log4j 2 can write more than 18,000,000 messages per second, whereas other frameworks like Logback and Log4j 1 just write up to 2,000,000 messages per second.