1. 程式人生 > >spring配置log4j

spring配置log4j

一.web.xml配置

<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>600000</param-value>

</context-param

>

<listener>

<listener-class>org.springframework.web.util.Log4jConfigListener</listener-class>

</listener>

二. log4j.properties配置

#log4j.rootLogger = [ level ] , appenderName, appenderName, ...

log4j.rootLogger = ALL,console,allR

#branch logger

log4j.logger.InfoLogger = INFO,infoR

log4j.logger.ErrorLogger = ERROR,errorR

log4j.logger.org.springframework=ERROR

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

log4j.logger.org.hibernate=DEBUG

#console

log4j.appender.console = org.apache.log4j.ConsoleAppender

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

log4j.appender.console.layout.ConversionPattern = %-d{yyyy-MM-ddHH:mm:ss}[%c]-[%p]%m%n

#infoR

log4j.appender.infoR = org.apache.log4j.RollingFileAppender

log4j.appender.infoR.File =D://logs/info/infoLog.txt

log4j.appender.infoR.MaxFileSize = 50MB

log4j.appender.infoR.MaxBackupIndex = 1000

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

log4j.appender.infoR.layout.ConversionPattern=%-d{yyyy-MM-ddHH:mm:ss}[%c]-[%p]-%m%n

#errorR

log4j.appender.errorR = org.apache.log4j.RollingFileAppender

log4j.appender.errorR.File =D://logs/error/errorLog.txt

log4j.appender.errorR.MaxFileSize = 50MB

log4j.appender.errorR.MaxBackupIndex = 1000

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

log4j.appender.errorR.layout.ConversionPattern=%-d{yyyy-MM-ddHH:mm:ss}[%c]-[%p]-%m%n

#allR

log4j.appender.allR = org.apache.log4j.RollingFileAppender

log4j.appender.allR.File =D://logs/all/allLog.txt

log4j.appender.allR.MaxFileSize = 500MB

log4j.appender.allR.MaxBackupIndex = 1000

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

log4j.appender.allR.layout.ConversionPattern=%-d{yyyy-MM-ddHH\:mm\:ss}[%c]-[%p]-%m%n

三.Log4j-1-1-16.jar