Selecting a log rotation tool
By default, Apache Tomcat and vFabric tc Server redirect the output from
STDOUT
and
STDERR
directly to a file. To rotate this log file, the output from
STDOUT
and
STDERR
must instead be piped to an intermediate tool that is capable of rotating the log file. There are a few existing tools that can be used:
Note: VMware does not endorse or recommend any particular third-party utility, nor is the list below meant to be exhaustive.
rotatelogs
If you already have Apache HTTP Server, vFabric ERS HTTPD, or vFabric Web Server installed, you can use the rotatelogs
tool that is packaged with this software. This is the same tool that these software packages use to rotate their log files. For more information, see the rotatelogs documentation.
cronolog
This is a third-party, Open Source log rotation tool that is very similar to rotatelogs
. It can be installed directly from http://cronolog.org/ or possibly through your operating system's package manager.
- If you do not want to use a third-party tool, you can write your own script. The script would simply need to receive log data via
STDIN
and handle writing it to some log location.
Once you have
rotatelogs
,
cronolog
, or another similar tool installed, you must then modify the
catalina.sh
script so that it will pipe to the tool rather than redirect directly to a file.
Modifications for vFabric tc Server
- Open the
$TCSERVER_INSTALL/tomcat-x.x.x.RELEASE/bin/catalina.sh
file in a text editor. - Search for and delete this line:
touch "$CATALINA_OUT"
- Search for this line, which occurs twice in the file:
>> "$CATALINA_OUT" 2>&1 &
- For daily rotation, replace both occurrences of the line from the previous step with one of these lines. Choose the line that matches the log rotation tool that is installed on your system.
rotatelogs
2>&1 |/usr/bin/rotatelogs "$CATALINA_BASE/logs/catalina.out" 86400 &
cronolog
2>&1 |/usr/bin/cronolog "$CATALINA_BASE/logs/catalina-%Y-%m-%d.out" &
- Custom script
2>&1 |/usr/bin/myapp arg1 arg2 ... argX &
Note: The commands above assume the tool is installed in the /usr/bin
directory. Adjust the path to the executable as required for your system.
- To use a different log rotation scheme, such as rotate by size, simply adjust the command listed in the previous step.
- Restart the vFabric tc Server instance to activate the changes.
Modifications for Apache Tomcat
- Open the
$CATALINA_HOME/bin/catalina.sh
file in a text editor. - Search for and delete this line:
touch "$CATALINA_BASE"/logs/catalina.out
- Search for this line, which occurs twice in the file:
$CATALINA_BASE"/logs/catalina.out 2>&1 &
- For daily rotation, replace both occurrences of the line from the previous step with one of these lines. Choose the line that matches the log rotation tool that is installed on your system.
rotatelogs
2>&1 |/usr/bin/rotatelogs "$CATALINA_BASE/logs/catalina.out" 86400 &
cronolog
2>&1 |/usr/bin/cronolog "$CATALINA_BASE/logs/catalina-%Y-%m-%d.out" &
- Custom script
2>&1 |/usr/bin/myapp arg1 arg2 ... argX &
Note: The commands above assume the tool is installed in the /usr/bin
directory. Adjust the path to the executable as required for your system.
- To use a different log rotation scheme, such as rotate by size, simply adjust the command listed in the previous step.
- Restart Apache Tomcat to activate the changes.