在Log4j.xml文件中声明自定义appender

时间:2012-11-09 10:30:37

标签: log4j

我编写了一个自定义appender,所以如何在Log4j.xml文件中声明它。

My property file is[custom appender is in org.copofi.common.logging.SystemStatusAppender] :

    log4j.rootLogger=INFO,logfile,console,SystemStatus
    log4j.logger=INFO,logfile,console,SystemStatus

    # Console appender (stdout)
    log4j.appender.console=org.apache.log4j.ConsoleAppender
    log4j.appender.console.layout=org.apache.log4j.PatternLayout
    log4j.appender.console.layout.ConversionPattern=[%d{yy-MM-dd HH:mm:ss.SSS}] [%p] <%t> [%X{jsessionId}] [%c] %m%n

    # File appender
    log4j.appender.logfile=org.apache.log4j.FileAppender
    log4j.appender.logfile.File=${catalina.base}/logs/copofi.log
    log4j.appender.logfile.layout=org.apache.log4j.PatternLayout
    log4j.appender.logfile.layout.ConversionPattern=[%d{yy-MM-dd HH:mm:ss.SSS}] [%p] <%t> [%X{jsessionId}] [%c] %m%n

    log4j.appender.SystemStatus=org.copofi.common.logging.SystemStatusAppender

1 个答案:

答案 0 :(得分:-1)

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE log4j:configuration SYSTEM "log4j.dtd">
<log4j:configuration debug="false" xmlns:log4j="http://jakarta.apache.org/log4j/">`    

<appender name="CONSOLE" class="org.apache.log4j.ConsoleAppender">
            <param name="Threshold" value="INFO"/>
            <layout class="org.apache.log4j.PatternLayout">
                <param name="ConversionPattern" value="%d{MMM dd, yyyy hh:mm:ss a zzz} %-5p %F.%M:%L: %m%n"/>
            </layout>

            <filter class="org.apache.log4j.varia.LevelMatchFilter">
                <!-- only the levels (comma separated) specified in LevelToMatch will be logged -->
                <param name="LevelToMatch" value="DEBUG, WARN,INFO,ERROR, FATAL"/>
                <param name="AcceptOnMatch" value="true"/>
            </filter>
        </appender>

    <root>
        <level value="INFO"/>
        <appender-ref ref="CONSOLE_LOG"/>       
    </root>

</log4j:configuration>