log4j配置文件详解

<?xml version="1.0" encoding="GB2312"?>
<!DOCTYPE log4j:configuration SYSTEM "log4j.dtd">
<log4j:configuration xmlns:log4j="http://jakarta.apache.org/log4j/">  
    //请先跳到下面查看<root>配置项
    <!-- 系统级别日志记录APPENDER -->
    <appender name="PROJECT" class="com.alibaba.common.logging.spi.log4j.DailyRollingFileAppender"> //PROJECT bean,指向DailyRollingFileAppende.class
        <param name="file" value="${wholesale_loggingRoot}/sys/webx/webx.log"/>  //日志文件输出位置
        <param name="append" value="false"/>  //以累加模式
        <param name="encoding" value="GBK"/>  //GBK编码
        <param name="threshold" value="info"/>  //info级别才打日志
        <layout class="org.apache.log4j.PatternLayout">
            <param name="ConversionPattern" value="%d [%X{requestURIWithQueryString}] %-5p %c{2} - %m%n"/> //具体输出格式,这个自己查百度
        </layout>
    </appender>
    <appender name="SESSION" class="com.alibaba.common.logging.spi.log4j.DailyRollingFileAppender">
        <param name="file" value="${wholesale_loggingRoot}/sys/webx/session.log"/>
        <param name="append" value="false"/>
        <param name="encoding" value="GBK"/>
        <layout class="org.apache.log4j.PatternLayout">
            <param name="ConversionPattern" value="%n%d %-5p %c{2} - [%X{loginUserNick}@%X{remoteAddr} - %X{method} %X{requestURIWithQueryString}] %nUserAgent: %X{userAgent}%nReferrer: %X{referrer} %n%m%n"/>
        </layout>
    </appender>
    <appender name="FILTER" class="com.alibaba.common.logging.spi.log4j.DailyRollingFileAppender">
        <param name="file" value="${wholesale_loggingRoot}/sys/webx/webx-filter.log"/>
        <param name="append" value="false"/>
        <param name="encoding" value="GBK"/>
        <layout class="org.apache.log4j.PatternLayout">
            <param name="ConversionPattern" value="%d %-5p %c{2} - %m%n"/>
        </layout>
    </appender>
    <appender name="VELOCITY" class="com.alibaba.common.logging.spi.log4j.DailyRollingFileAppender">
        <param name="file" value="${wholesale_loggingRoot}/sys/velocity/velocity.log"/>
        <param name="append" value="false"/>
        <param name="encoding" value="GBK"/>
        <layout class="org.apache.log4j.PatternLayout">
            <param name="ConversionPattern" value="%d %-5p %c{2} - %m%n"/>
        </layout>
    </appender>
 
    <!-- dragoon begin -->
    <appender name="EXCEPTION_LOG" class="com.alibaba.dragoon.patrol.log4j.PatrolLog4jAppender">
       <param name="Threshold" value="ERROR"/>
    </appender>
    <!-- dragoon end -->
 
    <!--Logger定义-->
    <!--系统级别Logger-->
    <logger name="com.alibaba.webx.session" additivity="false">
        <level value="$wholesale_loggingLevel"/>
        <appender-ref ref="SESSION"/>
    </logger>
    <logger name="com.alibaba.china.biz.common.monitor.PerformanceInterceptor" additivity="false">
        <level value="$wholesale_loggingLevel"/>
        <appender-ref ref="PERFORMANCE"/>
    </logger>
    <logger name="com.alibaba.webx.filter" additivity="false">
        <level value="$wholesale_loggingLevel"/>
        <appender-ref ref="FILTER"/>
    </logger>
    <logger name="com.alibaba.service.VelocityService" additivity="false">
     <level value="${wholesale_loggingLevel}"/>
     <appender-ref ref="VELOCITY"/>
    </logger>
    <logger name="businessErrorLog" additivity="false">
        <level value="$wholesale_loggingLevel"/>
        <appender-ref ref="BUSINESSERRORAPPENDER"/>
    </logger>
    <logger name="invokeSearchLog" additivity="false">
        <level value="info"/>
        <appender-ref ref="INVOKESEARCHAPPENDER"/>
    </logger>
    <logger name="tsSearchLogger" additivity="false">
        <level value="info"/>
        <appender-ref ref="tsSearchAppender"/>
    </logger>
    <logger name="taobaoGreetingLogger" additivity="false">
        <level value="info"/>
        <appender-ref ref="taobaoGreetingAppender"/>
    </logger>
    <logger name="xshowLogger" additivity="false">
        <level value="info"/>
        <appender-ref ref="xshowAppender"/>
    </logger>
 
    <!--ROOT LOGGER-->
 
    <root>
        //设置日志级别,该变量在antx.properties文件中,即${wholesale.loggingLevel}.
        //此处有个约定$wholesale_loggingLevel等同于${wholesale_loggingLevel}(webx的约定),
        //但绝不等同于${wholesale.loggingLevel}!!!!!
        <level value="$wholesale_loggingLevel"/>  
        <appender-ref ref="PROJECT"/>  //故名思意指向PROJECT配置项,即<appender name="PROJECT" ……/>
    <!-- dragoon -->
    <appender-ref ref="EXCEPTION_LOG"/>
    </root>
</log4j:configuration>

相关推荐