I only would like to keep the Access Logs of the last n days created by Tomcat Access Log Valve. http://tomcat.apache.org/tomcat-6.0-doc/config/valve.html#Access%20Log%20Valve
But there seems to be no configuration-Attribute to define how long to keep the log-files? I guess this is because "Access Log Valve" only creates log files and doesn't delete them, is that correct?
for tomcat 7 you can config tomcat/conf/logging.properties
e.g:
1catalina.org.apache.juli.FileHandler.maxDays = 90
https://tomcat.apache.org/tomcat-7.0-doc/logging.html
By default
rotatable
is true for Access Log, so you will be having a new file created every 24 hours.Tomcat itself does not do any housekeeping on the old files, the general principle on a Unix system is to have a cron job set up on the system to archive older files into a back up directory and/or delete them.
Incase of Apache Tomcat 7.0. You can use maxDays parameter to delete old log files. https://tomcat.apache.org/tomcat-7.0-doc/config/valve.html
You can try to create logrotate config:
"su tomcat tomcat" - i added for avoiding logrotate error on wrong permissions
For Windows, based on Erwan's answer in Tomcat localhost_access_log files cleanup, for the given folder and recursing into all subfolders:
To test, just use:
And when having multiple suffixes in the log folder, like both
.txt
and.log
, see using FORFILES in batch to delete tmp and bak files older than a week: