November 2024
M T W T F S S
 123
45678910
11121314151617
18192021222324
252627282930  

Categories

November 2024
M T W T F S S
 123
45678910
11121314151617
18192021222324
252627282930  

Rotating catalina.out log files

It is possible to rotate the catalina.out log, by using a log rotation program like rotatelogs or cronolog.

It is possible to rotate the catalina.out log, but it is not controlled by the standard logging.properties or log4j.properties files.

The catalina.out log is stderr and stdout piped to a file. If you want to rotate this log file you will need to use a log rotation program like rotatelogs or cronolog. Then just pipe to the log rotation program rather than the file.

Here is an example of how to do this with cronolog. Using another program would be very similar, the command in step #3 would just be slightly different.

1.) Edit the bin/catalina.sh file.

2.) Find the following line and comment it out.

touch "$CATALINA_BASE"/logs/catalina.out

Note that in later versions of Tomcat this may look like:

touch "$CATALINA_OUT"

3.) Find the following line (there should be two instances of this line, replace both)

>> "$CATALINA_BASE"/logs/catalina.out 2>&1 &

and replace it with this line

2>&1 |/usr/bin/cronolog "$CATALINA_BASE/logs/catalina-%Y-%m-%d.out" &

Note that in later versions of Tomcat the line that needs to be replaced may look like:

>> "$CATALINA_OUT" 2>&1 &

4.) Save bin/catalina.sh

5.) Restart Tomcat.

You should now have a “catalina-2010-03-30.out” file in your logs directory. When the date changes a new log file will be created. The following day you should see “catalina-[following date].out”.

Please note that the log file may not be rotated exactly at midnight. It will rotate the first time something is written to the log after the date has changed. This generally isn’t a problem for busy log files.

Leave a Reply

You can use these HTML tags

<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>