一、环境
操作系统: linux centos7
tomcat版本: tomcat7、8
二、步骤
1. 下载cronolog https://fossies.org/linux/www/old/cronolog-1.6.2.tar.gz
2. 解压cronolog tar zxvf 压缩包
3. 进入解压目录,输入命令
./configure
make && make install
4. 进入到tomcat目录下,打开bin/catalina.sh配置文件编辑
(1) 找到touch "$CATALINA_OUT"
前面加上"#"注释掉
#touch "$CATALINA_OUT"
(2) 找到类似下方的代码(有两处):
org.apache.catalina.startup.Bootstrap “$@” start \
>> “$CATALINA_OUT” 2>&1 “&”
修改为:
org.apache.catalina.startup.Bootstrap "$@" start 2>&1 \
|/usr/local/sbin/cronolog "$CATALINA_BASE"/logs/catalina.%Y-%m-%d.out >> /dev/null 2>&1 &
(注意:如果你的cronolog安装路径不是/usr/local/sbin/cronolog 那么则需要该改为你自己的路径>安装路径通过which cronolog查看)
(3) 找到类似下方的代码:
if [ -z "$CATALINA_OUT" ] ; then
CATALINA_OUT="$CATALINA_BASE"/logs/catalina.out
Fi
修改为:
if [ -z "$CATALINA_OUT" ] ; then
CATALINA_OUT="$CATALINA_BASE"/logs/catalina.%Y-%m-%d.out
fi