Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Mixing log4j 1.x and log4j 2 with third party libraries dependending on log4j 1.x

I'm maintaining a Maven project that uses log4j 1.x with a large codebase. Not only is log4j 1.x used in existing code, it is also used by some third party libraries on which the project depends.

I want to start using log4j 2 now, but I wonder if it is worth the hassle.

I know it is possible to mix the two (cf. Mixing log4j 1.x and log4j 2) but what about the third party libraries that depend on log4j 1.x, I'm afraid there will be conflicts.

So should I rather stick to log4j 1.x or risk a dependency hell by upgrading to log4j 2?

like image 631
Roland Avatar asked Feb 27 '17 08:02

Roland


People also ask

Can we use Log4j and Log4j2 together?

API CompatibilityLog4j 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.

Is Log4j 2 backwards compatible?

Log4j2 is backwards compatible if you add the log4j1 compatibility library. My web-inf\lib has: slf-api. log4j-1.2-api (backwards compat.

Is Log4j 1 x still supported?

Log4j 1. x has reached End of Life in 2015 and is no longer supported. Vulnerabilities reported after August 2015 against Log4j 1. x were not checked and will not be fixed.


2 Answers

I've done so myself. I don't think there will be any issue. Even the project I did for had third party libraries.

You can use log4j-1.2-api-2.x.jar simply. Remove your older log4j-1.2.x.jar and replace with below three jars:

  1. log4j-1.2-api-2.x - will handle third party libraries depending on older log4j version.
  2. log4j-api-2.x.jar
  3. log4j-core-2.x.jar

Moreover, for your own code, you can follow migration steps to start using log4j2 api and third party libraries will continue using bridge between older and newer version that is log4j-1.2-api-2.x.jar (aka log4j 1.x bridge)

Below is the official documentation:

Migrate from log4j-1.x to log4j-2

like image 180
Nitin Bhojwani Avatar answered Nov 14 '22 23:11

Nitin Bhojwani


It seems that perhaps the naming has changed since @Nitin answered the question. According to the log4j site, the Maven dependency is:

<dependencies>
  <dependency>
    <groupId>org.apache.logging.log4j</groupId>
    <artifactId>log4j-1.2-api</artifactId>
    <version>2.2</version>
  </dependency>
</dependencies>
like image 31
Nic Cottrell Avatar answered Nov 14 '22 21:11

Nic Cottrell