1. 程式人生 > >LOG4J 將debug等日誌檔案資訊同時列印到控制檯

LOG4J 將debug等日誌檔案資訊同時列印到控制檯

如果希望將debug、info等寫入日誌檔案的資訊同時列印到控制檯,

需要在log4j中配置控制檯,並且在為log4j.rootLogger賦值時,最後一個新增控制檯資訊,

我目前的配置結果如下:

log4j.rootLogger=debug,infofile,errorlogfile,D,stdout

log4j.appender.infofile = org.apache.log4j.DailyRollingFileAppender
log4j.appender.infofile.Threshold = INFO
log4j.appender.infofile.File = E/://logs//20101222//loginfo

log4j.appender.infofile.Append = true
log4j.appender.infofile.ImmediateFlush = true
log4j.appender.infofile.DatePattern = '_'yyyyMMdd'.log '
log4j.appender.infofile.layout = org.apache.log4j.PatternLayout
log4j.appender.infofile.layout.ConversionPattern = /#ARCHIVEINFO/#%d{yyyy-MM-dd HH/:mm/:ss}%m%n

log4j.appender.D = org.apache.log4j.RollingFileAppender
log4j.appender.D.File = E/://logs//20101222//logdebug.log
log4j.appender.D.MaxFileSize=1024KB
log4j.appender.D.MaxBackupIndex = 10000
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}]%-5p %c(line/:%L) %x-%m%n

log4j.appender.errorlogfile = org.apache.log4j.RollingFileAppender
log4j.appender.errorlogfile.Threshold = ERROR
log4j.appender.errorlogfile.File = E/://logs//20101222//logerror.log
log4j.appender.errorlogfile.Append = true
log4j.appender.errorlogfile.layout = org.apache.log4j.PatternLayout
log4j.appender.errorlogfile.layout.ConversionPattern =%d{yyyy-MM-dd HH:mm:ss} [%c] %m -(:%L)%n

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}]%-5p %c(line/:%L) %x-%m%n