log4j配置

China☆狼群 提交于 2020-03-20 08:54:38

java代码
this.logger = Logger.getLogger(Folder.class);
this.rcMarryGaofaLogger = Logger.getLogger("aoa");
//指定日志配置文件,这样在wrapper环境下可以单独配置日志
PropertyConfigurator.configure("log4j.properties");


log4j.properties

log4j.rootLogger= info, stdout, D

### direct log messages to stdout ###
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{yyyy-MM-dd HH:mm:ss} [ %t:%r ] - [ %p ] %m%n
log4j.appender.stdout.layout.ConversionPattern= %d %p %t [%C.%M(%L)] - <%m>%n

#每天生成一个文件
log4j.appender.D = org.apache.log4j.DailyRollingFileAppender
log4j.appender.D.File = C:/log.log
log4j.appender.D.Append = true
log4j.appender.D.Threshold = info
log4j.appender.D.layout = org.apache.log4j.PatternLayout
log4j.appender.D.MaxFileSize=50MB
log4j.appender.D.MaxBackupIndex=3
log4j.appender.D.layout.ConversionPattern = %d %p %t [%C.%M(%L)] - <%m>%n

# data log
log4j.logger.aoa= info, stdout, aoadata
#每天生成一个文件
log4j.appender.aoadata = org.apache.log4j.DailyRollingFileAppender
log4j.appender.aoadata.File = C:/data_log.log
log4j.appender.aoadata.Append = true
log4j.appender.aoadata.Threshold = info
log4j.appender.aoadata.layout = org.apache.log4j.PatternLayout
log4j.appender.aoadata.layout.ConversionPattern = %d %p %t [%C.%M(%L)] - <%m>%n
log4j.appender.aoadata.MaxFileSize=50MB
log4j.appender.aoadata.MaxBackupIndex=3

 

#指定一个类的日志级别

log4j.logger.com.framework.servlet=DEBUG

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!