Search code examples
tomcattomcat9catalina.out

Is it safe to delete catalina.out if Tomcat is stopped?


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?


Solution

  • 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:

    cat > catalina.out
    # or
    truncate catalina.out
    

    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:

    • remove the ConsoleHandler from logging.properties (.handlers and handlers): the data logged to the ConsoleHandler is also logged to catalina.<date>.log,
    • make sure the logging system of your applications doesn't log to the standard output/standard error, but to a properly rotated file.