Log file rotation for Linux

Andrew Foster shared this idea 6 years ago
Idea Logged

Would be good for the log files to auto-rotate .


The main culprit is catalina.out, which continually grows until I just blank it out. Before I started running "echo > /.../catalina.out" via cron it was about 750mb-1gb.


Other issues are with the catalina.[date].log, host-manager.[date].log, localhost.[date].log, & localhost_access_log.[date].log (this one is a particularly large group of .5-2mb files that are generated every day and don't seem to rotate at all).

Replies (4)

photo
1

Hey Andrew,


After failing to get this configured using some external articles, I've raised an enhancement to be reviewed by the devs. From what I can find, this will all be controlled via Tomcat, but maybe can ship with some pre-built scripts which can be copied to the relevant system folders to run.

I'll let you know once I hear more on this.

Thanks,David

photo
1

Hi Andrew,

I know i's been a good few years (4 years) since this was logged, however progress has been made albeit late... With this I would like to give some feedback on this;

From what we can see It looks like Tomcat can rotate its own logs. There is a lot of documentation here albeit, it doesn't seem to mention rotation.

There is an example logging.properties file here, that has rotation enabled. Which should help with the issue in question.

With this there is also additional options for this... this is more of an advanced configuration for Tomcat that allows it to use log4j2 itself. This can be found here.

What next?

From the above information this then allows more ways or users to address this themselves. (I'm hoping this helps)

Let me know your thoughts on this.

Regards,

Mark

photo
1

Posting here for posterity, if anyone will stumble across this issue, a more on point solution


1. You need to create a custom configuration file (Yellowfin_Catalina) for Catalina.out under etc/logrotate.d as follows


<<path to the file>>/appserver/logs/catalina.out {
    copytruncate
    daily
    rotate 10
    size 3G
    compress
    missingok
 }


a)daily means that the tool will attempt to rotate the logs on a daily basis. Other possible values are weekly and monthly.

rotate 10 indicates that only 10 rotated logs should be kept. Thus, the oldest file will be removed on the 11th subsequent run.

b)size=100M sets the minimum size for the rotation to take place to 100M. In other words, each log will not be rotated until it reaches 100MB.

c)compress are used to tell that all rotated logs, with the exception of the most recent one, should be compressed.

d)Copytruncate indicates that log file will copied to rotated log and main log will be truncated

e)Missingok tells logrotate to skip rotating and not give an error if the log file isn’t there


Last step is to schedule this in crontab and some example is shown below

0 * * * * /usr/sbin/logrotate /etc/logrotate.d/Yellowfin_Catalina


That will take care of the log rotation. However that is goign to hide any abnormality because it will work just fine so in order to capture that, we also created a script to alert us when more than X amount of files are created,basically to alert when catalina files are growing uncontrollably

#----------------------------------------------------------#
# INITIALIZE ALL INPUT PARAMETERS                          #
#----------------------------------------------------------#
recipients=<<recipient>>
drive=<<path to the logs folder>>
server=`hostname`
#MailServer=<<insert mail server>>
#current_timestamp=`(date +"%F_%T")`
#previous_timestamp=`date +"%F_%T" --date="30 min ago"`

cd $drive

current_timestamp=`date +"%H:%M"`
previous_timestamp=`date +"%H:%M" -d "30 mins ago"`
file_count=`find $drive/catalina.out* -type f -newermt "$previous_timestamp" | wc -l`
#file_count=`find $drive/catalina.out* | wc -l`
#file_list=`find $drive/catalina_out* -mmin -30`
file_list=`find catalina.out* -mmin -30`
#echo $file_list

if [ ${file_count} -gt 2 ]; then 
 echo "More than two Yellowfin backup files($file_count files) created in past 30 min.

Server/host_name: $server 

File location: $drive 

Files names:
$file_list

Please check and take necessary actions." |mailx -v -s "$server:Yellowfin  alert for `date`" $recipients
else
 echo "Whatever you want"
exit
fi


Hope this helps a bit

photo
1

Hi Stefan,

Some brilliant feedback there to help others who are affected by this. We appreciate the community spirit by letting us and other members know of this.

Have a great week ahead.

Regards,

Mark

Leave a Comment
 
Attach a file