Linux 日誌切割工具cronolog詳解:https://blog.csdn.net/chenkeqin_2012/article/details/52670887java
wget http://cronolog.org/download/cronolog-1.6.2.tar.gz tar zxvf cronolog-1.6.2.tar.gz cd cronolog-1.6.2./configure make && make install
which cronolog 通常狀況下顯示爲:/usr/local/sbin/cronolog
找到下面這行,相似這樣的行有2處:web
org.apache.catalina.startup.Bootstrap "$@" start \ >> "$CATALINA_OUT" 2>&1 &
第一處:tomcat是帶「-security」參數的啓動,shell
第二處:默認tomcat啓動方式,也就是else下面的那部分,咱們只修改這裏。apache
另外還要把touch 「$CATALINA_OUT"這行註釋掉。tomcat
# touch "$CATALINA_OUT" if [ "$1" = "-security" ] ; then if [ $have_tty -eq 1 ]; then echo "Using Security Manager" fi shift "$_RUNJAVA" "$LOGGING_CONFIG" $LOGGING_MANAGER $JAVA_OPTS $CATALINA_OPTS \ -Djava.endorsed.dirs="$JAVA_ENDORSED_DIRS" -classpath "$CLASSPATH" \ -Djava.security.manager \ -Djava.security.policy=="$CATALINA_BASE"/conf/catalina.policy \ -Dcatalina.base="$CATALINA_BASE" \ -Dcatalina.home="$CATALINA_HOME" \ -Djava.io.tmpdir="$CATALINA_TMPDIR" \ org.apache.catalina.startup.Bootstrap "$@" start \ >> "$CATALINA_OUT" 2>&1 & else "$_RUNJAVA" "$LOGGING_CONFIG" $LOGGING_MANAGER $JAVA_OPTS $CATALINA_OPTS \ -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/sbin/cronolog /usr/local/tomcat/logs/catalina.%Y%m%d.out >> /dev/null & # >> "$CATALINA_OUT" 2>&1 & fi
查看日誌目錄是否生成catalina.yymmdd.out的日誌文件bash
-rw-r--r-- 1 root root 10537 Jul 30 10:50 catalina.20140730.outapp
配置cronolog完成了,觀察天天是否有一個新的catalina.yymmdd.out的日誌文件生成,按期刪除日期較舊的日誌文件。ide
log4j.rootLogger=INFO, R log4j.appender.R=org.apache.log4j.RollingFileAppender log4j.appender.R.File=${catalina.home}/logs/tomcat.newlog #設定日誌文件名 log4j.appender.R.MaxFileSize=100KB #設定文件到100kb即分割 log4j.appender.R.MaxBackupIndex=10 #設定日誌文件保留的序號數 log4j.appender.R.layout=org.apache.log4j.PatternLayout log4j.appender.R.layout.ConversionPattern=%p %t %c - %m%n
#!/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}