问题描述
我正在维护一个Maven项目,该项目使用log4j 1.x和大型代码库.现有代码中使用的log4j 1.x不仅是由项目依赖的某些第三方库使用的.
我现在想开始使用log4j 2,但是我想知道这是否值得.
我知道可以混合两者(参见混合log4j 1 .x和log4j 2 )但是,依赖log4j 1.x的第三方库呢
所以我宁愿坚持log4j 1.x或通过升级到log4j 2?
来冒险地狱.推荐答案
我自己做了.我认为不会有任何问题. 甚至我为我为第三方图书馆做的项目.
您可以简单地使用log4j-1.2-api2.x.jar. 删除旧的log4j-1.2.x.jar,并替换为以下三罐:
- log4j-1.2-api-2.x-将根据旧的log4j版本处理第三方库.
- log4j-api2.x.jar
- log4j-core-2.x.jar
此外,对于您自己的代码,您可以按照迁移步骤开始使用log4j2 api和第三方库,将继续使用旧版本和较新版本(log4j-1.2-api-2.x.jar)之间的桥梁(aka log4j 1) .x桥)
以下是官方文件:
其他推荐答案
似乎自@nitin回答这个问题以来的命名也许发生了变化.根据 log4j site 依赖性是:
<dependencies> <dependency> <groupId>org.apache.logging.log4j</groupId> <artifactId>log4j-1.2-api</artifactId> <version>2.2</version> </dependency> </dependencies>
问题描述
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?
推荐答案
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:
- log4j-1.2-api-2.x - will handle third party libraries depending on older log4j version.
- log4j-api-2.x.jar
- 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
其他推荐答案
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>