tomcat使用log4j分割
官方文档
下载tomcat-juli-adapters.jar和tomcat-juli.jar 和log4j.jar
将tomcat-juli-adapters.jar和log4j.jar拷贝到 tomcat目录\lib下
将tomcat-juli.jar放到 tomcat目录\bin下
删除tomcat/conf下的logging.properties
在tomcat/lib下创建log4j.properties文件(多节点情况下请把${catalina.base}改为实际的tomcat目录)
log4j.rootLogger = INFO, CATALINA # Define all the appenders #log4j.appender.CATALINA = org.apache.log4j.DailyRollingFileAppender log4j.appender.CATALINA = org.apache.log4j.RollingFileAppender log4j.appender.CATALINA.File = ${catalina.base}/logs/catalina.out log4j.appender.CATALINA.Append = true log4j.appender.RollingFile.ImmediateFlush=true log4j.appender.CATALINA.Encoding = UTF-8 # Roll-over the log once per day #log4j.appender.CATALINA.DatePattern = '.'yyyy-MM-dd'.log' log4j.appender.CATALINA.MaxFileSize=1MB log4j.appender.CATALINA.MaxBackupIndex=10 log4j.appender.CATALINA.layout = org.apache.log4j.PatternLayout log4j.appender.CATALINA.layout.ConversionPattern = %d [%t] %-5p %c- %m%n log4j.appender.LOCALHOST = org.apache.log4j.DailyRollingFileAppender log4j.appender.LOCALHOST.File = ${catalina.base}/logs/localhost log4j.appender.LOCALHOST.Append = true log4j.appender.LOCALHOST.Encoding = UTF-8 log4j.appender.LOCALHOST.DatePattern = '.'yyyy-MM-dd'.log' log4j.appender.LOCALHOST.layout = org.apache.log4j.PatternLayout log4j.appender.LOCALHOST.layout.ConversionPattern = %d [%t] %-5p %c- %m%n log4j.appender.MANAGER = org.apache.log4j.DailyRollingFileAppender log4j.appender.MANAGER.File = ${catalina.base}/logs/manager log4j.appender.MANAGER.Append = true log4j.appender.MANAGER.Encoding = UTF-8 log4j.appender.MANAGER.DatePattern = '.'yyyy-MM-dd'.log' log4j.appender.MANAGER.layout = org.apache.log4j.PatternLayout log4j.appender.MANAGER.layout.ConversionPattern = %d [%t] %-5p %c- %m%n log4j.appender.HOST-MANAGER = org.apache.log4j.DailyRollingFileAppender log4j.appender.HOST-MANAGER.File = ${catalina.base}/logs/host-manager log4j.appender.HOST-MANAGER.Append = true log4j.appender.HOST-MANAGER.Encoding = UTF-8 log4j.appender.HOST-MANAGER.DatePattern = '.'yyyy-MM-dd'.log' log4j.appender.HOST-MANAGER.layout = org.apache.log4j.PatternLayout log4j.appender.HOST-MANAGER.layout.ConversionPattern = %d [%t] %-5p %c- %m%n log4j.appender.CONSOLE = org.apache.log4j.ConsoleAppender log4j.appender.CONSOLE.Encoding = UTF-8 log4j.appender.CONSOLE.layout = org.apache.log4j.PatternLayout log4j.appender.CONSOLE.layout.ConversionPattern = %d [%t] %-5p %c- %m%n # Configure which loggers log to which appenders log4j.logger.org.apache.catalina.core.ContainerBase.[Catalina].[localhost] = DEBUG, LOCALHOST log4j.logger.org.apache.catalina.core.ContainerBase.[Catalina].[localhost].[/manager] = DEBUG, MANAGER log4j.logger.org.apache.catalina.core.ContainerBase.[Catalina].[localhost].[/host-manager] = DEBUG, HOST-MANAGER log4j.logger.org.apache.catalina.core = DEBUG log4j.logger.org.apache.catalina.session = DEBUG
|
注释掉catalina.sh的自动生成catalina.out
if [ -z "$CATALINA_OUT" ] ; then #CATALINA_OUT="$CATALINA_BASE"/logs/catalina.out CATALINA_OUT=/dev/null fi
|
Tomcat使用定时任务分割
编写shell脚本,放在tomcat/bin下,在cron中自动执行
#!/bin/bash
cd `dirname $0` d=`date +%Y%m%d` d7=`date -d'7 day ago' +%Y%m%d`
cd ../logs/
cp catalina.out catalina.out.${d} echo "" > catalina.out rm -rf catalina.out.${d7}
|