gpt4 book ai didi

java - StatusLogger 发现多个日志记录实现

转载 作者:太空宇宙 更新时间:2023-11-04 09:26:23 24 4
gpt4 key购买 nike

在使用 log4j 和 slf4j 的应用程序中,我尝试使用依赖于 log4j2 的 elasticsearch jar。

应用程序的日志依赖关系如下所示-

    <dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
<version>1.7.25</version>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-log4j12</artifactId>
<version>1.7.25</version>
</dependency>
<dependency>
<groupId>log4j</groupId>
<artifactId>log4j</artifactId>
<version>1.2.17</version>
</dependency>

该应用程序正在使用自己的 log4j.xml 并具有一些 log4j 的自定义附加程序,因此如果不重写附加程序就无法将其迁移到 log4j2。

按照elasticsearch documentation中的建议添加了以下依赖项使用 log4j2 以外的其他记录器。

    <dependency>
<groupId>org.elasticsearch</groupId>
<artifactId>elasticsearch</artifactId>
<version>${es.version}</version>
</dependency>
<dependency>
<groupId>org.elasticsearch.client</groupId>
<artifactId>transport</artifactId>
<version>${es.version}</version>
</dependency>
<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-to-slf4j</artifactId>
<version>2.11.1</version>
</dependency>

但现在启动应用程序时,我看到一些如下警告

DEBUG StatusLogger org.slf4j.helpers.Log4jLoggerFactory is not on classpath. Good!
DEBUG StatusLogger Using ShutdownCallbackRegistry class org.apache.logging.log4j.core.util.DefaultShutdownCallbackRegistry
WARN StatusLogger Multiple logging implementations found:
Factory: org.apache.logging.log4j.core.impl.Log4jContextFactory, Weighting: 10
Factory: org.apache.logging.slf4j.SLF4JLoggerContextFactory, Weighting: 15
Using factory: org.apache.logging.slf4j.SLF4JLoggerContextFactory

有人可以告诉我这个警告代表什么吗?我怎样才能删除它?

最佳答案

这已在 log4j2 mailing list 中得到解答

I think what you are trying to say is

  1. Your app needs to use Log4J 1.x.
  2. You are trying to include something that is using the Log4J 2 api.

The problem you are encountering is that you have provided 2implementations of the Log4J api - log4j-to-slf4j and log4j-core. Youcan only have one of them. You need to exclude the Log4J core jar fromwhatever is declaring it as a dependency.

On another note, converting Log4J 1 appenders to Log4J 2 isn’tparticularly hard. Log4J 1 hasn’t been maintained in many years andwas declared end-of-life 4 years ago.

Ralph

关于java - StatusLogger 发现多个日志记录实现,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57657475/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com