ikon999原創:Dwr2的日誌程式碼分析

beifengwang發表於2014-03-10

1、dwr log涉及的類:

org.directwebremoting.util下的

Loggerdwr的日誌類,Logger工廠;

LoggingOutputdwr日誌輸出介面

CommonsLoggingOutputapache Commons log輸出

ServletLoggingOutputservlet 容器 log輸出;

 

2、log過程

(1)載入dwrservlet,初始化StartupUtil類的log屬性時,Log類在建構函式中判斷是否有CommonsLog類,有的話,生成CommonsLoggingOutput物件;否則生成ServletLoggingOutput物件;實際的log操作是這2個物件完成的,logger類裡持有LoggingOutput介面的引用;

(2)ServletLoggingOutput的日誌輸出可以由dwrservlet

<init-param>

<param-name>logLevelparam-name>

<param-value>DEBUGparam-value>

init-param>

來控制;

CommonsLoggingOutput的日誌輸出由log4j配置檔案來控制,如:

log4j.logger.org.directwebremoting=DEBUG,stdout, logfile

log4j.logger.org.getahaed=DEBUG,stdout, logfile

如果沒有以上2句,則由rootLogger來決定;

 

commons-logging.properties

org.apache.commons.logging.Log=org.apache.commons.logging.impl.Log4JLogger

org.apache.commons.logging.LogFactory=org.apache.commons.logging.impl.Log4jFactory

 

log4j.properties

log4j.rootLogger=INFO,stdout

 

log4j.logger.org.directwebremoting=DEBUG,stdout, logfile

log4j.logger.org.getahaed=DEBUG,stdout, logfile

 

log4j.appender.stdout=org.apache.log4j.ConsoleAppender

log4j.appender.stdout.layout=org.apache.log4j.PatternLayout

log4j.appender.stdout.layout.ConversionPattern=%d%p[%c]-%n

 

log4j.appender.logfile=org.apache.log4j.RollingFileAppender

log4j.appender.logfile.File=D:/ikonweb/dwrtest/log/dwrtest.log

log4j.appender.logfile.MaxFileSize=51200KB

# Keep three backup files.

log4j.appender.logfile.MaxBackupIndex=3

# Pattern to output: date priority [category] - message

log4j.appender.logfile.layout=org.apache.log4j.PatternLayout

log4j.appender.logfile.layout.ConversionPattern=%d%p[%c]-%m%n

 

webXml中載入log4j

log4jConfigLocation

/WEB-INF/log4j.properties

org.springframework.web.util.Log4jConfigListener

來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/29212814/viewspace-1104401/,如需轉載,請註明出處,否則將追究法律責任。

相關文章