Apache has announced the release of its newest logging library for Java – Log4j 2.0. An adapter has been released for those with Log4j 1.x. Since the API for Log4j 2.0 uses Java 6 or higher versions of Java, it is not compatible with Log4j’s previous releases. With this adapter, the use of Log4j 1.x API will be allowed on applications. Adapters for Apache Commons Logging and SLF4J are also being offered.
Apache posted on their website new features that have been made for Log4j 2.0:
- API Separation ensures forward compatibility as well as makes it clear for application developers to identify which classes and methods to use.
- Performance is improved compared to Log4j 1.x. In multi-threaded scenarios, Log4j 2.0’s Asynchronous Loggers have ten times higher throughput and orders of magnitude lower latency than Log4j 1.x and Logback. In most instances, Log4j 2.0, like Logback, performs faster in critical areas than Log4j 1.x.
- Offers support for various APIs such as SLF4J and Common Logging APIs.
- Configurations will automatically reload and log events will not lose while reconfiguration is ongoing.
- With its advanced filtering, Log4j 2.0 supports filtering based on context data, markers, regular expressions, and other components in the Log event. Before filtering pass to Loggers or while passing through Appenders, it can now be specified to apply to all events. Filters can be associated with Loggers and also common Filter class can be used in any of these conditions.
- There is no need to write code as plugin pattern is used to configure components. Plugins are automatically recognized and used when configuration references them.
- By adding Lookup Plugin, users can customize property providers. With Log4j’s new feature, properties are now supported. Properties from values defined in the configuration file, system properties, environmental variables, the ThreadContext Map and date present in the event, can be referenced in a configuration, Log4j will replace them directly or pass them to underlying component that will resolve them.
Log4j 2.0 is now available for download and testing. You can download it here.