标签:java
1)下载与tomcat对应版本的tomcat-juli.jar 和 tomcat-juli-adapters.jarhttp://archive.apache.org/dist/logging/log4j/1.2.17/
http://tomcat.apache.org/download-70.cgi
tomcat-juli-adapters.jar放入{$CATALINA_HOME}/lib
用新下载的tomcat-juli.jar替换掉$CATALINA_HOME/bin/中的tomcat-juli.jar;(下载的tomcat-juli.jar包含了所有Commons Logging实现,能够发现log4j和配置)
2)下载 log4j-1.2.17.jar放到 {$CATALINA_HOME}/lib
http://archive.apache.org/dist/logging/log4j/1.2.17/
3)删除$CATALINA_BASE/conf/logging.properties
4)修改 Tomcat 的 conf/context.xml 文件,将<Context>改为<Context swallowOutput="true">
5).将自己的log4j.properties放入{$CATALINA_HOME}/lib
### set log levels ### log4j.rootLogger = INFO,A,B,CONSOLE ### 输出到日志文件 ### log4j.appender.A = org.apache.log4j.DailyRollingFileAppender log4j.appender.A.File = ${catalina.home}/logs/interface.log log4j.appender.A.Append = true log4j.appender.A.Threshold = INFO log4j.appender.A.layout = org.apache.log4j.PatternLayout log4j.appender.A.layout.ConversionPattern = %-d{yyyy-MM-dd HH:mm:ss} [ %t:%r ] - [ %p ] %m%n ### 保存异常信息到单独文件 ### log4j.appender.B = org.apache.log4j.DailyRollingFileAppender log4j.appender.B.File = ${catalina.home}/logs/error.log log4j.appender.B.Append = true log4j.appender.B.Threshold = ERROR log4j.appender.B.layout = org.apache.log4j.PatternLayout log4j.appender.B.layout.ConversionPattern = %-d{yyyy-MM-dd HH:mm:ss} [ %l:%c:%t:%r ] - [ %p ] %m%n ### 保存异常信息到控制台 ### log4j.appender.CONSOLE = org.apache.log4j.ConsoleAppender log4j.appender.CONSOLE.Encoding = UTF-8 log4j.appender.CONSOLE.Threshold = ERROR log4j.appender.CONSOLE.layout = org.apache.log4j.PatternLayout log4j.appender.CONSOLE.layout.ConversionPattern = %-d{yyyy-MM-dd HH:mm:ss} [ %l:%c:%t:%r ] - [ %p ] %m%n
6)重启tomcat
标签:java
原文地址:http://blog.51cto.com/929044991/2091543