Tag Archives: catalina.out

[Solved] Too large catalina.out file of Tomcat (logrotate mode)

Problem:

sudo du -sh /opt/tomcat/logs/*
...
4.5G    /opt/tomcat/logs/catalina.out
...

The log file catalina.out of Tomcat on CentOS has reached more than 4G

Solution:

logrotate

Create profile

vi /etc/logrotate.d/tomcat

To write a configuration file:

/opt/tomcat/logs/catalina.out {   
    copytruncate   
    daily   
    rotate 7   
    compress   
    missingok   
    size 5M  
}

Configuration Description:

/opt/Tomcat/logs/Catalina. Out : log path to archive

copyruncat : copy truncation mode

daily : trigger once a day

Rotate : up to 7 log files

compress : use compression

missingok : if the log file is missing, proceed to the next log file without issuing an error message

size : log files are rotated only when the log file size exceeds the byte size

In this way, logrotate automatically triggers log cutting and archiving once a day

Test logrotate rotation log

logrotate -v /etc/logrotate.conf
...
rotating pattern: /opt/tomcat/logs/catalina.out  5242880 bytes (7 rotations)
empty log files are rotated, old logs are removed
considering log /opt/tomcat/logs/catalina.out
  log needs rotating
rotating log /opt/tomcat/logs/catalina.out, log->rotateCount is 7
dateext suffix '-20180928'
glob pattern '-[0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9]'
glob finding old rotated logs failed
copying /opt/tomcat/logs/catalina.out to /opt/tomcat/logs/catalina.out-20180928
set default create context
truncating /opt/tomcat/logs/catalina.out
compressing log with: /bin/gzip
...

Then, under the logs folder of tomcat, check whether the Catalina. Out file has been rotated and backed up

[admin@Servicenumber logs]$ ls -lh
23M
...
-rw-r-----. 1 tomcat tomcat 249K 9月  28 09:30 catalina.out
-rw-r-----. 1 tomcat tomcat 566K 9月  28 09:27 catalina.out-20180928.gz
...

When you see the GZ file, it means that logrotate is OK

Log file of logrotate

/var/lib/logrotate.status 

Attention

When using logrotate, make sure that the Tomcat log output location is /var/log/Tomcat/Catalina. Out to take effect. Logrotate cannot be enabled if it is not the log output location of /var/log/ of the operating system