cronolog配置tomcat日志自动切割

一、安装cronolog
二、配置 tomcat
找到 tomcat 中 bin 目录下的 catalina.sh 文件

  1. 查找
if [ -z "$CATALINA_OUT" ] ; then
  CATALINA_OUT=/opt/htdocs/logs/catalina.out
fi

修改为

if [ -z "$CATALINA_OUT" ] ; then
  CATALINA_OUT=/opt/htdocs/logs/catalina.%Y-%m-%d.out
fi
  1. 查找 touch "$CATALINA_OUT"
    注释掉#touch "$CATALINA_OUT"
  2. 查找"$CATALINA_OUT" 2>&1 "&"
    有两处
org.apache.catalina.startup.Bootstrap "$@" start \
>> "$CATALINA_OUT" 2>&1 "&"

都修改为 :

org.apache.catalina.startup.Bootstrap "$@" start \
| /usr/local/sbin/cronolog "$CATALINA_OUT" >> /dev/null &
  1. 重启 tomcat 服务,查看日志文件

你可能感兴趣的:(cronolog配置tomcat日志自动切割)