深入dwr2之一 Dwr2的日志代码分析

转自: http://column.ibeifeng.com/51564/2008100689.shtml
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的


<init-param>   
  
<param-name>logLevel</param-name>   
  
<param-value>DEBUG</param-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] - <%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  


在web.Xml中加载log4j
<context-param>   
  
<param-name>log4jConfigLocation</param-name>   
  
<param-value>/WEB-INF/log4j.properties</param-value>   
  
</context-param>   
  
<listener>   
  
<listener-class>   
  
org.springframework.web.util.Log4jConfigListener   
  
</listener-class>   
  
</listener>  

你可能感兴趣的:(java,apache,Web,log4j,DWR)