java Tomcat 6 和 log4j 应用程序日志记录不产生任何输出
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/917442/
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
Tomcat 6 and log4j application logging produce no output
提问by matt b
I'm trying to get log4j application (webapp) logging working in a Tomcat 6 app. I have log4j-1.2.15.jar in my WEB-INF directory, log4j.dtd and log4j.xml in WEB-INF/classes.
我正在尝试让 log4j 应用程序 (webapp) 日志记录在 Tomcat 6 应用程序中工作。我的 WEB-INF 目录中有 log4j-1.2.15.jar,WEB-INF/classes 中有 log4j.dtd 和 log4j.xml。
My log4j.xml looks like:
我的 log4j.xml 看起来像:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE log4j:configuration SYSTEM "log4j.dtd" >
<log4j:configuration>
<appender name="massAppender" class="org.apache.log4j.RollingFileAppender">
<param name="maxFileSize" value="100KB" />
<param name="maxBackupIndex" value="2" />
<param name="File" value="${catalina.home}/logs/mass.log" />
<layout class="org.apache.log4j.PatternLayout">
<param name="ConversionPattern" value="%d{ABSOLUTE} %5p %c{1}: %m%n " />
</layout>
</appender>
<category name="com.company.mass">
<priority value="DEBUG"/>
<appender-ref ref="massAppender"/>
</category>
<root>
<appender-ref ref="massAppender" />
</root>
</log4j:configuration>
My servlet is in the package:
我的 servlet 在包中:
package com.company.mass;
where the logger is declared as:
记录器声明为:
private static Logger logger = Logger.getLogger(Handler.class);
and at the top of my doGet(...) method there is:
在我的 doGet(...) 方法的顶部有:
logger.error("foo");
When I deploy the app in Tomcat and go to the servlet, it works correctly. I even get a mass.log file, but nothing gets put in it. It doesn't show up in any other logs either, and there are no obvious errors. Any idea what's going on?
当我在 Tomcat 中部署应用程序并转到 servlet 时,它可以正常工作。我什至得到了一个 mass.log 文件,但没有放入其中。它也不会出现在任何其他日志中,并且没有明显的错误。知道发生了什么吗?
回答by matt b
Are you sure that log4j is actually using your log4j.xmlfor it's configuration, and not another file on the classpath?
您确定 log4j 实际上是在使用您log4j.xml的配置,而不是类路径上的另一个文件吗?
Enable the system property -Dlog4j.debugto have log4j print out information about exactly which configuration file it is using.
启用系统属性-Dlog4j.debug以让 log4j 打印出有关它正在使用的确切配置文件的信息。
回答by Mike Pone
Not sure if you need a priority in your root logger. Try this config
不确定您的根记录器是否需要优先级。试试这个配置
<category name="com.company.mass">
<priority value="DEBUG"/>
<!-- no need to specify appender again here -->
</category>
<root>
<priority value="INFO"/>
<appender-ref ref="massAppender" />
</root>
回答by Gandalf
Try adding the line :
尝试添加行:
<param name="Threshold" value="ALL" />
to your massAppender config
到您的 massAppender 配置
and this line
和这条线
<priority value ="debug"/>
inside your root definition
在您的根定义中
回答by Ruudy Garcia
When I've encountered this problem I was able to resolve it by adding common-logging.jarto my deployment assembly.
当我遇到这个问题时,我能够通过添加common-logging.jar到我的部署程序集来解决它。

