tomcat7 日志设置为log4j
tomcat的日志设置用log4j的官方文档:http://tomcat.apache.org/tomcat-7.0-doc/logging.html
1. 下载tomcat-juli.jar,
tomcat-juli-adapters.jar
http://tomcat.apache.org/download-70.cgi
2. 下载log4j v1.2.x
http://logging.apache.org/log4j/1.2/download.html
3. 配置
(1) log4j.jar和tomcat-juli-adapters.jar拷贝至 $CATALINA_HOME/lib/下
(2) tomcat-juli.jar拷贝至$CATALINA_HOME/bin/下,覆盖原来的jar
(3) 删除 $CATALINA_BASE/conf/logging.properties
(4) log4j.properties放在$CATALINA_BASE/lib/下
log4j.properties的内容的例子:
# # Log4J Settings for log4j 1.2.x (via jakarta-commons-logging) # # The five logging levels used by Log are (in order): # # 1. DEBUG (the least serious) # 2. INFO # 3. WARN # 4. ERROR # 5. FATAL (the most serious) # Set root logger level to WARN and append to stdout log4j.rootLogger=INFO, fileLog log4j.appender.stdout=org.apache.log4j.ConsoleAppender log4j.appender.stdout.layout=org.apache.log4j.PatternLayout # Pattern to output the caller's file name and line number. log4j.appender.stdout.layout.ConversionPattern=%d %5p (%c:%L) - %m%n #-----------------------append:webappLog-------------------- log4j.appender.fileLog=org.apache.log4j.RollingFileAppender log4j.appender.fileLog.File=/home/webadmin/tomcat/logs/tomcat.log log4j.appender.fileLog.MaxFileSize=10000KB log4j.appender.fileLog.MaxBackupIndex=2 log4j.appender.fileLog.append=true log4j.appender.fileLog.layout=org.apache.log4j.PatternLayout log4j.appender.fileLog.layout.ConversionPattern=%d %5p (%c:%L) - %m%n # Print only messages of level ERROR or above in the package noModule. log4j.logger.noModule=FATAL
最后重启tomcat。