centos7使用cronolog分割tomcat8.5的catalina.out日志
Posted tarencez
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了centos7使用cronolog分割tomcat8.5的catalina.out日志相关的知识,希望对你有一定的参考价值。
1.安装cronolog
wget https://files.cnblogs.com/files/crazyzero/cronolog-1.6.2.tar.gz
tar -zxvf cronolog-1.6.2.tar.gz
cd cronolog-1.6.2
./configure
make && make install
或者 yum install cronolog
2.检查是否安装成功
which cronolog
正常显示 /usr/local/sbin/cronolog
3.tomcat8.5版本修改catalina.out文件
直接将第453-491的代码
shift
if [ -z "$CATALINA_OUT_CMD" ] ; then
touch "$CATALINA_OUT"
catalina_out_command=">> \\"$CATALINA_OUT\\" 2>&1"
else
catalina_out_command="| $CATALINA_OUT_CMD"
fi
if [ ! -z "$CATALINA_PID" ]; then
catalina_pid_file="$CATALINA_PID"
else
catalina_pid_file=/dev/null
fi
if [ "$1" = "-security" ] ; then
if [ $have_tty -eq 1 ]; then
echo "Using Security Manager"
fi
shift
eval \\{ $_NOHUP "\\"$_RUNJAVA\\"" "\\"$LOGGING_CONFIG\\"" $LOGGING_MANAGER $JAVA_OPTS $CATALINA_OPTS \\
-D$ENDORSED_PROP="\\"$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 "[email protected]" start \\
2\\>\\&1 \\&\\& echo \\$! \\>\\"$catalina_pid_file\\" \\; \\} $catalina_out_command "&"
else
eval \\{ $_NOHUP "\\"$_RUNJAVA\\"" "\\"$LOGGING_CONFIG\\"" $LOGGING_MANAGER $JAVA_OPTS $CATALINA_OPTS \\
-D$ENDORSED_PROP="\\"$JAVA_ENDORSED_DIRS\\"" \\
-classpath "\\"$CLASSPATH\\"" \\
-Dcatalina.base="\\"$CATALINA_BASE\\"" \\
-Dcatalina.home="\\"$CATALINA_HOME\\"" \\
-Djava.io.tmpdir="\\"$CATALINA_TMPDIR\\"" \\
org.apache.catalina.startup.Bootstrap "[email protected]" start \\
2\\>\\&1 \\&\\& echo \\$! \\>\\"$catalina_pid_file\\" \\; \\} $catalina_out_command "&"
fi
覆盖替换为
shift
#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 "[email protected]" start 2>&1 \\
| /usr/local/sbin/cronolog "$CATALINA_BASE"/logs/catalina.%Y-%m-%d_%H.out >> /dev/null &
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 "[email protected]" start 2>&1 \\
| /usr/local/sbin/cronolog "$CATALINA_BASE"/logs/catalina.%Y-%m-%d_%H.out >> /dev/null &
fi
参考文章:
https://blog.csdn.net/woshiji594167/article/details/80923795 cronolog下载地址
https://www.cnblogs.com/baobeiqi-e/p/10521522.html Tomcat8.5修改文件
https://blog.csdn.net/woshiji594167/article/details/80923795 三种方式
以上是关于centos7使用cronolog分割tomcat8.5的catalina.out日志的主要内容,如果未能解决你的问题,请参考以下文章
linux 下 使用cronolog对Tomcat 输出catalina.out 日志按照自定义日期格式进行切割 亲测可用