Using Log4j 1.2 Bridge with Log4j 2 API

Q

How can I run my application with both Apache Log4j 2 API and Log4j 1.2 API? My program has two parts, one part uses the new Log4j 2 API, but the other part uses the old Log4j 1.2 API.

✍: FYIcenter.com

A

The Apache Log4j 2 package comes with the Log4j 1.2 Bridge module to allow you run programs that use both Log4j 2 API and Log4j 1.2 API.

When you run your program, you need to include these JAR files in the classpath:

  • log4j-api-2.x.jar - Provides the Log4j 2 API.
  • log4j-core-2.x.jar - Provides the implementation of Log4j 2 API.
  • log4j-1.2-api-2.x.jar - Provides the bridge converting Log4j 1.2 API to Log4j 2 API.

Warning, you should not include log4j-1.2.x.jar in the classpath. Log4j 1.2 API calls will be handled by log4j-1.2-api-2.x.jar.

The picture belows shows you the JAR dependency diagram of your application and Log4j JAR files.

Using Log4j 1.2 Bridge with Log4j 2 API
Using Log4j 1.2 Bridge with Log4j 2 API

 

Trace Logging on Apache Log4j API

Running Program with Apache Log4j Configuration

Using Apache Log4j in Java Programs

⇑⇑ FAQ for Apache Log4j

2022-12-22, 13065🔥, 2💬