log4j中的记录器和附加器

时间:2012-06-08 19:55:18

标签: log4j

我已按如下方式配置Logger和Appender。 我面临的问题是我没有在每个FileAppender中获得指定的阈值日志级别意味着每个FileAppender都具有跟踪级别的输出而不是已配置 但是,每个FileAppender的阈值级别 consoleAppender在日志级别方面运行良好。

#Configuring multiple logger and appender
log4j.rootLogger=trace,consoleA,file1A,file2A

log4j.appender.consoleA=org.apache.log4j.ConsoleAppender
log4j.appender.consoleA.Target=System.out
log4j.appender.consoleA.Threshold=ERROR
log4j.appender.consoleA.layout=org.apache.log4j.PatternLayout
log4j.appender.consoleA.layout.ConversionPattern=%d{ABSOLUTE} %5p %c{1}:%L - %m%n

#File1 Appender
log4j.appender.file1A=org.apache.log4j.RollingFileAppender
log4j.appender.file1A.File=C:\\loging.log
log4j.appender.file1A.MaxFileSize=1MB
log4j.appender.file1A.MaxBackupIndex=1
log4j.appender.file1A.Threshold=WARN
log4j.appender.file1A.layout=org.apache.log4j.PatternLayout
log4j.appender.file1A.layout.ConversionPattern=%d{ABSOLUTE} %5p %c{1}:%L - %m%n

#File2 Appender
log4j.appender.file2A=org.apache.log4j.RollingFileAppender
log4j.appender.file2A.File=C:\\loging2.log
log4j.appender.file2A.MaxFileSize=1MB
log4j.appender.file1A.Threshold=DEBUG
log4j.appender.file2A.MaxBackupIndex=1
log4j.appender.file2A.layout=org.apache.log4j.PatternLayout
log4j.appender.file2A.layout.ConversionPattern=%d{ABSOLUTE} %5p %c{1}:%L - %m%n

1 个答案:

答案 0 :(得分:0)

您的配置中有一些拼写错误。首先,我认为水平应该是CAPS。

log4j.rootLogger=TRACE,consoleA,file1A,file2A

您还定义了file1A阈值两次,但未定义file2A的阈值

log4j.appender.file1A.Threshold=WARN
log4j.appender.file1A.Threshold=DEBUG