log4j XML配置文件

<? xmlversion='1.0'encoding='UTF-8' ?>
<! DOCTYPElog4j:configurationSYSTEM"log4j.dtd" >
< log4j:configuration xmlns:log4j ="http://jakarta.apache.org/log4j/" >

<!--
%c输出日志信息所属的类的全名
%d输出日志时间点的日期或时间,默认格式为ISO8601,也可以在其后指定格式,比如:%d{yyy-MM-ddHH:mm:ss},输出类似:2002-10-18-22:10:28
%f输出日志信息所属的类的类名
%l输出日志事件的发生位置,即输出日志信息的语句处于它所在的类的第几行
%m输出代码中指定的信息,如log(message)中的message
%n输出一个回车换行符,Windows平台为“rn”,Unix平台为“n”
%p输出优先级,即DEBUG,INFO,WARN,ERROR,FATAL。如果是调用debug()输出的,则为DEBUG,依此类推
%r输出自应用启动到输出该日志信息所耗费的毫秒数
%t输出产生该日志事件的线程名
-->
< appender name ="STDOUT" class ="org.apache.log4j.ConsoleAppender" >
< layout class ="org.apache.log4j.PatternLayout" >
< param name ="ConversionPattern"
value
="[%d{yyyy-MM-ddHH:mm:ss}][%t][%p][%m] " />
</ layout >
</ appender >

< appender class ="org.apache.log4j.DailyRollingFileAppender"
name
="ROLLINGFILE" >
< param name ="DatePattern" value =".yyyy-MM-dd" />
< param name ="File" value ="D:/jframelog/jframe.log" />
< param name ="Encoding" value ="GBK" />
< layout class ="org.apache.log4j.PatternLayout" >
< param name ="ConversionPattern"
value
="[%d{yyyy-MM-ddHH:mm:ss}][%t][%p][%m] " />
</ layout >
</ appender >

<!-- 设定级别为debug的配置信息 -->
< appender name ="DEBUG"
class
="org.apache.log4j.DailyRollingFileAppender" >
< param name ="DatePattern" value =".yyyy-MM-dd" />
< param name ="File" value ="D:/jframelog/jframe_debug.log" />
< param name ="Append" value ="true" />
< layout class ="org.apache.log4j.PatternLayout" >
< param name ="ConversionPattern"
value
="[%d{yyyy-MM-ddHH:mm:ss}][%t][%p][%m] " />
</ layout >
< filter class ="org.apache.log4j.varia.LevelRangeFilter" >
< param name ="LevelMin" value ="DEBUG" />
< param name ="LevelMax" value ="DEBUG" />
</ filter >
</ appender >

<!-- 设定级别为info的配置信息 -->
< appender name ="INFO"
class
="org.apache.log4j.DailyRollingFileAppender" >
< param name ="DatePattern" value =".yyyy-MM-dd" />
< param name ="File" value ="D:/jframelog/jframe_info.log" />
< param name ="Append" value ="true" />
< layout class ="org.apache.log4j.PatternLayout" >
< param name ="ConversionPattern"
value
="[%d{yyyy-MM-ddHH:mm:ss}][%t][%p][%m] " />
</ layout >
< filter class ="org.apache.log4j.varia.LevelRangeFilter" >
< param name ="LevelMin" value ="INFO" />
< param name ="LevelMax" value ="INFO" />
</ filter >
</ appender >

<!-- 设定级别为warn的配置信息 -->
< appender name ="WARN"
class
="org.apache.log4j.DailyRollingFileAppender" >
< param name ="DatePattern" value =".yyyy-MM-dd" />
< param name ="File" value ="D:/jframelog/jframe_warn.log" />
< param name ="Append" value ="true" />
< layout class ="org.apache.log4j.PatternLayout" >
< param name ="ConversionPattern"
value
="[%d{yyyy-MM-ddHH:mm:ss}][%t][%p][%m] " />
</ layout >
< filter class ="org.apache.log4j.varia.LevelRangeFilter" >
< param name ="LevelMin" value ="WARN" />
< param name ="LevelMax" value ="WARN" />
</ filter >
</ appender >

<!-- 设定级别为error的配置信息 -->
< appender name ="ERROR"
class
="org.apache.log4j.DailyRollingFileAppender" >
< param name ="File" value ="D:/jframelog/jframe_error.log" />
< param name ="Append" value ="true" />
< layout class ="org.apache.log4j.PatternLayout" >
< param name ="ConversionPattern"
value
="[%d{yyyy-MM-ddHH:mm:ss}][%t][%p][%m] " />
</ layout >
< filter class ="org.apache.log4j.varia.LevelRangeFilter" >
< param name ="LevelMin" value ="ERROR" />
< param name ="LevelMax" value ="ERROR" />
</ filter >
</ appender >

<!-- 设定级别为fatal的配置信息 -->
< appender name ="FATAL"
class
="org.apache.log4j.DailyRollingFileAppender" >
< param name ="File" value ="D:/jframelog/jframe_fatal.log" />
< param name ="Append" value ="true" />
< layout class ="org.apache.log4j.PatternLayout" >
< param name ="ConversionPattern"
value
="[%d{yyyy-MM-ddHH:mm:ss}][%t][%p][%m] " />
</ layout >
< filter class ="org.apache.log4j.varia.LevelRangeFilter" >
< param name ="LevelMin" value ="FATAL" />
< param name ="LevelMax" value ="FATAL" />
</ filter >
</ appender >

<!-- 设定不同包中类的日志级别 -->

< logger name ="com.jframe" >
< level value ="DEBUG" />
</ logger >
< logger name ="org.apache" >
< level value ="ERROR" />
</ logger >
< logger name ="org.springframework" >
< level value ="ERROR" />
</ logger >

<!-- 默认级别,需要输出哪种类型日志,就写哪种类型 -->
< root >
< level value ="DEBUG" />
< appender-ref ref ="ROLLINGFILE" />
< appender-ref ref ="STDOUT" />
< appender-ref ref ="DEBUG" />
< appender-ref ref ="INFO" />
< appender-ref ref ="WARN" />
< appender-ref ref ="ERROR" />
< appender-ref ref ="FATAL" />
</ root >
</ log4j:configuration >

log4j.dtd放入和XML同级目录中

你可能感兴趣的:(log4j)