spring log4j

vallenlsl 2010-02-15

关键字:springlog4j

spring对log4j提供了很好的支持。

web.xml中配置代码如下:

Java代码

<context-param>

<param-name>webAppRootKey</param-name>

<param-value>webName.root</param-value>

</context-param>

<context-param>

<param-name>log4jConfigLocation</param-name>

<param-value>WEB-INF/log4j.properties</param-value>

</context-param>

<context-param>

<param-name>log4jRefreshInterval</param-name>

<param-value>3000</param-value>

</context-param>

<listener>

<listener-class>

org.springframework.web.util.Log4jConfigListener

</listener-class>

</listener>

<context-param>

<param-name>webAppRootKey</param-name>

<param-value>webName.root</param-value>

</context-param>

<context-param>

<param-name>log4jConfigLocation</param-name>

<param-value>WEB-INF/log4j.properties</param-value>

</context-param>

<context-param>

<param-name>log4jRefreshInterval</param-name>

<param-value>3000</param-value>

</context-param>

<listener>

<listener-class>

org.springframework.web.util.Log4jConfigListener

</listener-class>

</listener>

这里webAppRootKey代表你的项目名

log4j.properties文件放在WEB-INF下

其代码如下:

Java代码

log4j.rootCategory=INFO,stdout,R

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

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

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

log4j.appender.R=org.apache.log4j.DailyRollingFileAppender

log4j.appender.R.File=${webName.root}/WEB-INF/logs/log.log

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

log4j.appender.R=org.apache.log4j.DailyRollingFileAppender

log4j.appender.R.DatePattern='.'yyyy-MM-dd

log4j.appender.R.layout.ConversionPattern=%d-[HL]%p%t%c-%m%n

log4j.logger.org.springframework=DEBUG

log4j.logger.com.ibatis.db=WARN

log4j.logger.org.hibernate=DEBUG

log4j.logger.org.hibernate.ps.PreparedStatementCache=WARN

log4j.logger.com.myproject=DEBUG

log4j.rootCategory=INFO,stdout,R

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

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

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

log4j.appender.R=org.apache.log4j.DailyRollingFileAppender

log4j.appender.R.File=${webName.root}/WEB-INF/logs/log.log

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

log4j.appender.R=org.apache.log4j.DailyRollingFileAppender

log4j.appender.R.DatePattern='.'yyyy-MM-dd

log4j.appender.R.layout.ConversionPattern=%d-[HL]%p%t%c-%m%n

log4j.logger.org.springframework=DEBUG

log4j.logger.com.ibatis.db=WARN

log4j.logger.org.hibernate=DEBUG

log4j.logger.org.hibernate.ps.PreparedStatementCache=WARN

log4j.logger.com.myproject=DEBUG

log4j.appender.R.File=${webName.root}/WEB-INF/logs/log.log指日志产生的路径在WEB-INF/logs/log.log

该配置是每天产生1个log文件

log4j.logger.org.springframework=DEBUG

log4j.logger.com.ibatis.db=WARN

log4j.logger.org.hibernate=DEBUG

log4j.logger.org.hibernate.ps.PreparedStatementCache=WARN

这里可以更详细的用日志来显示springhibernate/ibatis运行情况!可以通过该日志看到每个查询的list中每个对象数据。

相关推荐