rotating catalina.out in tomcat 5.5 using cronolog


Tags:

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...


a huge f'in problem at GMAC, i can already see it. good thing we have ol camel to take care of it.

One of the best and cleanest solutions I have ever seen for log management. Thanks a lot.

I tried the above method but problem is that we are runing tomcat from user tomcat and when I run "/logs permission denied" mesage appaears I use the chown to change the permission of /usr/sbin/cronolog but nothing happens.
good to see if some geek has a solution for it.

If I'm reading the post correctly, it would appear that the tomcat user does not have access to write to the directory under /logs. If you post the permissions for each directory in the path to the location that you are trying to write the logs to, we can probably help you out.

Hi,

Very insightful post indeed, but this solution works only when starting Tomcat from the catalina.bat script and not when running as a service (through tomcat5w). Is there a way to use cronolog in this case ? I have tried the --LogPath option without success so far.

I have to admit my windows skills are pretty laughable, but I'll ask around and see if anyone has a solution.