Apache Log4j 2 is a logging framework designed for Java applications. According to the vendor, it offers a comprehensive set of features and capabilities that cater to the logging needs of various businesses across different industries. The software development, information technology, financial services, e-commerce, and telecommunications sectors are some examples of the industries that Log4j 2 is said to serve.
Key Features
API Separation: Log4j API is separate from the implementation, allowing developers to use it with Log4j or other logging implementations. According to the vendor, it supports logging Messages and lambda expressions, provides more logging methods than SLF4J, and supports java.text.MessageFormat syntax and printf-style messages.
Improved Performance: Log4j 2 contains Asynchronous Loggers based on the LMAX Disruptor library, which, according to the vendor, offers higher throughput and lower latency in multi-threaded scenarios. The vendor claims that it outperforms Log4j 1.x, Logback, and java.util.logging in multi-threaded applications, providing significant performance improvements.
Support for multiple APIs: According to the vendor, Log4j 2 API provides the best performance and supports Log4j 1.2, SLF4J, Commons Logging, and java.util.logging APIs. The vendor states that applications can use any SLF4J-compliant library as their logger implementation with the log4j-to-slf4j adapter.
Automatic Reloading of Configurations: Log4j 2 can automatically reload its configuration upon modification without losing log events, according to the vendor. Configuration reloading takes place without interrupting logging.
Advanced Filtering: Log4j 2 supports filtering based on context data, markers, regular expressions, and other components in the Log event, according to the vendor. Filtering can be applied to all events before being passed to Loggers or as they pass through Appenders. Filters can also be associated with Loggers, allowing the use of a common Filter class in various circumstances.
Plugin Architecture: Log4j uses the plugin pattern to configure components, eliminating the need to write code for creating and configuring components, according to the vendor. It recognizes plugins and uses them when referenced in the configuration.
Property Support: Log4j 2 allows referencing properties in the configuration file, system properties, environment variables, ThreadContext Map, and event data, as stated by the vendor. It supports dynamic resolution of properties by underlying components and allows users to customize property providers.
Java 8 Lambda Support: According to the vendor, Log4j 2 supports lambda expressions in log messages, which are only evaluated if the requested log level is enabled, reducing unnecessary message construction.
Custom Log Levels: Log4j 2 allows the definition of custom log levels in code or configuration without subclassing, according to the vendor.
Log Builder API: Log events can be constructed using a builder in addition to the various log methods in the Log4j API, according to the vendor.