Log4j.xml配置

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE log4j:configuration SYSTEM "log4j.dtd">

<log4j:configuration xmlns:log4j="http://jakarta.apache.org/log4j/">

    <!-- Console Appender -->
    <appender name="console" class="org.apache.log4j.ConsoleAppender">
        <param name="encoding" value="UTF-8"/>
        <layout class="org.apache.log4j.PatternLayout">
            <param name="ConversionPattern" value="%d{HH:mm:ss,SSS} %l %m%n"/>
        </layout>
    </appender>

    <!-- Default Appender -->
    <appender name="default" class="org.apache.log4j.DailyRollingFileAppender">
        <param name="file" value="${catalina.home}/logs/all.log"/>
        <param name="append" value="true"/>
        <param name="encoding" value="UTF-8"/>
        <layout class="org.apache.log4j.PatternLayout">
            <param name="ConversionPattern" value="%d{HH:mm:ss,SSS} %l %m%n"/>
        </layout>
    </appender>

    <!-- redpin Appender -->
    <appender name="redpin" class="org.apache.log4j.DailyRollingFileAppender">
        <param name="file" value="${catalina.home}/logs/redpin.log"/>
        <param name="append" value="true"/>
        <param name="encoding" value="UTF-8"/>
        <layout class="org.apache.log4j.PatternLayout">
            <param name="ConversionPattern" value="[%r][%p][%t] %d{HH:mm:ss,SSS} %l %m%n"/>
        </layout>
    </appender>
    
    <!-- bbg Appender -->
    <appender name="server" class="org.apache.log4j.DailyRollingFileAppender">
        <param name="file" value="${catalina.home}/logs/maps.log"/>
        <param name="append" value="true"/>
        <param name="encoding" value="UTF-8"/>
        <layout class="org.apache.log4j.PatternLayout">
            <param name="ConversionPattern" value="%d{HH:mm:ss,SSS} %l %m%n"/>
        </layout>
    </appender>

    <!-- bbg logger -->
    <logger name="cn.com.server" additivity="true">
        <level value="debug"/>
        <appender-ref ref="server"/>
    </logger>

    <!--redpin logger -->
    <logger name="org.redpin" additivity="true">
        <level value="info"/>
        <appender-ref ref="redpin"/>
    </logger>
    
    <!-- root logger -->
    <root>
        <level value="warn"/>
        <appender-ref ref="default"/>
        <appender-ref ref="console"/>
    </root>

</log4j:configuration>

关于自己的一点理解:

logger节点可以指定不同的包输出到指定的appender定义的日志中,additivity表示是否往root节点指定的appender中输出

你可能感兴趣的:(日志配置)