Log4j 2 Compatibility with Log4j 1
Log4j 2 provides support for the Log4j 1 logging methods by providing alternate implementations of the classes containing those methods. These classes may be found in the log4j-1.2-api jar distributed with the project. All calls to perform logging will result in the data passed to the logging methods to be forwarded to the Log4j2 API where they can be processed by implementations of the Log4j 2 API.
Log4j 2 provides experimental support for Log4j 1 configuration files. Configuration of the Appenders, Layouts and Filters that were provided in the Log4j 1 distribution will be redirected to their Log4j 2 counterparts - with the exception of the implemented Rewrite Policies. This means that although the while the behavior of these components will be similar they may not be exactly the same. For example, the XML generated by the XMLLayout may not exactly match the XML generated by the Log4j 1XMLLayout.
In addition, Log4j 2 supports custom Log4j 1 Appenders, Filters, and Layouts with some constraints. Since the original Log4j 1 components may not be present in Log4j 2, custom components that extend them will fail.
As support for Log4j 1 is an experimental feature one of the following steps must be taken to enable it:
- Set the system property “log4j1.compatibility” to a value of “true”. Log4j 2 will then add log4j.properties, log4j-test.properties, log4j.xml and log4j-test.xml to the configuration files it searches for on the class path.
- Set the Log4j 1 system property “log4j.configuration” to the location of the log4j 1 configuration file. The files must have a file extension of either “.properties” or “.xml”.
- RewriteAppender (limited)
- JDBCAppender (cannot be mapped to Log4j 2’s JdbcAppender)
- SocketAppender (Requires the use of the SerializedLayout which is a security risk)
- SocketHubAppender (Requires the use of the SerializedLayout which is a securiy risk)
- TelnetAppender (Security risk)
- Custom rewrite policies since LoggingEvent is currently a no-op.
Log4j 2 currently will ignore renderers.