Linux下切分Tomcat的catalina.out日志文件 第2页

rotating catalina.out in tomcat 5.5 using cronolog
Submitted by theCamel on Tue, 08/14/2007 - 16:25.
Tags: Tomcat
Cronolog provides a solution to the age-old problem of tomcat's catalina.out log file not rotating and growing so large that the server must be stopped to deal with it.

First, install cronolog, which can be downloaded from here.

the cronolog command works like this:

cronolog [OPTIONS] logfile-spec

a simple example is:

cronolog /logs/catalina.out.%Y-%m-%d

so once output is piped to cronolog, it will create a logfile that looks like:

catalina.out.2007-08-14

and when the date changes, it creates a new file:

catalina.out.2007-08-15

so to configure, in the catalina.sh replace this string:

org.apache.catalina.startup.Bootstrap "$@" start \
>> "$CATALINA_BASE"/logs/catalina.out 2>&1 &


with this:

org.apache.catalina.startup.Bootstrap "$@" start 2>&1 \
| /usr/local/sbin/cronolog /logs/catalina.out.%Y-%m-%d >> /dev/null &


and the catalina.out will now be rotated daily and stored in the path we specified "/logs". If you wish to keep the logs in the tomcat logs dir, just specify that path in the cronolog command in catalina.sh

| cronolog "$CATALINA_BASE"/logs/catalina.out.%Y-%m-%d >> /dev/null &


I also removed this line from catalina.sh:

touch "$CATALINA_BASE"/logs/catalina.out


as it would no longer be necessary.

so now instead of one gigantic, ever-growing catalina.out, I have this:


catalina.2007-08-10.log
catalina.2007-08-11.log
catalina.2007-08-12.log
catalina.2007-08-13.log
catalina.2007-08-14.log
catalina.2007-08-15.log


and all my old log-removal scripts can work and I no longer have to stop the tomcat server just to deal with a log file...

内容版权声明:除非注明,否则皆为本站原创文章。

转载注明出处:https://www.heiqu.com/wyzyxx.html