spring log4j.properties

时间:2020-12-15 02:56:49

log4j.properties

log4j.rootLogger=info,appender2,appender3
#appender2\u914D\u7F6E FileAppender
log4j.appender.appender2=org.apache.log4j.FileAppender
log4j.appender.appender2.Threshold=info
log4j.appender.appender2.ImmediateFlush=true
log4j.appender.appender2.File=${myappfuse.root}/WEB-INF/logs/mylog.log
log4j.appender.appender2.Append=true
#log4j.appender.appender2.encoding=gbk
log4j.appender.appender2.layout=org.apache.log4j.PatternLayout
log4j.appender.appender2.layout.ConversionPattern=%d{yyyy/MM/dd hh:mm:ss} %m %n #appender2\u914D\u7F6E FileAppender
log4j.appender.appender3=org.apache.log4j.FileAppender
log4j.appender.appender3.Threshold=debug
log4j.appender.appender3.ImmediateFlush=true
log4j.appender.appender3.File=${myappfuse.root}/WEB-INF/logs/debug.log
log4j.appender.appender3.Append=true
#log4j.appender.appender2.encoding=gbk
log4j.appender.appender3.layout=org.apache.log4j.PatternLayout
log4j.appender.appender3.layout.ConversionPattern=%d{yyyy/MM/dd hh:mm:ss} %m %n

在web.xml里添加如下代码

<context-param>
<param-name>webAppRootKey</param-name>
<param-value>myappfuse.root</param-value>
</context-param>
<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></param-value>
</context-param>
<listener>
<listener-class>org.springframework.web.util.Log4jConfigListener</listener-class>
</listener>

注意:log4j.properties文件位置放在src下