0

I need to clear all my logs when I undeploy an application in Tomcat. I don't want to clear the logs every time manually.

How can I achieve this?

Paul Bellora
  • 54,340
  • 18
  • 130
  • 181
muthukumar
  • 2,233
  • 3
  • 23
  • 30

1 Answers1

3

I don't think you will find any solution inside Tomcat.

You can either :

  • Implement a shutdown hook (see this article) to delete the log file when context destroyed
  • Write a shell script that delete the war file/folder (in order to undeploy) and the application log.

My preference would be the shell script, since it is really easy to write, to call and, if you need it, you can undeploy without clearing the log...

Community
  • 1
  • 1
tibo
  • 5,326
  • 4
  • 37
  • 53
  • +1 Note that a shutdown hook executes when the JVM is shutdown, not necessarily when an application is undeployed (see [this post](http://stackoverflow.com/q/6950396/697449), where I learned that). The context destroyed approach is preferable. – Paul Bellora Aug 17 '12 at 04:09
  • +1 I didn't want to refer to "addShutdownHook()" when using "shutdown hook". My bad! – tibo Aug 17 '12 at 04:16