我尝试在servlet中使用我的默认日志文件的第二个日志文件 我有这个log4j.xml配置。
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE log4j:configuration SYSTEM "log4j.dtd">
<log4j:configuration xmlns:log4j="http://jakarta.apache.org/log4j/" ERROR="false">
<appender name="FILE_error" class="org.apache.log4j.RollingFileAppender">
<param name="Threshold" value="DEBUG"/>
<param name="maxFileSize" value="10240KB" />
<param name="maxBackupIndex" value="5" />
<param name="File" value="logs/engine.log"/>
<param name="Append" value="true"/>
<layout class="org.apache.log4j.PatternLayout">
<param name="ConversionPattern" value="%d{ISO8601} %t %-5p [%c{1}] %m%n "/>
</layout>
</appender>
<appender name="CONSOLE_error" class="org.apache.log4j.ConsoleAppender">
<param name="Target" value="System.out"/>
<param name="Threshold" value="DEBUG"/>
<layout class="org.apache.log4j.PatternLayout">
<param name="ConversionPattern" value="%d{ISO8601} %t %-5p [%c{1}] %m%n "/>
</layout>
</appender>
<category name="errorLogger" additivity="false">
<priority value="DEBUG"/>
<appender-ref ref="CONSOLE_error"/>
<appender-ref ref="FILE_error"/>
</category>
<appender name="FILE" class="org.apache.log4j.RollingFileAppender">
<param name="Threshold" value="DEBUG"/>
<param name="maxFileSize" value="10240KB" />
<param name="maxBackupIndex" value="5" />
<param name="File" value="logs/error_info.log"/>
<param name="Append" value="true"/>
<layout class="org.apache.log4j.PatternLayout">
<param name="ConversionPattern" value="%d{ISO8601} %t %-5p [%c{1}] %m%n "/>
</layout>
</appender>
<appender name="CONSOLE" class="org.apache.log4j.ConsoleAppender">
<param name="Target" value="System.out"/>
<param name="Threshold" value="DEBUG"/>
<layout class="org.apache.log4j.PatternLayout">
<param name="ConversionPattern" value="%d{ISO8601} %t %-5p [%c{1}] %m%n "/>
</layout>
</appender>
<category name="com.foo" additivity="false">
<priority value="DEBUG"/>
<appender-ref ref="CONSOLE"/>
<appender-ref ref="FILE"/>
</category>
<category name="org.apache" additivity="false">
<priority value="DEBUG"/>
<appender-ref ref="CONSOLE"/>
<appender-ref ref="FILE"/>
</category>
<root>
<priority value="DEBUG"/>
<appender-ref ref="CONSOLE"/>
<appender-ref ref="FILE"/>
<appender-ref ref="CONSOLE_error"/>
<appender-ref ref="FILE_error"/>
</root>
</log4j:configuration>
现在在servlet中我设置了这样的记录器:
public class PaymentConfirmation extends HttpServlet implements Constants{
private static final Logger errorLog= Logger.getLogger("errorLogger");
但在运行时: errorLog.debug(“开始应用”); 我得到了:
log4j:WARN No appenders could be found for logger (errorLogger).
log4j:WARN Please initialize the log4j system properly.
log4j和log4j.xml在类路径中 我在这做错了什么?
答案 0 :(得分:0)
我也遇到了同样的错误。你可以尝试使用-Dlog4j.debug java选项运行你的java程序。它将提供一些有关失败的信息,然后您就可以解决这个问题。