Log4j配置经验点滴

在一同事配置的Log4j中,配置有两个.properties文件(serverl.log4j.properties和wap.log4j.properties),先加载的server.log4j.properties,使用如下语句:

PropertyConfigurator.configureAndWatch

在启动后,相关日志如愿记录入:server.log4j.properties中定义的文件;

#### Use two appenders, one to log to console, another to log to a file
log4j.rootLogger=debug, server01, stdout

log_dir=/opt/aspire/product/download/mmdlsjava/logs

log4j.logger.org.apache=warn

log4j.category.SERVER01=DEBUG,server01
log4j.appender.server01=org.apache.log4j.RollingFileAppender
log4j.appender.server01.Append=true
log4j.appender.server01.MaxFileSize=1024KB
log4j.appender.server01.MaxBackupIndex=100
log4j.appender.server01.File=${log_dir}/server_app.log
log4j.appender.server01.layout=org.apache.log4j.PatternLayout
log4j.appender.server01.layout.ConversionPattern=[%d{yyyy-MM-dd HH:mm:ss}]%-5p[%t]%x(%F:%L) - %m%n

log4j.category.SERVER02=DEBUG,server02
log4j.appender.server02=org.apache.log4j.DailyRollingFileAppender
log4j.appender.server02.Append=true
log4j.appender.server02.File=${log_dir}/server_app.log
log4j.appender.server02.layout=org.apache.log4j.PatternLayout
log4j.appender.server02.layout.ConversionPattern=[%d{yyyy-MM-dd HH:mm:ss}]%-5p[%t]%x(%F:%L) - %m%n
log4j.appender.server02.DatePattern='_'yyyyMMdd

#### First appender writes to console
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}]%-5p[%t]%x(%F:%L) - %m%n

注意红色字体部分,上面有说tomcat也会使用这个日志文件,使用这一样屏蔽掉tomcat等相关的调试日志,否则将产生一大堆tomcat的日志;

 

你可能感兴趣的:(apache,tomcat,log4j,F#,WAP)