spring对log4j提供了很好的支持。
web.xml中配置代码如下:
[code]
<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>
[/code]
这里webAppRootKey代表你的项目名
log4j.properties文件放在WEB-INF下
其代码如下:
[code]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
[/code]
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
这里可以更详细的用日志来显示spring hibernate/ibatis 运行情况!可以通过该日志看到每个查询的list中每个对象数据。
web.xml中配置代码如下:
[code]
<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>
[/code]
这里webAppRootKey代表你的项目名
log4j.properties文件放在WEB-INF下
其代码如下:
[code]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
[/code]
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
这里可以更详细的用日志来显示spring hibernate/ibatis 运行情况!可以通过该日志看到每个查询的list中每个对象数据。