log4j xml模式配置

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

    <!-- 控制台输出日志 -->
    <appender name="CONSOLE" class="org.apache.log4j.ConsoleAppender">
        <param name="Threshold" value="INFO"/>
        <param name="Target" value="System.out"/>
        <layout class="org.apache.log4j.PatternLayout">
            <param name="ConversionPattern" value="%d{yyyy-MM-dd HH\:mm\:ss} [%p] %m%n"/>
        </layout>
        <filter class="org.apache.log4j.varia.LevelRangeFilter">
            <param name="LevelMin" value="INFO"/>
            <param name="LevelMax" value="ERROR"/>
        </filter>
    </appender>

    <!-- info至error 级别日志 -->
    <appender name="INFO_ERROR" class="org.apache.log4j.RollingFileAppender">
        <param name="File" value="/home/logs/pfmms/info_error.log"/>
        <param name="Append" value="true"/>
        <param name="MaxFileSize" value="20MB"/>
        <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} [%p] %m%n"/>
        </layout>
        <filter class="org.apache.log4j.varia.LevelRangeFilter">
            <param name="LevelMin" value="INFO"/>
            <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="/home/logs/pfmms/debug.log"/>
        <param name="Append" value="true"/>
        <param name="MaxFileSize" value="20MB"/>
        <param name="MaxBackupIndex" value="10"/>
        <layout class="org.apache.log4j.PatternLayout">
            <param name="ConversionPattern" value="%d{yyyy-MM-dd HH\:mm\:ss} [%p] %m%n"/>
        </layout>
        <filter class="org.apache.log4j.varia.LevelRangeFilter">
            <param name="LevelMin" value="DEBUG"/>
            <param name="LevelMax" value="DEBUG"/>
        </filter>
    </appender>
	
    <!-- error级别日志  -->
    <appender name="ERROR_LOG" class="org.apache.log4j.RollingFileAppender">
        <param name="Threshold" value="ERROR"/>
        <param name="File" value="/home/logs/pfmms/error.log"/>
        <param name="Append" value="true"/>
        <param name="MaxFileSize" value="20MB"/>
        <param name="MaxBackupIndex" value="10"/>
        <layout class="org.apache.log4j.PatternLayout">
            <param name="ConversionPattern" value="%d{yyyy-MM-dd HH\:mm\:ss} [%p] %m%n"/>
        </layout>
        <filter class="org.apache.log4j.varia.LevelRangeFilter">
            <param name="LevelMin" value="ERROR"/>
            <param name="LevelMax" value="ERROR"/>
        </filter>
    </appender>

	<!--设置sql包的输出级别-->  
	<category name="java.sql" additivity="true">  
		<priority value="DEBUG" />
		<appender-ref ref="CONSOLE"/>
	</category>  

    <root>
    	<!-- 优先级 -->
        <priority value="INFO"/>
        <appender-ref ref="CONSOLE"/>
        <appender-ref ref="INFO_ERROR"/>
        <appender-ref ref="DEBUG_LOG"/>
        <appender-ref ref="ERROR_LOG"/>
    </root>

</log4j:configuration>
 

你可能感兴趣的:(log4j,xml)