Thursday, June 18, 2015

Tomcat Logging: a Lesson in Half-Baked

Out of the box, Tomcat logging will output to catalina.out, until your hard drive is brought to its knees.  We won't hold our breath for the day that logrotate is implemented natively on those files in the logs folder.

Instead, here's how to logrotate that pesky catalina.out file.

1. In your Tomcat, navigate to .../bin/catalina.sh
2. Within catalina.sh, search for this keyword: "catalina.out"
3.  Now, by default, catalina.out will be set to "CATALINA_BASE"\logs\catalina.out
4.  LogRotate can't seem to operate in Tomcat's logs folder.  So, let's move the file somewhere else.  Let's say, /var/log/tomcat, for example.
5.  Next, let's configure a logrotate file that cron will operate on.
6.  Navigate to /etc/logrotate.d
7.  Create the file, "tomcat" and add the following configuration:
Based on this configuration, cron will copy and truncate the catalina.out file daily.  logrotate will keep seven days worth of catalina.out logs
8.  Let's save out a catalina.out file: sudo vi /var/log/tomcat/catalina.out
9.  To make things more user friendly, let's put a symbolic link in Tomcat's logs folder
10. Navigate to Tomcat's logs folder
11. Then: sudo ln -s /var/log/tomcat/catalina.out catalina.out

12. Finally, for all of this to take effect, we'll need to restart Tomcat
13. So, sudo ../bin/shutdown.sh
14. Then ../bin/startup.sh

Please note, cron has it's own notion when it'll perform the logrotate.  My system performs the operation at 3am.

No comments:

Post a Comment