Step 2: Setting up logrotate

ARTIFACTORY: How to reduce the amount of tomcat logs in 7.x with logrotate

AuthorFullName__c
Nir Ovadia
articleNumber
000005360
ft:sourceType
Salesforce
FirstPublishedDate
2022-08-04T06:54:33Z
lastModifiedDate
2022-08-04
VersionNumber
4
The second part is rotating the log. We can create a logrotate file like so
$ARTIFACTORY_HOME/var/log/tomcat/tomcat*.log {
size 25M
rotate 10000000000000
copytruncate
compress
missingok
olddir ../archived
dateext
extension .log
dateformat -%Y-%m-%d-%s
}

This logrotate file does the following:
  1. Only rotates the file if it’s over 25M
  2. Copies the log file to the $ARTIFACTORY_HOME/var/log/archived folder to be rotated, and clears out the current log file (basically what we expect with a log rotation)
  3. Compresses the file
  4. adds the date timestamp to the compressed log name
so it essentially behaves the same way as the current default Artifactory log rotation. The only difference is the
rotate 10000000000000

line, which essentially is the limit of rotated files. If you set this to something like 3, it will only keep 3 tomcat archived logs in the archived folder. Any new ones will cause the oldest archived log to be deleted. Setting it to an obscenely high number causes it to basically be unlimited.

There are other things you can do with logrotate, such as prerotate and postrotate scripts. In this case, we’ll leave it at that. Then you can add the logrotate operation to a cron job, something like
0 0 0 ? * MON * root /usr/sbin/logrotate /path/to/custom-logrotate.conf

which will run this every Monday at 00:00. Since the file is usually pretty small, we don’t really need a frequent CRON to rotate it.

And that’s it, now you have a tomcat-catalina.log and a tomcat-localhost.log (or whatever names you decided to call them) that will rotate the same way the default Artifactory logs do (25MB, into the log/archived folder) instead of creating tiny daily logs.