[英]Singleton, startup and log4j initialization: No appenders could be found for logger
We wrote a simple class like this: 我们编写了一个像这样的简单类:
import org.apache.log4j.Logger;
[...]
@Singleton
@Startup
public class ContactFormScheduler {
private static final Logger log = Logger.getLogger(ContactFormScheduler.class);
[...] [...]
When we start server (WildFly 10.1.0) we got the following error: 启动服务器(WildFly 10.1.0)时,出现以下错误:
15:35:27,142 ERROR [stderr] (ServerService Thread Pool -- 58) log4j:WARN No appenders could be found for logger (com.test.ContactFormScheduler). 15:35:27,142错误[stderr](ServerService线程池-58)log4j:WARN找不到记录器(com.test.ContactFormScheduler)的附加程序。
15:35:27,143 ERROR [stderr] (ServerService Thread Pool -- 58) log4j:WARN Please initialize the log4j system properly. 15:35:27,143错误[stderr](ServerService线程池-58)log4j:WARN请正确初始化log4j系统。
Any hints? 有什么提示吗? What's the best way to initialize log4j?
初始化log4j的最佳方法是什么?
In web.xml: 在web.xml中:
<context-param>
<param-name>log4j-config-location</param-name>
<param-value>/WEB-INF/log4j.properties</param-value>
</context-param>
in jboss-deployment-structure.xml 在jboss-deployment-structure.xml中
<jboss-deployment-structure xmlns="urn:jboss:deployment-structure:1.2">
<deployment>
<!-- Exclusions allow you to prevent the server from automatically adding some dependencies -->
<exclusions>
<module name="org.apache.log4j" />
</exclusions>
</deployment>
</jboss-deployment-structure>
Others classes logs correctly. 其他类正确记录日志。
Thanks Andrea 谢谢安德里亚
If you exclude log4j from being in your WAR/lib
directory, remove the jboss-deployment-structure.xml
and move the log4j.properties
to WAR/WEB-INF/classes
WildFly automatically configure log4j for your deployment. 如果将log4j排除在
WAR/lib
目录中,则删除jboss-deployment-structure.xml
并将log4j.properties
移至WAR/WEB-INF/classes
WildFly自动为您的部署配置log4j。
If you'd rather use your own version of log4j you'd still need to move your log4j.properties
to WAR/WEB-INF/classes
directory as log4j wouldn't be able to read anything from the WAR/WEB-INF
directory. 如果您希望使用自己的log4j版本,则仍需要将
log4j.properties
移至WAR/WEB-INF/classes
目录,因为log4j无法从WAR/WEB-INF
目录读取任何内容。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.