Reputation: 3255
Is there any ways to Clear the catalin.out logs file....? in certain intervals.
if Increasing the logs file more than 5GB than server will be automatically shutdown.
Upvotes: 8
Views: 12546
Reputation: 12817
this could be used to 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 in size, 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.
Upvotes: 0
Reputation: 1577
truncate will keep file pointers intact and remove its content. Logging will continue working, disk space will be freed and you don't need to restart any process (tomcat).
its possible to implement log rotation that way it you copy the file to some backup location
truncate -s 0 catalina.out
Upvotes: 1
Reputation: 747
You should use log rotation and then log archiving.
log rotation will split the log with respect to size, date or time, so that the log will not grow in huge size. And the inactive log files can be zipped/compressed or moved to different path/filesystem.
Upvotes: 0
Reputation: 3255
I have developed .sh file to clear catalina.out file that i will put at location where my project is deployed in tomcat.Now i will execute that file from my java code at certain interval.
Following is the command in my .sh file
echo "" > path to catalina.out file
Upvotes: 3
Reputation: 26733
I suggest to use cronolog - it basically works as a proxy. You can pipe the log output via it, and configure the settings for cronolog how you want your log files to be rotated.
This has an advantage so you don't need to restart your Tomcat just for log cleanup/rotation.
Upvotes: 0
Reputation: 31928
If you are on linux and you want to clear the log now without restarting tomcat then you can do:
cat /dev/null > /path/to/logfile
Upvotes: 8
Reputation: 52665
One possibility is to use log4j instead of the default logging provided by tomcat. log4j provides a RollingFileAppender, which can do the above job.
Refer to this tomcat link for details.
Upvotes: 1