0

I have a Tomcat7 webserver running on CentOS Linux. Tomcat is configured by default to write all System.out to the /logs/catalina.out file. It does not rotate or trim this file, so it will eventually exceed the max file size and crash the web server.

Given this does not seem like a good idea... how to prevent this?

I found, catalina.out rolling with Tomcat 6.0

and I configured my logging.properties like it said, but this does not seem to work, maybe it prevents Tomcat from logging to catalina.out, but still every other System.out write is going to the file.

The odd thing is I have two identical servers, configured in the exact same way, but one is writing to catalina.out, and the other is not??

Community
  • 1
  • 1
James
  • 17,965
  • 11
  • 91
  • 146

3 Answers3

0

Well this is what I came up with.

  • start tomcat
  • delete the catalina.out file

Now it will no longer write to the file. This seems to work. Simple, but a hack. Anyone got a better solutions?

James
  • 17,965
  • 11
  • 91
  • 146
0

If the catalina.out is deleted after tomcat is stopped, it will create a new catalina.out once tomcat starts again and it is totally safe. In case if you remove the catalina.out while tomcat is running, it will keep on logging to catalina.out which is removed already (reference of the file is hold by the tomcat) hence the space will not be released. So you will need to restart the tomcat sever to release the space. It is not recommended.

But in critical applications running on tomcat used by public, this won`t be a good solution since there will be a downtime.

Therefore, you can clear the log of catalina.out file without stopping tomcat with the command below.

sudo cat /dev/null > /opt/tomcat/apache-tomcat-9.0.37/logs/catalina.out  

To keep catalina.out smaller and get rid of older logs, either one of the following ways can be used:

  1. You could use the above Linux command and add it to a CronScheduler to run daily/ weekly/ monthly or yearly as preferred.

  2. Use logrotate tool in Linux. It is a log managing command-line tool in 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.

Du-Lacoste
  • 11,530
  • 2
  • 71
  • 51
-1

Review the content of all aplications deployed in your webapps folder. the one witch is writing in your catalina.out may have in web-inf/lib/classes a logging.properties file.

is there any handler inside that file configured to write to ConsoleHandler.

Try this.

In this point review the topic Considerations for production usage.

Saeed
  • 3,294
  • 5
  • 35
  • 52
JaviC
  • 1