My catalina.out file has 37 GB which seems to prevent my app running correctly on a linux (Centos) server since the file takes up all my server space. I never thought that a log file can get this big. Would it be safe (I have no test server to try) to stop Tomcat (Tomcat9) and just delete catalina.out? Is a new catalina.out file created when I start Tomcat again?
Or would it be better to do
sudo echo > catalina.out
as described here. What actually does this command do?
I need to stop the Tomcat for an update of my app from time to time anyway and I don’t need to store the older log files. So what is the best way to keep catalina.out small?
2
Answers
You can safely truncate (i.e. replace the content with an empty string) the
catalina.out
file even if Tomcat is running, which can be done manifold:Deleting the file, while Tomcat is down also works, but on a running Tomcat it would have a big side effect: Tomcat will still be appending data to the deleted file and the space will not be released until Tomcat shuts down.
In order to keep
catalina.out
small you should:ConsoleHandler
fromlogging.properties
(.handlers
andhandlers
): the data logged to theConsoleHandler
is also logged tocatalina.<date>.log
,If the
catalina.out
is deleted aftertomcat
is stopped, it will create a newcatalina.out
oncetomcat
starts again and it is totally safe. In case if you remove thecatalina.out
whiletomcat
is running, it will keep on logging tocatalina.out
which is removed already (reference of the file is hold by thetomcat
) hence the space will not be released. So you will need to restart thetomcat
sever to release the space. It is not recommended.Delete/ Move
catalina.out
whentomcat
server is stopped will not have any problem at all.But in critical applications running on
tomcat
used by public, this won`t be a good solution since there will be a downtime.Actually you can clear the log of
catalina.out
file without stopping tomcat with the command below.To keep
catalina.out
smaller and get rid of older logs, either one of the following ways can be used:You could use the above
Linux
command and add it to aCronScheduler
to run daily/ weekly/ monthly or yearly as preferred.
Use
logrotate
tool inLinux
. It is a log managing command-line toolin Linux. This can rotate the log files under different conditions.
Particularly, we can rotate log files on a fixed duration or if the
file has grown to a certain size. You can click here for more
info on this.