# Tomcat 6 HTTP log rolling and purging

We run our web app in an Apache Tomcat 6 container. Our code uses SLF4J and Logback and rolls/purges just fine. The Tomcat log (catalina, stdout, etc.) just get deleted on a Tomcat service restart.

The problem is we also are doing some HTTP logging. As far as anyone can tell it's coming from this line in the Tomcat server.xml file.

<Valve className="org.apache.catalina.valves.FastCommonAccessLogValve" directory="httplogs" pattern="combined" resolveHosts="false" prefix="" suffix=".log" rotatable="true" fileDateFormat="yyyy-MM-dd" />


This seems to rotate just fine, but never purges. Is there a way to have Tomcat purge this automatically or do I have to modify the restart script to clean the httplogs directory?

-

I would suggest cleaning up the log files using a cron job (UNIX) or scheduled task (Windows).

First determine how long you want to keep the logs for, 1 week, 1 month, 3 months? Then run a script every day or so that removes the old logs. On Unix to delete log files older than 90 days:

find /path/to/httplogs/ -name "*.log" -type f -mtime +90 -exec rm -f {} \;


On windows a similar command can be used (forfiles is only available on some editions)

forfiles /p "C:\path\to\httplogs\" /s /m *.log /d -90 /c "cmd /c del @PATH"


Read the online documentation for these commands and understand and test what they are doing before putting them in a production environment.

If there is a common prefix for these logs then you can add this to the search mask to be more specific in which files are removed. Alternatively I often gzip older files rather than deleting them in case they prove useful later on.

-