How to delete Tomcat Access Log after n days?

后端 未结 6 1759
伪装坚强ぢ
伪装坚强ぢ 2021-01-03 19:48

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%20Val

6条回答
  •  天命终不由人
    2021-01-03 20:40

    For Windows, based on Erwan's answer in Tomcat localhost_access_log files cleanup, for the given folder and recursing into all subfolders:

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

    To test, just use:

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

    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:

    for %%t in (.txt, .log) do forfiles /p "C:\path\to\httplogs\" /s /m *%%t /d -10 /c "cmd /c del @PATH"
    

提交回复
热议问题