The second part is rotating the log. We can create a logrotate file like so
This logrotate file does the following:
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
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.
$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:
- Only rotates the file if it’s over 25M
- 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)
- Compresses the file
- adds the date timestamp to the compressed log name
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.