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

梦想与她 提交于 2020-03-19 06:30:31

问题


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?


回答1:


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




回答2:


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>


来源:https://stackoverflow.com/questions/42480824/mixing-log4j-1-x-and-log4j-2-with-third-party-libraries-dependending-on-log4j-1

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!