5

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?

3 Answers 3

6

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.

1

When you take a look at the source code of the class, for example here at google's code search you can see, that there is no purging at all. If you have someone around who could code some lines Java, one could easily extend the class and add the needed function.

0

I'm pretty sure that that one needs to be purged on tomcat service restart along with the other logs you mentioned.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.