将log4j 1.x和log4j 2与依赖于log4j 1.x的第三方库混合 [英] Mixing log4j 1.x and log4j 2 with third party libraries dependending on log4j 1.x

查看:579
本文介绍了将log4j 1.x和log4j 2与依赖于log4j 1.x的第三方库混合的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在维护一个使用log4j 1.x和大型代码库的Maven项目. 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.

我现在想开始使用log4j 2,但是我想知道是否值得为之烦恼.

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

我知道可以将两者混合使用(请参见.混合log4j 1 .x和log4j 2 ),但是依赖log4j 1.x的第三方库又如何呢,恐怕会发生冲突.

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冒着依赖地狱的风险?

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.

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

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-将根据较旧的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网桥)

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)

以下是官方文档:

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

这篇关于将log4j 1.x和log4j 2与依赖于log4j 1.x的第三方库混合的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆