slf4j找不到log4j2jar

vsdwdz23  于 2021-07-03  发布在  Java
关注(0)|答案(1)|浏览(351)

我知道使用slf4j和log4j2作为记录器实现应该很容易。
您只需要将jar添加到类路径。
我本以为我是这样做的,但我仍在努力

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 ```

org.slf4j
slf4j-api
1.7.30


org.apache.logging.log4j
log4j-slf4j18-impl
2.14.0
runtime


org.apache.logging.log4j
log4j-api
2.14.0
runtime


org.apache.logging.log4j
log4j-core
2.14.0
runtime

然后是 `.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文件吗?
但我没有得到相应的错误信息。
我正在使用
eclipse版本:2020-09(4.17.0)
apache maven 3.6.3版
以及 maven-war-plugin ```

maven-war-plugin
3.2.3

WebContent

false

gc0ot86w

gc0ot86w1#

这是因为你正在使用 slf4j 1.7.* 但你用的是 logj4j-slf4j18-impl 假设与slf4j 1.8(尚未发布或更改为2.0.0版本,目前为alpha版本)一起使用。你需要从

<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兼容

相关问题