java 使用 Logback 但 Log4j 开始显示 WARN no Appenders
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/14325508/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Using Logback but Log4j started displaying WARN no Appenders
提问by Chris Watts
I am using logback for my logging and it has been working however; the other day I started getting a warning
我正在使用 logback 进行日志记录,但是它一直在工作;前几天我开始收到警告
log4j:WARN No appenders could be found for logger (org.apache.axis.i18n.ProjectResourceBundle). log4j:WARN Please initialize the log4j system properly.
log4j:WARN 找不到记录器 (org.apache.axis.i18n.ProjectResourceBundle) 的附加程序。log4j:WARN 请正确初始化 log4j 系统。
I am not using log4j nor have I ever with this project. I have a logback.xml in my resources folder.
我没有使用 log4j,也没有使用过这个项目。我的资源文件夹中有一个 logback.xml。
Any ideas on why this warning started to show up?
关于为什么这个警告开始出现的任何想法?
采纳答案by theadam
You must be using a library that does use log4j. Can you post anything more about your project?
您必须使用确实使用 log4j 的库。你能发布更多关于你的项目的信息吗?
You should probably just put log4j bridge on the classpath. Read more here: http://www.slf4j.org/legacy.html
您可能应该将 log4j 桥放在类路径上。在此处阅读更多信息:http: //www.slf4j.org/legacy.html
The jar you want to look into is log4j-over-slf4j. It will bridge log4j API to actually make calls to your implementation of slf4j API (in your case - logback).
您要查看的 jar 是 log4j-over-slf4j。它将桥接 log4j API 以实际调用您的 slf4j API 实现(在您的情况下 - logback)。
If you are using Maven to build your project then it might be as simple as putting
如果您使用 Maven 来构建您的项目,那么它可能就像放置一样简单
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>log4j-over-slf4j</artifactId>
<version>1.7.7</version>
</dependency>
in dependencies.
在依赖项中。
Excluding a library (if needed) would be done in this fashion (this assumes we are talking about the transitive dependency from the jar you've mentioned):
排除库(如果需要)将以这种方式完成(假设我们正在谈论您提到的 jar 的传递依赖):
<dependency>
<groupId>org.swift.common</groupId>
<artifactId>jira-soap</artifactId>
<version>4.4.0</version>
<exclusions>
<exclusion>
<groupId>...</groupId>
<artifactId>...</artifactId>
</exclusion>
</exclusions>
</dependency>
回答by Avec
Took me some time to find out since the message was log4j:WARN No appenders could be found for logger
由于消息是 log4j:WARN No appender can be found for logger
I tried to exclude log4j and I tried the log4j-over-slf4j.
我试图排除 log4j,我尝试了 log4j-over-slf4j。
Then I ran mvn dependency:tree and finally found out that mye commons-configuration actually was using commons-logging
然后我运行了 mvn dependency:tree ,最后发现 mye commons-configuration 实际上是在使用 commons-logging
[INFO] +- commons-configuration:commons-configuration:jar:1.9:compile
[INFO] | \- commons-logging:commons-logging:jar:1.1.1:compile
[INFO] +- ch.qos.logback:logback-classic:jar:1.0.13:compile
[INFO] | +- ch.qos.logback:logback-core:jar:1.0.13:compile
[INFO] | \- org.slf4j:slf4j-api:jar:1.7.5:compile
[INFO] +- org.slf4j:log4j-over-slf4j:jar:1.7.6:compile
[INFO] \- org.apache.commons:commons-lang3:jar:3.1:compile
This became the solution for me.
这成为我的解决方案。
<!-- logging with logback (and slf4j)-->
<dependency>
<groupId>ch.qos.logback</groupId>
<artifactId>logback-classic</artifactId>
<version>1.0.13</version>
</dependency>
<!-- had a dep in commons-configuration -->
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>jcl-over-slf4j</artifactId>
<version>1.7.6</version>
</dependency>