Log rotate (catalina.out) of Tomcat

Rotate Catalina.out of tomcat on On Linux (Centos 7) server


By default, Catalina.out file will not be rotated. To rotate it I have used logrotate.

First, understand the logrotate utility 


  1. Create tomcat file under /etc/logrotate.d/ using below command                               sudo vi /etc/logrotate.d/tomcat
  2. Press i to enable insert mode, past below script into file                                                               
    /opt/app/tomcat/logs/catalina.out {
     su myuser myusergroup
     missingok
     notifempty
     copytruncate
     daily
     size 5M
     rotate 7
    }
    Here /opt/app/tomcat/logs/catalina.out is path to your log file.
  3. press Esc key, then :wq! to write and quite (save) the file

Daily /etc/logrotate.conf will run which also include our tomcat file. So our log will be rotated next day.  To test everything configured well we can run below command with the debug mode (-d). Which won't affect any file just to debug. If you want to really test file rotation then run the same command with -v option

/usr/sbin/logrotate -d /etc/logrotate.d/tomcat



If your file is rotated when you run above command manually with -v option, but not rotating automatically with daily cron then you can try configuring crontab with your required schedule.


sudo crontab -u root -e

save the file with below cron

Everyday 1 AM:

0 1 * * * /usr/sbin/logrotate -v /etc/logrotate.d/tomcat  >/dev/null 2>&1


Everyday 11 PM and 1 AM:

0 1,23 * * * /usr/sbin/logrotate -v /etc/logrotate.d/tomcat  >/dev/null 2>&1

Comments

Popular posts from this blog

Git Auto Increment tag

Bypass SSL certificate check for Apache Axis2 client