slf4j找不到log4j2罐子 [英] slf4j does not find log4j2 jars
问题描述
我知道将 SLF4J 与Log4j2作为记录器实现一起使用应该很容易.
I know it should be easy to use SLF4J with Log4j2 as logger implementation.
您只需要将jar添加到类路径中即可.
You just need to add the jars to the classpath.
我以为我这样做了,但是我还是得到了
I have thought that I did so, but I am still getting
INFO: At least one JAR was scanned for TLDs yet contained no TLDs. Enable debug logging for this logger for a complete list of JARs that were scanned but no TLDs were found in them. Skipping unneeded JARs during scanning can improve startup time and JSP compilation time.
SLF4J: Failed to load class "org.slf4j.impl.StaticLoggerBinder".
SLF4J: Defaulting to no-operation (NOP) logger implementation
SLF4J: See http://www.slf4j.org/codes.html#StaticLoggerBinder for further details.
我的 pom.xml
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
<version>1.7.30</version>
</dependency>
<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-slf4j18-impl</artifactId>
<version>2.14.0</version>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-api</artifactId>
<version>2.14.0</version>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-core</artifactId>
<version>2.14.0</version>
<scope>runtime</scope>
</dependency>
然后摘录自 .classpath
<classpathentry kind="var" path="M2_REPO/org/slf4j/slf4j-api/1.7.30/slf4j-api-1.7.30.jar" sourcepath="M2_REPO/org/slf4j/slf4j-api/1.7.30/slf4j-api-1.7.30-sources.jar"/>
<classpathentry kind="var" path="M2_REPO/org/apache/logging/log4j/log4j-slf4j18-impl/2.14.0/log4j-slf4j18-impl-2.14.0.jar" sourcepath="M2_REPO/org/apache/logging/log4j/log4j-slf4j18-impl/2.14.0/log4j-slf4j18-impl-2.14.0-sources.jar"/>
<classpathentry kind="var" path="M2_REPO/org/apache/logging/log4j/log4j-api/2.14.0/log4j-api-2.14.0.jar" sourcepath="M2_REPO/org/apache/logging/log4j/log4j-api/2.14.0/log4j-api-2.14.0-sources.jar"/>
<classpathentry kind="var" path="M2_REPO/org/apache/logging/log4j/log4j-core/2.14.0/log4j-core-2.14.0.jar" sourcepath="M2_REPO/org/apache/logging/log4j/log4j-core/2.14.0/log4j-core-2.14.0-sources.jar"/>
然后,在 lib 文件夹中查找
$ find ./ -name "*slf4*.jar"
./target/my-app-0.0.1-SNAPSHOT/WEB-INF/lib/log4j-slf4j18-impl-2.14.0.jar
./target/my-app-0.0.1-SNAPSHOT/WEB-INF/lib/slf4j-api-1.7.30.jar
$ find ./ -name "*log4j*.jar"
./target/my-app-0.0.1-SNAPSHOT/WEB-INF/lib/log4j-slf4j18-impl-2.14.0.jar
./target/my-app-0.0.1-SNAPSHOT/WEB-INF/lib/log4j-api-2.14.0.jar
./target/my-app-0.0.1-SNAPSHOT/WEB-INF/lib/log4j-core-2.14.0.jar
我想念什么?
我是否需要添加一个log4j2 配置xml文件?但是我没有收到相应的错误消息.
What am I missing?
Do I need to add a log4j2 config xml file?But I do not get the corresponding error message.
我正在使用
- Eclipse 版本:2020-09 (4.17.0)
- Apache Maven 3.6.3
和 maven-war-plugin
<plugin>
<artifactId>maven-war-plugin</artifactId>
<version>3.2.3</version>
<configuration>
<warSourceDirectory>WebContent</warSourceDirectory>
<!-- https://stackoverflow.com/a/33390519/2092322 annotations instead of web.xml -->
<failOnMissingWebXml>false</failOnMissingWebXml>
</configuration>
</plugin>
推荐答案
这是因为您使用的是 slf4j 1.7.*
,但是您使用的是 logj4j-slf4j18-impl
假定与slf4j 1.8(尚未发布或更改为当前处于Alpha版本的2.0.0版本)一起使用.您需要更改
This is because you are using slf4j 1.7.*
but you using logj4j-slf4j18-impl
which suppose to be used with slf4j 1.8 (which doesn't released yet or change to version 2.0.0 which currently in alpha version).
You need to change from
<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-slf4j18-impl</artifactId>
<version>2.14.0</version>
<scope>runtime</scope>
</dependency>
到
<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-slf4j-impl</artifactId>
<version>2.14.0</version>
<scope>runtime</scope>
</dependency>
以使其与您在项目中使用的slf4j兼容
in order to make it compatible with slf4j that you used in your project
这篇关于slf4j找不到log4j2罐子的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!