java log4j 配置

<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE log4j:configuration SYSTEM "../WebRoot/WEB-INF/config/log4j/log4j.dtd">
<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="%m%n" />
  </layout>
  <!--滤镜设置输出的级别-->
  <filter class="org.apache.log4j.varia.LevelRangeFilter">
   <param name="levelMin" value="debug" />
   <param name="levelMax" value="fatal" />
   <param name="AcceptOnMatch" value="true" />
  </filter>

 </appender>

 <!--将级别为INFO的信息输出到文件-->
 <appender name="LOG.INFO"
  class="org.apache.log4j.RollingFileAppender">
  <param name="File" value="D:/hosting/wwwroot/rmtitems_com/htdocs/WEB-INF/logfile/info.log" />
  <param name="Append" value="true" />
  <param name="MaxFileSize" value="5120KB" />
  <param name="MaxBackupIndex" value="1000" />
  <layout class="org.apache.log4j.PatternLayout">
   <param name="ConversionPattern"
    value="%d{yyyy/MM/dd HH:mm:ss} - %-5p -%c %m%n" />
  </layout>
  <filter class="org.apache.log4j.varia.LevelRangeFilter">
   <param name="LevelMin" value="info" />
   <param name="LevelMax" value="info" />
   <param name="AcceptOnMatch" value="true" />
  </filter>
 </appender>

 <!--将级别为WARN的信息输出到文件-->
 <appender name="LOG.WARN"
  class="org.apache.log4j.RollingFileAppender">                         
  <param name="File" value="D:/hosting/wwwroot/rmtitems_com/htdocs/WEB-INF/logfile/warn.log" />
  <param name="Append" value="true" />
  <param name="MaxFileSize" value="5120KB" />
  <param name="MaxBackupIndex" value="1000" />
  <layout class="org.apache.log4j.PatternLayout">
   <param name="ConversionPattern"
    value="%d{yyyy/MM/dd HH:mm:ss} - %-5p -%c %m%n" />
  </layout>
  <filter class="org.apache.log4j.varia.LevelRangeFilter">
   <param name="LevelMin" value="warn" />
   <param name="LevelMax" value="warn" />
   <param name="AcceptOnMatch" value="true" />
  </filter>
 </appender>

 <!--将级别为ERROR的信息输出到文件-->
 <appender name="LOG.ERROR"
  class="org.apache.log4j.RollingFileAppender">
  <param name="File" value="D:/hosting/wwwroot/rmtitems_com/htdocs/WEB-INF/logfile/error.log" />
  <param name="Append" value="true" />
  <param name="MaxFileSize" value="5120KB" />
  <param name="MaxBackupIndex" value="1000" />
  <layout class="org.apache.log4j.PatternLayout">
   <param name="ConversionPattern"
    value="%d{yyyy/MM/dd HH:mm:ss} - %-5p -%c %m%n" />
  </layout>
  <filter class="org.apache.log4j.varia.LevelRangeFilter">
   <param name="LevelMin" value="error" />
   <param name="LevelMax" value="error" />
   <param name="AcceptOnMatch" value="true" />
  </filter>
 </appender>

 <!--将级别为FATAL的信息输出到文件-->
 <appender name="LOG.FATAL"
  class="org.apache.log4j.RollingFileAppender">
  <param name="File" value="D:/hosting/wwwroot/rmtitems_com/htdocs/WEB-INF/logfile/fatal.log" />
  <param name="Append" value="true" />
  <param name="MaxFileSize" value="5120KB" />
  <param name="MaxBackupIndex" value="1000" />
  <layout class="org.apache.log4j.PatternLayout">
   <param name="ConversionPattern"
    value="%d{yyyy/MM/dd HH:mm:ss} - %-5p -%c %m%n" />
  </layout>
  <filter class="org.apache.log4j.varia.LevelRangeFilter">
   <param name="LevelMin" value="fatal" />
   <param name="LevelMax" value="fatal" />
   <param name="AcceptOnMatch" value="true" />
  </filter>
 </appender>

 <!--将级别为DEBUG的信息输出到文件-->
 <appender name="LOG.DEBUG"
  class="org.apache.log4j.RollingFileAppender">
  
  <param name="File" value="D:/hosting/wwwroot/rmtitems_com/htdocs/WEB-INF/logfile/debug.log" />
  <param name="Append" value="true" />
  <param name="MaxFileSize" value="5120KB" />
  <param name="MaxBackupIndex" value="1000" />
  <layout class="org.apache.log4j.PatternLayout">
   <param name="ConversionPattern"
    value="%d{yyyy/MM/dd HH:mm:ss} - %-5p -%c %m%n" />
  </layout>
  <filter class="org.apache.log4j.varia.LevelRangeFilter">
   <param name="LevelMin" value="debug" />
   <param name="LevelMax" value="debug" />
   <param name="AcceptOnMatch" value="true" />
  </filter>
 </appender>

 <root>
  <priority value="debug" />

  <appender-ref ref="LOG.Console" />

  <appender-ref ref="LOG.INFO" />
  <appender-ref ref="LOG.WARN" />
  <appender-ref ref="LOG.ERROR" />
  <appender-ref ref="LOG.FATAL" />
  <appender-ref ref="LOG.DEBUG" />
 </root>
</log4j:configuration>

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值