方法1. 使用系统的logrotate转储日志
vi /etc/logrotate.d/tomcat-inter
/usr/local/tomcat-inter/logs/catalina.out /usr/local/tomcat-search/logs/catalina.out /usr/local/tomcat-sns/logs/catalina.out {
copytruncate
daily
rotate 120
nocompress
missingok
create
#create 0644 root root
##olddir /usr/local/dtt_xinhuaweb_bak/ (旧文件存放位置)
}
方法2.使用cronlog切割
wget
tar zxvf cronolog-1.6.2.tar.gz
cd cronolog-1.6.2
./configure –prefix=/usr/local/cronolog
make && make install
cd /usr/local/tomcat-inter/bin/
cp catalina.sh catalina.sh-20120508.bak
vi catalina.sh
-Djava.endorsed.dirs=”$JAVA_ENDORSED_DIRS” -classpath “$CLASSPATH” \
-Dcatalina.base=”$CATALINA_BASE” \
-Dcatalina.home=”$CATALINA_HOME” \
-Djava.io.tmpdir=”$CATALINA_TMPDIR” \
org.apache.catalina.startup.Bootstrap “$@” start 2>&1 \
|/usr/local/cronolog/sbin/cronolog “$CATALINA_BASE”/logs/catalina.out.%Y-%m-%d.out>> /dev/null &
重启tomcat
方法3. 使用log4j
wget
tar zxvf apache-log4j-1.2.16.tar.gz
cd apache-log4j-1.2.16
cp log4j-1.2.16.jar /usr/local/tomcat-inter/lib/
wget
cp tomcat-juli.jar /usr/local/tomcat-inter/bin/
wget
cp tomcat-juli-adapters.jar /usr/local/tomcat-inter/lib/
在$CATALINA_BASE/lib下新建log4j.properties
vi /usr/local/tomcat-inter/lib/log4j.properties
log4j.rootLogger=INFO, CATALINA
# Define all the appenders
log4j.appender.CATALINA=org.apache.log4j.DailyRollingFileAppender
log4j.appender.CATALINA.File=${catalina.base}/logs/catalina.
log4j.appender.CATALINA.Append=true
log4j.appender.CATALINA.Encoding=UTF-8
# Roll-over the log once per day
log4j.appender.CATALINA.DatePattern=’.'yyyy-MM-dd’.out’
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]=INFO, LOCALHOST
log4j.logger.org.apache.catalina.core.ContainerBase.[Catalina].[localhost].[/manager]=\
INFO, MANAGER
log4j.logger.org.apache.catalina.core.ContainerBase.[Catalina].[localhost].[/host-manager]=\
INFO, HOST-MANAGER