随着Tomcat的运行,catalina.out文件会越来越大,虽然Tomcat每日会生成一个catalina.ymd.log的文件,但catalina.out主文件仍然不断增加,需要对catalina.out按日切分才好,在网上找了一下,看到一篇《rotating catalina.out in tomcat 5.5 using cronolog》,就用公司的Tomcat配置一下。
|
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...