当前位置: 首页 > 知识库问答 >
问题:

log4j:警告:找不到记录器的附加器

诸葛奇玮
2023-03-14

我尝试使用第二个日志文件与我的默认日志文件在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");

但在运行时:错误日志。调试(“启动应用程序”);我得到:

log4j:WARN No appenders could be found for logger (errorLogger).
log4j:WARN Please initialize the log4j system properly.

log4j和log4j.xml在类路径我做错了什么?

共有1个答案

涂泰平
2023-03-14

我也得到了同样的错误。你能不能试着用-Dlog4j.debugjava选项运行你的java程序。它会给我们一些关于失败的洞察力,那时你就能解决这个问题。

 类似资料: