How to delete Tomcat Access Log after n days?

后端 未结 6 1720
伪装坚强ぢ
伪装坚强ぢ 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:37

    For Tomcat 7 you can config tomcat/conf/logging.properties. Example:

    1catalina.org.apache.juli.FileHandler.maxDays = 90
    

    Note: that 1 is not a typo.

    https://tomcat.apache.org/tomcat-7.0-doc/logging.html

    0 讨论(0)
  • 2021-01-03 20:38

    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

    0 讨论(0)
  • 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"
    
    0 讨论(0)
  • 2021-01-03 20:46

    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.

    0 讨论(0)
  • 2021-01-03 20:46

    You can try to create logrotate config:

    #cat /etc/logrotate.d/tomcat
    /var/log/tomcat/*.log {
            su tomcat tomcat
            copytruncate  
            daily  
            rotate 6  
            compress  
            missingok
    }
    

    "su tomcat tomcat" - i added for avoiding logrotate error on wrong permissions

    0 讨论(0)
  • 2021-01-03 20:52

    run in terminal:

    locate RELEASE-NOTES | egrep 'tomcat|apache' | xargs grep "Apache Tomcat Version"
    
    0 讨论(0)
提交回复
热议问题