Log4j Java 配置 1.2.8


Log4j 配置


环境:

Eclipse Version: Kepler Service Release 1
Build id: 20130919-0819


JDK 1.7



1. 下载log4j jar包,可以从下面附件中拿到  

http://download.csdn.net/detail/robinson111/6890559

2. 在你的工程中添加外部jar, 把log4j-1.2.8.jar 添加进去

3. 在src 根目录下,建立文件log4j.properties

http://download.csdn.net/detail/robinson111/6890561

内容如下(或者从附件中下载)

### set log levels ###
log4j.rootLogger = info, 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


### 输出到日志文件 ###
log4j.appender.D = org.apache.log4j.DailyRollingFileAppender
log4j.appender.D.File = C:/logs/info.log
log4j.appender.D.Append = true
log4j.appender.D.Threshold = DEBUG 
log4j.appender.D.layout = org.apache.log4j.PatternLayout
log4j.appender.D.layout.ConversionPattern = %-d{yyyy-MM-dd HH:mm:ss} [ %t:%r ] - [ %p ] %m%n


### 保存异常信息到单独文件 ###
log4j.appender.E = org.apache.log4j.DailyRollingFileAppender
log4j.appender.E.File = C:/logs/error.log 
log4j.appender.E.Append = true
log4j.appender.E.Threshold = ERROR 
log4j.appender.E.layout = org.apache.log4j.PatternLayout
log4j.appender.E.layout.ConversionPattern = %-d{yyyy-MM-dd HH:mm:ss} [ %t:%r ] - [ %p ] %m%n



大功告成




Log4j Java 配置 1.2.8

上一篇:LeetCode OJ:Merge Intervals


下一篇:合并排序(MergeSort)