log4j日记记录

原创
2017/01/06 17:02
阅读数 24
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE log4j:configuration SYSTEM "log4j.dtd">
<log4j:configuration xmlns:log4j="http://jakarta.apache.org/log4j/" debug="true">

    <!-- 控制台输出日志 -->
    <appender name="CONSOLE" class="org.apache.log4j.ConsoleAppender">
        <param name="Target" value="System.out"/>
        <layout class="org.apache.log4j.PatternLayout">
            <param name="ConversionPattern" value="%d{yyyy-MM-dd HH\:mm\:ss}  [%c]   [%p] %l %m%n"/>
        </layout>
        <filter class="org.apache.log4j.varia.LevelRangeFilter">
            <param name="LevelMin" value="DEBUG"/>
            <param name="LevelMax" value="ERROR"/>
        </filter>
    </appender>
    
    <!-- debug级别日志 -->
    <appender name="DEBUG_LOG" class="org.apache.log4j.RollingFileAppender">
        <param name="Threshold" value="DEBUG"/>
        <param name="File" value="${catalina.home}/logs/game-debug.log"/>
        <param name="Append" value="true"/>
        <param name="MaxFileSize" value="100MB"/>
        <param name="MaxBackupIndex" value="10"/>
        <layout class="org.apache.log4j.PatternLayout">
            <param name="ConversionPattern" value="%d{yyyy-MM-dd HH\:mm\:ss}  [%c]   [%p] %l %m%n"/>
        </layout>
        <filter class="org.apache.log4j.varia.LevelRangeFilter">
            <param name="LevelMin" value="DEBUG"/>
            <param name="LevelMax" value="DEBUG"/>
        </filter>
    </appender>
    

    <!-- info至error 级别日志 -->
    <appender name="INFO_LOG" class="org.apache.log4j.RollingFileAppender">
        <param name="File" value="${catalina.home}/logs/game-info.log"/>
        <param name="Append" value="true"/>
        <param name="MaxFileSize" value="100MB"/>
        <param name="Threshold" value="INFO"/>
        <param name="MaxBackupIndex" value="10"/>
        <layout class="org.apache.log4j.PatternLayout">
            <param name="ConversionPattern" value="%d{yyyy-MM-dd HH\:mm\:ss}  [%c]   [%p] %l %m%n"/>
        </layout>
        <filter class="org.apache.log4j.varia.LevelRangeFilter">
            <param name="LevelMin" value="INFO"/>
            <param name="LevelMax" value="INFO"/>
        </filter>
    </appender>
    
    <!-- info至error 级别日志 -->
    <appender name="WARN_LOG" class="org.apache.log4j.RollingFileAppender">
        <param name="File" value="${catalina.home}/logs/game-warn.log"/>
        <param name="Append" value="true"/>
        <param name="MaxFileSize" value="100MB"/>
        <param name="Threshold" value="WARN"/>
        <param name="MaxBackupIndex" value="10"/>
        <layout class="org.apache.log4j.PatternLayout">
            <param name="ConversionPattern" value="%d{yyyy-MM-dd HH\:mm\:ss}  [%c]   [%p] %l %m%n"/>
        </layout>
        <filter class="org.apache.log4j.varia.LevelRangeFilter">
            <param name="LevelMin" value="WARN"/>
            <param name="LevelMax" value="WARN"/>
        </filter>
    </appender>
    
	
	
     <!-- error级别日志  -->
    <appender name="ERROR_LOG" class="org.apache.log4j.DailyRollingFileAppender">
        <param name="File" value="${catalina.home}/logs/game-error.log"/>
        <param name="Append" value="true"/>
        <param name="Threshold" value="ERROR"/>
        <param name="DatePattern" value="'.'yyyy-MM-dd'.log'"></param>
        <layout class="org.apache.log4j.PatternLayout">
            <param name="ConversionPattern" value="%d{yyyy-MM-dd HH\:mm\:ss}  [%c]   [%p] %l %m%n"/>
        </layout>
        <filter class="org.apache.log4j.varia.LevelRangeFilter">
            <param name="LevelMin" value="ERROR"/>
            <param name="LevelMax" value="ERROR"/>
        </filter>
    </appender>
    

    
    <category name="org.springframework.scheduling.quartz" additivity="false">
        <priority value="ERROR" />
        <appender-ref ref="CONSOLE"/>
    </category>
    <category name="org.springframework.jdbc.datasource" additivity="false">
        <priority value="ERROR" />
        <appender-ref ref="CONSOLE"/>
    </category>
    <category name="org.quartz" additivity="false">
        <priority value="ERROR" />
        <appender-ref ref="CONSOLE"/>
    </category>
    <category name="org.apache.activemq" additivity="false">
        <priority value="ERROR" />
        <appender-ref ref="CONSOLE"/>
    </category>
    <category name="java.sql.ResultSet" additivity="false">
        <priority value="INFO" />
        <appender-ref ref="CONSOLE"/>
    </category>
    
    <category name="java.sql" additivity="false">
        <priority value="ERROR" />
        <appender-ref ref="CONSOLE"/>
    </category>
    
    <root>
    	<!-- 优先级 -->
        <priority value="INFO"/>
        <appender-ref ref="CONSOLE"/>
        <appender-ref ref="DEBUG_LOG"/>
        <appender-ref ref="INFO_LOG"/>
        <appender-ref ref="WARN_LOG"/>
        <appender-ref ref="ERROR_LOG"/>
    </root>

</log4j:configuration>
展开阅读全文
打赏
0
0 收藏
分享
加载中
更多评论
打赏
0 评论
0 收藏
0
分享
返回顶部
顶部