1. 打开log4j.properties文件
2. 根据不同的package类配置不同的logger,Level, Appender,如
#全局的日志级别
log4j.rootLogger=ERROR
#org.* 的日志级别和输出的Appender
log4j.logger.org=ERROR, A1
#com.java.test的日志级别和输出的Appender
log4j.logger.com.java.test=DEBUG,A2
#net.sf.hibernate的日志级别和输出的Appender
log4j.logger.net.sf.hibernate=ERROR,A3
3. 配置Appender
log4j.appender.A1=org.apache.log4j.RollingFileAppender
log4j.appender.A1.File=c:/logs/test-a1.log
log4j.appender.A1.MaxFileSize=500KB
log4j.appender.A1.MaxBackupIndex=50
log4j.appender.A1.Append=true
log4j.appender.A1.layout=org.apache.log4j.PatternLayout
log4j.appender.A1.layout.ConversionPattern=%d{ISO8601} - [%p] [%C{1}] - %m%n
log4j.appender.A2=org.apache.log4j.RollingFileAppender
log4j.appender.A2.File=c:/logs/test-a1.log
log4j.appender.A2.MaxFileSize=500KB
log4j.appender.A2.MaxBackupIndex=50
log4j.appender.A2.Append=true
log4j.appender.A2.layout=org.apache.log4j.PatternLayout
log4j.appender.A2.layout.ConversionPattern=%d{ISO8601} - [%p] [%C{1}] - %m%n
log4j.appender.A3=org.apache.log4j.RollingFileAppender
log4j.appender.A3.File=c:/logs/test-a3.log
log4j.appender.A3.MaxFileSize=500KB
log4j.appender.A3.MaxBackupIndex=50
log4j.appender.A3.Append=true
log4j.appender.A3.layout=org.apache.log4j.PatternLayout
log4j.appender.A3.layout.ConversionPattern=%d{ISO8601} - [%p] [%C{1}] - %m%n
log4j 应用例子
最新推荐文章于 2017-08-18 18:29:32 发布