StatusLogger 发现多个日志记录实现
StatusLogger Multiple logging implementations found
在将 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
谁能告诉我这个警告是什么意思?我怎样才能删除它?
中得到解答
I think what you are trying to say is
- Your app needs to use Log4J 1.x.
- You are trying to include something that is using the Log4J 2 api.
The problem you are encountering is that you have provided 2
implementations of the Log4J api - log4j-to-slf4j and log4j-core. You
can only have one of them. You need to exclude the Log4J core jar from
whatever is declaring it as a dependency.
On another note, converting Log4J 1 appenders to Log4J 2 isn’t
particularly hard. Log4J 1 hasn’t been maintained in many years and
was declared end-of-life 4 years ago.
Ralph
在将 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
谁能告诉我这个警告是什么意思?我怎样才能删除它?
I think what you are trying to say is
- Your app needs to use Log4J 1.x.
- You are trying to include something that is using the Log4J 2 api.
The problem you are encountering is that you have provided 2 implementations of the Log4J api - log4j-to-slf4j and log4j-core. You can only have one of them. You need to exclude the Log4J core jar from whatever is declaring it as a dependency.
On another note, converting Log4J 1 appenders to Log4J 2 isn’t particularly hard. Log4J 1 hasn’t been maintained in many years and was declared end-of-life 4 years ago.
Ralph