Tomcat Log Rotating Policy

In Windows, the tomcat service creates the stdout and stderr files. These files can end up taking up a lot of space and create space issues. These files generation can be stopped by providing empty values to Redirect Stdout and Redirect Stderr in Tomcat Monitor. We can also modify the service.bat file in <TOMCAT_HOME>/bin so that the service does not create stdout/stderr files initially.The following parameters need to be changed. 

--StdOutput auto needs to be changed to --StdOutput ““ 

--StdError auto needs to be changed to --StdError "" 

To modify an existing Tomcat service, we can use the Tomcat Monitor application. 

In <TOMCAT_HOME>/bin folder, the following command needs to be entered in command prompt open the Tomcat monitor. 

tomcat9w.exe //ES//<service name> 

e.g. tomcat9w.exe //ES//Tomcat9 

Then in the logging section, empty the Redirect stdout and Redirect stderr values and apply the changes. 

In linux,catalina.out takes in the stdout and stderr logs. To rotate that we can use logrotate utility provided in linux.  

For more info: https://dzone.com/articles/how-rotate-tomcat-catalinaout  

For info about logrotate: https://linux.die.net/man/8/logrotate  

To debug logrotate: sudo /usr/sbin/logrotate -d /etc/logrotate.conf 

To force logrotate to run : sudo /usr/sbin/logrotate -f /etc/logrotate.conf 

An example of a tomcat file that needs to be place in /etc/logrotate.d  

/opt/apache-tomcat/logs/catalina.out       /* path of catalina.out in linux filesystem */ 

{  

copytruncate  

daily  

rotate 7  

compress  

missingok  

size 5k  

create 777 root root           /* create mode owner group for the rotated logfile /* 

su root root 

©2021 Cognizant, all rights reserved. US Patent 10,410,152