更新log4j版本1.2版本到2.16.0或更高版本

huangapple go评论70阅读模式
英文:

updating log4j version 1.2 version to 2.16.0 or later

问题

To update the log4j version from 1.2 to 2.16 or higher, you can modify your pom.xml file as follows:

<dependency>
    <groupId>org.apache.logging.log4j</groupId>
    <artifactId>log4j-api</artifactId>
    <version>2.17.1</version>
</dependency>
<dependency>
    <groupId>org.apache.logging.log4j</groupId>
    <artifactId>log4j-core</artifactId>
    <version>2.17.1</version>
</dependency>

It seems you've already done this correctly. If it's not working, make sure you've saved the changes in your pom.xml file and try rebuilding your project. There's no need to add a separate dependency for "log4j" since "log4j-core" includes it.

英文:

How do I update the log4j version from 1.2 to 2.16 or higher? This is what I have in my pom.xml file right now(using maven) for job4j-api and job4j-core but nothing for just job4j

        &lt;dependency&gt;
            &lt;groupId&gt;org.apache.logging.log4j&lt;/groupId&gt;
            &lt;artifactId&gt;log4j-api&lt;/artifactId&gt;
            &lt;version&gt;2.17.1&lt;/version&gt;
        &lt;/dependency&gt;
        &lt;dependency&gt;
            &lt;groupId&gt;org.apache.logging.log4j&lt;/groupId&gt;
            &lt;artifactId&gt;log4j-core&lt;/artifactId&gt;
            &lt;version&gt;2.17.1&lt;/version&gt;
        &lt;/dependency&gt;

I can see their current versions and that it is not updated in the shell view
here. I tried adding the following snippet

 &lt;dependency&gt;
            &lt;groupId&gt;org.apache.logging.log4j&lt;/groupId&gt;
            &lt;artifactId&gt;log4j&lt;/artifactId&gt;
            &lt;version&gt;2.17.1&lt;/version&gt;
        &lt;/dependency&gt;

but didn't seem to work. Do i need to update the jar file somehwere? Any hints would be highly appreciated. Thanks.

答案1

得分: 0

第一个配置是正确的,您可以查看从 log4j 1 迁移到 log4j 2 的迁移指南,以继续迁移:https://logging.apache.org/log4j/2.x/manual/migration.html

在使用依赖项 log4j:12.13 时,您应该升级、删除或排除 logkit 和 search。

英文:

The first configuration is correct you can see the guide of migration from log4j 1 to log4j 2 to continue the migration : https://logging.apache.org/log4j/2.x/manual/migration.html

Add you should upgrade,delete or exclude the logkit and search when you use the dependency log4j:12.13

答案2

得分: 0

仅仅添加log4j2的依赖不会消除对log4j1的依赖。您还需要从您的pom文件中移除该依赖。

如果您没有明确添加它,它可能作为一种传递性依赖存在,并由其他某些东西注入。您需要找出是什么引入了这个依赖,并在它上面添加一个排除log4j的设置(然后希望它仍然正常工作,有一些方法可以代理log4j2以使用log4j1的API,但这不是自动的。请在文档中搜索相关信息)。

英文:

Merely adding a dependency on log4j2 won't get rid of the dependency on log4j1. You also need to remove that dependency from your pom.

If you didn't add it explicitly, it's there as a transient dependency and being injected by something else. You'll need to figure out what that something else is, and add an exclusion of log4j to it (and then hope it still works, there are ways to proxy log4j2 to be accessible using log4j1 APIs but it's not automatic. Search for it in the documentation).

huangapple
  • 本文由 发表于 2023年5月30日 07:34:35
  • 转载请务必保留本文链接:https://go.coder-hub.com/76360828.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定