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

Rol*_*and 5 java logging log4j maven log4j2

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.

那么我应该坚持使用 log4j 1.x 还是通过升级到 log4j 2 冒依赖地狱的风险?

Nit*_*ani 5

我自己也是这样做的。我不认为会有任何问题。甚至我做的项目也有第三方库。

您可以简单地使用 log4j-1.2-api-2.x.jar。删除旧的 log4j-1.2.x.jar 并替换为以下三个 jar:

  1. log4j-1.2-api-2.x - 将根据旧的 log4j 版本处理第三方库。
  2. log4j-api-2.x.jar
  3. log4j-core-2.x.jar

此外,对于您自己的代码,您可以按照迁移步骤开始使用 log4j2 api,第三方库将继续使用旧版本和新版本之间的桥接器,即 log4j-1.2-api-2.x.jar(又名 log4j 1.x 桥接器) )

下面是官方文档:

从 log4j-1.x 迁移到 log4j-2