LOG4J 将debug等日志文件信息同时打印到控制台

时间:2021-10-23 21:50:35

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