深入dwr2之一 Dwr2的日志代码分析
[url]http://column.ibeifeng.com/51564/2008100689.shtml[/url] 1、dwr log涉及的类: org.directwebremoting.util下的 Logger:dwr的日志类,Logger工厂; LoggingOutput :dwr日志输出接口 CommonsLoggingOutput :apache Commons log输出 ServletLoggingOutput :servlet 容器 log输出; 2、 log过程 (1) 加载dwrservlet,初始化StartupUtil类的log属性时,Log类在构造函数中判断是否有CommonsLog类,有的话,生成CommonsLoggingOutput对象;否则生成ServletLoggingOutput对象;实际的log操作是这2个对象完成的,logger类里持有LoggingOutput接口的引用; (2) ServletLoggingOutput 的日志输出可以由dwrservlet的 [code="java"] logLevel DEBUG [/code] 来控制; CommonsLoggingOutput的日志输出由log4j配置文件来控制,如: [code="java"]log4j.logger.org.directwebremoting=DEBUG,stdout, logfile log4j.logger.org.getahaed=DEBUG,stdout, logfile[/code] 如果没有以上2句,则由rootLogger来决定; commons-logging.properties [code="java"]org.apache.commons.logging.Log=org.apache.commons.logging.impl.Log4JLogger org.apache.commons.logging.LogFactory=org.apache.commons.logging.impl.Log4jFactory[/code] log4j.properties [code="java"]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] - <%m>%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[/code] 在web.Xml中加载log4j [code="java"] log4jConfigLocation /WEB-INF/log4j.properties org.springframework.web.util.Log4jConfigListener [/code]