Log4j配置文件

使用${webapp.root}配置相对路径


log4j.properties:
 ### set log levels ###
log4j.rootLogger = info,CONSOLE,INFO,ERROR

### 输出到控制台 ###
log4j.appender.CONSOLE = org.apache.log4j.ConsoleAppender
log4j.appender.CONSOLE.Threshold = INFO
log4j.appender.CONSOLE.Target = System.out
log4j.appender.CONSOLE.layout = org.apache.log4j.PatternLayout
log4j.appender.CONSOLE.layout.ConversionPattern =  %d %-5p [%c{1}] %m%n

### 输出到日志文件 ###
log4j.appender.INFO = org.apache.log4j.DailyRollingFileAppender
log4j.appender.INFO.File = ${webapp.root}/logs/info.log
log4j.appender.INFO.Append = true
## 输出INFO级别以上的日志
log4j.appender.INFO.Threshold = INFO
log4j.appender.INFO.layout = org.apache.log4j.PatternLayout
log4j.appender.INFO.layout.ConversionPattern = %-d{yyyy-MM-dd HH:mm:ss}  [ %t:%r ] - [ %p ]  %m%n
log4j.appender.INFO.DatePattern = '.'yyyy-MM-dd

### 保存异常信息到单独文件 ###
log4j.appender.ERROR = org.apache.log4j.DailyRollingFileAppender
## 异常日志文件名
log4j.appender.ERROR.File = ${webapp.root}/logs/error.log
log4j.appender.ERROR.Append = true
## 只输出ERROR级别以上的日志!!!
log4j.appender.ERROR.Threshold = ERROR
log4j.appender.ERROR.layout = org.apache.log4j.PatternLayout
log4j.appender.ERROR.layout.ConversionPattern = %-d{yyyy-MM-dd HH:mm:ss}  [ %t:%r ] - [ %p ]  %m%n
log4j.appender.ERROR.DatePattern = '.'yyyy-MM-dd


该配置需要Spring支持!!
web.xml配置
<context-param>
		<param-name>log4jConfigLocation</param-name>
		<param-value>WEB-INF/classes/log4j.properties</param-value>
	</context-param>
	<context-param>
		<param-name>log4jRefreshInterval</param-name>
		<param-value>6000</param-value>
	</context-param>
<listener>
		<listener-class>org.springframework.web.util.Log4jConfigListener</listener-class>
	</listener>

你可能感兴趣的:(log4j)