6

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?

Community
  • 1
  • 1
Roland
  • 7,525
  • 13
  • 61
  • 124
  • 1
    Only you can weigh the pro's of log4j 2 vs the con's of *"dependency hell"*. We may all have opinions about that, but we don't know you project and requirements. Voting to close as "primarily opinion-based". – Andreas Feb 27 '17 at 08:35
  • @Andreas Objectively speaking: is it possible for my project to depend on log4j 2 and third party libraries on log4j 1.x without giving a conflict? This is not a matter of opinion but of fact, no? – Roland Feb 27 '17 at 08:57
  • 1
    It is a matter of fact, that if you read the answer to the question you linked, and the documentation of the Log4j 1 to Log4j 2 bridge, you'd already know that the bridge will redirect all Log4j 1 calls to the Log4j 2 implementation, because that is what a bridge does. As long as you *exclude* any actual Log4j 1 implementation, there will be no conflict. Whether the *"dependency hell"* of excluding Log4j 1 is worth the features of Log4j 2, is for you to decide, as already stated, and is entirely opinion-based. – Andreas Feb 27 '17 at 09:01

2 Answers2

7

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

Nitin Bhojwani
  • 702
  • 1
  • 5
  • 14
1

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>
Nic Cottrell
  • 9,401
  • 7
  • 53
  • 76