spring中集成log4j

在spring中集成log4j,进行日志的记录。

需要引入log4j.jar包

在web.xml文件中添加以下代码:

<!-- log4j的配置 -->
  <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>
  <!-- log4j结束 -->

 

webAppRootKey代表项目名称
将log4j.properties文件放在WEB-INF下

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

 

日志产生的路径在WEB-INF/logs/log.log

下面上传log4j.jar包

你可能感兴趣的:(spring,log4j,日志)