ikon999原创:Dwr2的日志代码分析

来源:互联网 发布:生化危机 知乎 编辑:程序博客网 时间:2024/05/17 20:31

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

 

webXml中加载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>

更多详情
0 0