Log4j配置语句解释

 

 

 

 

 

 

log4j.rootLogger=INFO,ERR
log4j.appender.STDOUT=org.apache.log4j.ConsoleAppender 
log4j.appender.STDOUT.layout=org.apache.log4j.PatternLayout 
log4j.appender.STDOUT.layout.ConversionPattern=%d{yyyy-MM-dd HH\:mm\:ss} [\u8F93\u51FA\u65E5\u5FD7] %m%n

#Error Logger Configuration
log4j.logger.ERR=ERROR,ERR
log4j.appender.ERR=org.apache.log4j.RollingFileAppender
log4j.appender.ERR.File=../logs/mip.log
log4j.appender.ERR.Append=true
log4j.appender.ERR.MaxFileSize=1MB
log4j.appender.ERR.MaxBackupIndex=1
log4j.appender.ERR.layout=org.apache.log4j.PatternLayout
log4j.appender.ERR.layout.ConversionPattern=%d - %c [%t] %-5p %c %x %l - %m%n
log4j.additivity.ERR=false

 

 

 

 

log4j.rootLogger=INFO,ERR

 

指定日志记录的优先级,Log4j只建议使用4个,优先级从高到底分别为Error、Warn、Info、Debug

 

 

log4j.appender.STDOUT=org.apache.log4j.ConsoleAppender

 

指定日志输出的地方,这是输出到控制台

 

 

log4j.appender.STDOUT.layout=org.apache.log4j.PatternLayout 
log4j.appender.STDOUT.layout.ConversionPattern=%d{yyyy-MM-dd HH\:mm\:ss} [\u8F93\u51FA\u65E5\u5FD7] %m%n


指定日志输出格式

输出这种格式的语句:八月 07, 2013 9:26:34 上午 org.hibernate.cfg.HbmBinder bindCollectionSecondPass

 

 

 

log4j.appender.ERR=org.apache.log4j.RollingFileAppender
log4j.appender.ERR.File=../logs/mip.log
log4j.appender.ERR.Append=true
log4j.appender.ERR.MaxFileSize=1MB
log4j.appender.ERR.MaxBackupIndex=1

 

用文件输出日志信息,RollingFileAppender是按照文件大小来备份的,如果超过了默认的最大的10MB就会生成新的日志文件。不过在这个例子里面,MaxBackupIndex=1,即最大备份文件数为1.

 

 

log4j.additivity.ERR=false

 

 这句的意思没懂,查了一下文档,原文是:

Additivity is set to true by default, that is children inherit the appenders of their ancestors by default. If this variable is set to false then the appenders found in the ancestors of this category are not used. However, the children of this category will inherit its appenders, unless the children have their additivity flag set to false too. See the user manual for more details.

根据我的水平,我的理解是:默认是true,设为false即不沿用父类的appender

 

仅仅是开发笔记。不要来踩我了。

 

 

 

 

 

 

你可能感兴趣的:(log4j)