'Tomcat catalina.out is 40GB
I wonder why my spring project with tomcat server got catalina.out file with size 40GB. Any solutions, please.catalina.out reach 40 GB
Solution 1:[1]
if you are linux user to handle this from system is pretty easy you can configure logrotation with logrotate this is very easy
Step : 1 (Create Logrotate file)
root@c2dapp01-usea1e# vim /etc/logrotate.d/tomcat
Step : Add rotation instruction for linux log rotator
/opt/tomcat/latest/logs/catalina.out {
copytruncate
daily
rotate 7
compress
missingok
size 100M
}
Step : 3 Add cron job to run daily in crond.daily or create custom cron (This file is by default there if not then only create)
root@c2dapp01-usea1e:# vim /etc/cron.daily/logrotate
# Clean non existent log file entries from status file
cd /var/lib/logrotate
test -e status || touch status
head -1 status > status.clean
sed 's/"//g' status | while read logfile date
do
[ -e "$logfile" ] && echo "\"$logfile\" $date"
done >> status.clean
mv status.clean status
test -x /usr/sbin/logrotate || exit 0
/usr/sbin/logrotate /etc/logrotate.conf
This script can be run manually.
/usr/sbin/logrotate /etc/logrotate.conf
Solution 2:[2]
Most probably the huge size of logs is due to the DEBUG
mode setting of log4j
. Change this setting to WARN
and the size of logging will be reduced.
This is quite common to see catalina.out
file expanding.
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 aCronScheduler
to run daily/ weekly/ monthly or yearly as preferred.Use
logrotate
tool inLinux
. 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.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 | Mansur Ul Hasan |
Solution 2 | Du-Lacoste |