Logger4j的配置
log4j两种方式:
1.xml配置 例如:
### set log levels ###
log4j.rootLogger = debug , stdout , D , E
### 输出到控制台 ###
log4j.appender.stdout = org.apache.log4j.ConsoleAppender
log4j.appender.stdout.Target = System.out
log4j.appender.stdout.layout = org.apache.log4j.PatternLayout
log4j.appender.stdout.layout.ConversionPattern = %d{ABSOLUTE} %5p %c{ 1 }:%L - %m%n
2.xml bean配置 例如:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE log4j:configuration SYSTEM "log4j.dtd">
<log4j:configuration xmlns:log4j="http://jakarta.apache.org/log4j/">
<!--appender 定义 begin-->
<!--控制台输出-->
<appender name="CONSOLE" class="org.apache.log4j.ConsoleAppender">
<param name="threshold" value="${log_console_level}" />
<param name="encoding" value="GBK" />
<layout class="org.apache.log4j.PatternLayout">
<param name="ConversionPattern" value="[%d{dd HH:mm:ss,SSS\} %-5p] [%t] %c{2\} - %m%n" />
</layout>
</appender>
<!--debug 文件输出-->
<appender name="DEBUG-ALL" class="org.apache.log4j.DailyRollingFileAppender">
<param name="file" value="${log_dir}/${log_app}-debug.log" />
<param name="append" value="true" />
<param name="encoding" value="GBK" />
<param name="threshold" value="debug" />
<layout class="org.apache.log4j.PatternLayout">
<param name="ConversionPattern"
value="%d [%X{requestURIWithQueryString}] %-5p [%t] %c{2} - %m%n" />
</layout>
</appender>
<root>
<level value="${log_root_level}" />
<appender-ref ref="CONSOLE" />
<appender-ref ref="ERROR-ALL" />
<appender-ref ref="DEBUG-ALL" />
<appender-ref ref="INFO-ALL" />
<!-- <appender-ref ref="ALL-LOG" /> -->
</root>
</log4j:configuration>
很好的介绍log4j的一篇文章,在这里分享下。