log4j分级输出

src目录下,创建log4j.xml文件
    <?xml version="1.0" encoding="GB2312" ?>  
    <!DOCTYPE log4j:configuration SYSTEM "log4j.dtd">  
    <!--#log4j中有5级logger ,#FATAL 0 ,#ERROR 3 ,#WARN 4 ,#INFO 6 ,#DEBUG 7 -->  
    <log4j:configuration xmlns:log4j='http://jakarta.apache.org/log4j/'>  
      
    <!--输出到控制台-->  
    <!--  
    <appender name="LOG.Console" class="org.apache.log4j.ConsoleAppender">    
    <layout class="org.apache.log4j.PatternLayout">    
      <param name="ConversionPattern" value="%d{yyy-MM-dd HH:mm:ss} [%-5p] %c {%F:%L} - %m%n" />    
    </layout>    
    </appender>  
    -->  
      
    <!--将级别为DEBUG的信息输出到控制台-->  
    <appender name="LOG.DEBUG" class="org.apache.log4j.RollingFileAppender">  
    <param name="File" value="d:/log/debug.log" />  
    <param name="MaxFileSize" value="5120KB" />  
    <param name="MaxBackupIndex" value="10" />  
    <layout class="org.apache.log4j.PatternLayout">  
      <param name="ConversionPattern" value="%d{yyy-MM-dd HH:mm:ss} [%-5p] %c {%F:%L} - %m%n" />  
    </layout>  
    <filter class="org.apache.log4j.varia.LevelRangeFilter">    
      <param name="LevelMin" value="DEBUG" />    
      <param name="LevelMax" value="DEBUG" />    
    </filter>  
    </appender>  
      
    <!--将级别为INFO的信息输出到控制台-->  
    <appender name="LOG.INFO" class="org.apache.log4j.RollingFileAppender">  
    <param name="File" value="d:/log/info.log" />  
    <param name="MaxFileSize" value="5120KB" />  
    <param name="MaxBackupIndex" value="10" />  
    <layout class="org.apache.log4j.PatternLayout">  
      <param name="ConversionPattern" value="%d{yyy-MM-dd HH:mm:ss} [%-5p] %c {%F:%L} - %m%n" />  
    </layout>  
    <filter class="org.apache.log4j.varia.LevelRangeFilter">    
      <param name="LevelMin" value="INFO" />    
      <param name="LevelMax" value="INFO" />    
    </filter>  
    </appender>  
      
    <!--将级别为WARN的信息输出到控制台-->  
    <appender name="LOG.WARN" class="org.apache.log4j.RollingFileAppender">  
    <param name="File" value="d:/log/warn.log" />  
    <param name="MaxFileSize" value="5120KB" />  
    <param name="MaxBackupIndex" value="10" />  
    <layout class="org.apache.log4j.PatternLayout">  
      <param name="ConversionPattern" value="%d{yyy-MM-dd HH:mm:ss} [%-5p] %c {%F:%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="LOG.ERROR" class="org.apache.log4j.RollingFileAppender">  
    <param name="File" value="d:/log/error.log" />  
    <param name="MaxFileSize" value="5120KB" />  
    <param name="MaxBackupIndex" value="10" />  
    <layout class="org.apache.log4j.PatternLayout">  
      <param name="ConversionPattern" value="%d{yyy-MM-dd HH:mm:ss} [%-5p] %c {%F:%L} - %m%n" />  
    </layout>  
    <filter class="org.apache.log4j.varia.LevelRangeFilter">    
      <param name="LevelMin" value="ERROR" />    
      <param name="LevelMax" value="ERROR" />    
    </filter>  
    </appender>  
      
    <!--将级别为FATAL的信息输出到控制台-->  
    <appender name="LOG.FATAL" class="org.apache.log4j.RollingFileAppender">  
    <param name="File" value="d:/log/fatal.log" />  
    <param name="MaxFileSize" value="5120KB" />  
    <param name="MaxBackupIndex" value="10" />  
    <layout class="org.apache.log4j.PatternLayout">  
      <param name="ConversionPattern" value="%d{yyy-MM-dd HH:mm:ss} [%-5p] %c {%F:%L} - %m%n" />  
    </layout>  
    <filter class="org.apache.log4j.varia.LevelRangeFilter">    
      <param name="LevelMin" value="FATAL" />    
      <param name="LevelMax" value="FATAL" />    
    </filter>  
    </appender>  
      
    <!--  
    <appender name="InitAction" class="org.apache.log4j.DailyRollingFileAppender">  
    <param name="File" value="d:/dbcon.log"/>  
    <param name="MaxFileSize" value="5120KB"/>  
    <param name="MaxFileSize" value="10" />  
    <param name="MaxBackupIndex" value="2" />  
    <param name="DatePattern" value="'.'yyyy-MM-dd'.'log"/>  
    <layout class="org.apache.log4j.PatternLayout">  
      <param name="ConversionPattern" value="%d{yyy-MM-dd HH:mm:ss} - %m%n"/>  
      <param name="ConversionPattern" value="%d{DATE} [%-5p] %c {%F:%L} - %m%n"/>  
    </layout>  
    </appender>  
    -->  
      
    <!--设置org.logicalcobwebs包的输出级别为INFO-->  
    <!--  
    <category name="org.logicalcobwebs">  
    <priority value="INFO" />  
    <appender-ref ref="LOG.Console" />  
    </category>  
    -->  
    <root>  
    <priority value="DEBUG"/>  
    <!-- 
    <appender-ref ref="LOG.Console" /> 
      -->  
    <appender-ref ref="LOG.DEBUG" />  
    <appender-ref ref="LOG.INFO" />  
    <appender-ref ref="LOG.WARN" />  
    <appender-ref ref="LOG.ERROR" />  
    <appender-ref ref="LOG.FATAL" />  
    </root>  
      
    </log4j:configuration>  

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