我已经按如下方式配置了 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