If you are using Gnu/Linux or Mac OS X, you can just do:
echo "" > catalina.out
or even shorter:
> catalina.out
Question
I couldn't restart Tomcat webserver. But catalina.out get very big. I have tried delete on test server and created new empty. But Tomcat doesn't write anymore in new catalina.out. How correct delete/create empty new one ?
Solution
If you are using Gnu/Linux or Mac OS X, you can just do:
echo "" > catalina.out
or even shorter:
> catalina.out
OTHER TIPS
for me
echo "" > catalina.out
or
sudo echo "" > catalina.out
didn't work, as the file was created with root/other user privilege
sudo truncate -s 0 catalina.out
worked for me. here -s is for size and I am setting the file size to 0
In base Tomcat installs, catalina.out
is usually the result of stdout/stderr redirections via the Tomcat launcher script.
If you run Tomcat on a Unix system, and if you delete the file while Tomcat is running, the problem is that the process will still have a descriptor open to that file and continue to write on it. The solution is therefore to use a program dedicated to handling such cases. For instance, logrotate (which is standard in pretty much all Linux distributions).
When tomcat
server is used, it is pretty normal that the disk usage increases as logs accumulate in the catalina.out
file.
If the catalina.out
is deleted after tomcat
is stopped, it will create a new catalina.out
once tomcat
starts and writes to it. But in your case, since catalina.out
was deleted while tomcat
was running it is holding up the file reference and writing to the deleted file. You can get rid of this by restarting the tomcat
server.
Actually 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 backup older logs, either one of the following ways can be used:
You could use the above Linux
command and add it to a CronScheduler
to run daily/ weekly/ monthly or yearly as preferred.
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.