Log4J - 禁用特定类的日志记录 - 多个appender

时间:2013-01-11 14:22:58

标签: log4j

我设置Log4J以使用多个appender。这工作正常。但是,我想将默认日志级别设置为一个appender到DEBUG,并将特定类的日志记录限制为INFO及更高版本。我想出的是FA appender,但不是DCSLOAD和DCSPROC appender。我做错了什么?

# Set root logger level to DEBUG and its only appender to A1.
log4j.rootLogger = CA, FA

# CA is set to be a ConsoleAppender.
log4j.appender.CA=org.apache.log4j.ConsoleAppender

# CA uses PatternLayout.
log4j.appender.CA.layout=org.apache.log4j.PatternLayout
log4j.appender.CA.layout.ConversionPattern=%d{yyyy-MM-dd HH:mm:ss.SSS} [%t] %-5p %c{3} %x - %m%n

# FA uses PatternLayout.
log4j.appender.FA=org.apache.log4j.RollingFileAppender 
log4j.appender.FA.File=${catalina.base}/logs/dcs.log 
log4j.appender.FA.layout=org.apache.log4j.PatternLayout 
log4j.appender.FA.layout.ConversionPattern=%d{yyyy-MM-dd HH:mm:ss.SSS} [%t] %-5p %c{3} %x - %m%n
log4j.appender.FA.MaxFileSize=1024KB
log4j.appender.FA.MaxBackupIndex=100

# DCSPROC, DCSLOAD and DCSDB are all File Appenders to different targets
log4j.appender.DCSPROC=org.apache.log4j.RollingFileAppender
log4j.appender.DCSPROC.File=${catalina.base}/logs/dcs_process.log 
log4j.appender.DCSPROC.layout=org.apache.log4j.PatternLayout 
log4j.appender.DCSPROC.layout.ConversionPattern=%d{yyyy-MM-dd HH:mm:ss.SSS} [%t] %-5p %c{3} %x - %m%n
log4j.appender.DCSPROC.MaxFileSize=1024KB
log4j.appender.DCSPROC.MaxBackupIndex=100

log4j.appender.DCSLOAD=org.apache.log4j.RollingFileAppender
log4j.appender.DCSLOAD.File=${catalina.base}/logs/dcs_business.log 
log4j.appender.DCSLOAD.layout=org.apache.log4j.PatternLayout 
log4j.appender.DCSLOAD.layout.ConversionPattern=%d{yyyy-MM-dd HH:mm:ss.SSS} [%t] %-5p %c{3} %x - %m%n
log4j.appender.DCSLOAD.MaxFileSize=1024KB
log4j.appender.DCSLOAD.MaxBackupIndex=100

log4j.appender.DCSDB=org.apache.log4j.RollingFileAppender
log4j.appender.DCSDB.File=${catalina.base}/logs/dcs_database.log 
log4j.appender.DCSDB.layout=org.apache.log4j.PatternLayout 
log4j.appender.DCSDB.layout.ConversionPattern=%d{yyyy-MM-dd HH:mm:ss.SSS} [%t] %-5p %c{3} %x - %m%n
log4j.appender.DCSDB.MaxFileSize=1024KB
log4j.appender.DCSDB.MaxBackupIndex=100

# set default logging level for outputs
log4j.logger.CA = DEBUG
log4j.logger.FA = DEBUG

log4j.logger.DCSDB = DEBUG, DCSDB
log4j.logger.DCSPROC = DEBUG, DCSPROC
log4j.logger.DCSLOAD = DEBUG, DCSLOAD

log4j.additivity.DCSDB=false
log4j.additivity.DCSPROC=false
log4j.additivity.DCSLOAD=false

#This works
log4j.logger.LoginServlet=INFO, FA

#These two do not  
log4j.logger.LoginServlet=INFO, DCSLOAD
log4j.logger.LoginServlet=INFO, DCSPROC

1 个答案:

答案 0 :(得分:0)

改变这些:

    log4j.logger.DCSDB = DEBUG, DCSDB
    log4j.logger.DCSPROC = DEBUG, DCSPROC
    log4j.logger.DCSLOAD = DEBUG, DCSLOAD

    log4j.logger.DCSDB = DEBUG
    log4j.logger.DCSPROC = DEBUG
    log4j.logger.DCSLOAD = DEBUG