1.可用配置:
log4j.rootCategory=DEBUG, 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.Encoding=UTF-8
log4j.appender.R.File=${myappfuse.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.org.hibernate=DEBUG
log4j.logger.org.hibernate.ps.PreparedStatementCache=WARN
log4j.logger.com.myproject=DEBUG
cn.jiankang51.hsps.web=DEBUG
2.其中指定了字符编码为UTF-8
如果字符编码无效,仍然出现乱码,可以在notepad++之类的文本编辑器中以ANSI格式查看即可。
3.log4j.appender.R.File=${myappfuse.root}/WEB-INF/logs/log.log
这个指定了log4j的日志文件存放地址
其中类EL表达式中的变量是在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>
<listener>
<listener-class>org.springframework.web.util.Log4jConfigListener</listener-class>
</listener>