我的应用程序日志记录有问题。应用程序使用 slf4j 和 logback 机制来实现日志记录。
Logger 被初始化为
private static final Logger LOG = LoggerFactory.getLogger(Classname.class);
但有些它无法生成日志。调试时发现错误
SLF4J: Class path contains multiple SLF4J bindings.
SLF4J: Found binding in [jar:file:/Users/xxx/.m2/repository/org/slf4j/slf4j-log4j12/1.7.5/slf4j-log4j12-1.7.5.jar!/org/slf4j/impl/StaticLoggerBinder.class]
SLF4J: Found binding in [jar:file:/Users/xxx/.m2/repository/ch/qos/logback/logback-classic/1.0.13/logback-classic-1.0.13.jar!/org/slf4j/impl/StaticLoggerBinder.class]
SLF4J: See http://www.slf4j.org/codes.html#multiple_bindings for an explanation.
SLF4J: Actual binding is of type [org.slf4j.impl.Log4jLoggerFactory]
然后我尝试从应用程序所在的父 pom.xml 文件中删除 slf4j-log4j12 绑定(bind)。但仍然无法生成日志。
然后我在应用程序 iml 文件中找到了以下条目
<orderEntry type="library" scope="RUNTIME" name="Maven: org.slf4j:slf4j-log4j12:1.7.5" level="project" />
当我删除该条目时,我的应用程序能够生成日志...目前我没有任何线索可以使用哪个文件作为引用生成 iml 文件?因此,如果我需要将 slf4j-log4j12 排除在我的项目中之外,我应该在 pom.xml 中将其删除吗?
即使我在 pom.xml 中删除它也不会生成日志?
请告诉我如何解决未生成日志的问题。
最佳答案
首先,您走在正确的轨道上。您需要使用 POM 来排除 slf4j-log4j12 和 commons-logging。
iml文件是Intelli生成的,需要获取intellij重新导入pom更新依赖。最好的办法是将 intellij 设置为在 pom.xml 更改时始终自动重新导入。
关于java - ch.qos.logback.classic 和 slf4j-log4j12,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24597408/