I haven't found a solution to purge old tomcat or jboss logs or any other timestamped logs: catalog.log./server.log.. Basically these logs are rotated by jboss as: server.log, server.log.20131201, server.log.20131203 and so on.
Is there a way I can use logrotate to delete logs older than n days? I don't want to use find inside postrotate or tweak jboss/tomcat logging properties. I just want to know if logrotate can actually achieve this on it's own. I know it's not very productive but I am stuck with a problem where I need answer for this.
If you don't want to use
find
insidepostrotate
, no, you can't.logrotate
treats every instance ofserver.log
rotated by Tomcat/JBoss as a different file, and since they are unique,logrotate
will rotate them only once.maxage
- the directive that removes rotated logs older thann
days - is only checked if the logfile is to be rotated, so thatmaxage
is only executed once and can't keep track of the file's age.However, if you change your mind about using
find
,logrotate
can help you simplify the management of log files created by Tomcat and JBoss. I use it to compress and remove old files with a configuration file like this:where:
rotate 1
andcompress
rename and compress, say,server.log.20131201
toserver.log.20131201.0.bz2
. The0
between the timestamp and the.bz2
extension comes fromstart 0
.size 0
makes sure that files are always renamed and compressed.lastaction
block removes rotated files older than 180 days.