2013-01-11 93 views
0

我設置Log4J以使用多個appender。這工作正常。但是,我想將默認日誌級別設置爲一個appender以進行DEBUG,並將特定類的日誌記錄限制爲INFO及更高級別。我想出了一些關於FA appender的作品,而不是DCSLOAD和DCSPROC appender。我究竟做錯了什麼?Log4J - 禁用特定類的日誌記錄 - 多個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 
+0

OK,我明白我需要做的。我改變了我的類級調試到這一點,它似乎現在正在工作:log4j.logger.LoginServlet = DEBUG –

回答

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 
+0

我做了這個改變,並且它關閉了所有appender的DEBUG日誌記錄。但是,當我在所有三個地方將LoginServlet類的日誌級別更改爲DEBUG時,我只得到FA appender調試,而不是DCSLOAD或DCSPROC appender。 –

+0

如果你想爲一個記錄器定義多個appender,你需要像這樣定義:log4j.logger.LoginServlet = INFO,FA,DCSLOAD,DCSPROC –