Migrating from Log4j 1.xUsing the Log4j 1.x bridgePerhaps the simplest way to convert to using Log4j 2 is to replace the log4j 1.x jar file with Log4j 2's log4j-1.2-api.jar. However, to use this successfully applications must meet the following requirements:
Converting to the Log4j 2 APIFor the most part, converting from the Log4j 1.x API to Log4j 2 should be fairly simple. Many of the log statements will require no modification. However, where necessary the following changes must be made.
Configuring Log4j 2Although the Log4j 2 configuration syntax is different than that of Log4j 1.x, most, if not all, of the same functionality is available. Below are the example configurations for Log4j 1.x and their counterparts in Log4j 2. Sample 1 - Simple configuration using a Console AppenderLog4j 1.x XML configuration
Log4j 2 XML configuration
Sample 2 - Simple configuration using a File AppenderLog4j 1.x XML configuration
Log4j 2 XML configuration
Sample 3 - SocketAppenderLog4j 1.x XML configuration. This example from Log4j 1.x is misleading. The SocketAppender does not actually use a Layout. Configuring one will have no effect.
Log4j 2 XML configuration
Sample 4 - AsyncAppenderLog4j 1.x XML configuration using the AsyncAppender.
Log4j 2 XML configuration.
Sample 5 - AsyncAppender with Console and FileLog4j 1.x XML configuration using the AsyncAppender.
Log4j 2 XML configuration. Note that the Async Appender should be configured after the appenders it references. This will allow it to shutdown properly.
|