如果希望將debug、info等寫入日志文件的信息同時打印到控制臺,,
需要在log4j中配置控制臺,,并且在為log4j.rootLogger賦值時,最后一個添加控制臺信息,,
我目前的配置結(jié)果如下:
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