Stack Overflow 社区您好,
我正在使用 Micronaut 4 和 Apache Beam 开发 Maven 项目,面临 SLF4J 日志记录问题。尽管我的依赖项中有
logback-classic
,但我遇到了标准 SLF4J 错误:
SLF4J: Failed to load class "org.slf4j.impl.StaticLoggerBinder".
SLF4J: Defaulting to no-operation (NOP) logger implementation
我尝试从各种依赖项中排除
org.slf4j
,但问题仍然存在。当我删除 beam-sdks-java-io-google-cloud-platform
时,日志记录可以正常工作,表明存在冲突。我还注意到类路径中的 slf4j-simple
,这可能是导致问题的原因。这是我的 pom.xml 的片段:
<dependency>
<groupId>org.apache.beam</groupId>
<artifactId>beam-sdks-java-io-google-cloud-platform</artifactId>
<version>${beam.version}</version>
</dependency>
可以从 https://github.com/j1cs/logback-error 克隆该项目。要运行该项目,请使用:
./mvnw mn:run -DskipTests=true
预期的日志输出应该是:
00:14:57.306 [main] INFO i.m.c.DefaultApplicationContext$RuntimeConfiguredEnvironment - Established active environments: [cli]
00:14:57.308 [main] INFO i.m.c.DefaultApplicationContext$BootstrapEnvironment - Established active environments: [cli]
00:14:57.328 [main] INFO i.m.context.DefaultBeanContext - Reading bootstrap environment configuration
有人可以提供有关解决此设置中的 SLF4J 实现冲突的见解或建议吗?
谢谢!
更换好:
<dependency>
<groupId>ch.qos.logback</groupId>
<artifactId>logback-classic</artifactId>
<scope>runtime</scope>
</dependency>
到
<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-slf4j-impl</artifactId>
<version>2.12.1</version>
<scope>runtime</scope>
</dependency>
并在
log4j2.xml
中添加 src/main/resources
现在我可以看到日志了。