Tomcat localhost_access_log文件清理 [英] Tomcat localhost_access_log files cleanup
问题描述
我们在Tomcat 8上运行了Solr.在不同的环境中,由于localhost_access_log文件填满了服务器而导致了问题.这些文件是通过配置如下的server.xml中的访问阀日志创建的-
We have Solr running on Tomcat 8. We are having issues in our different environments with localhost_access_log files filling up the servers. These files are created by the Access Valve Log in server.xml configured like this -
<Valve className="org.apache.catalina.valves.AccessLogValve" directory="logs"
prefix="localhost_access_log"
suffix=".txt" pattern="%h %l %u %t "%r" %s %b" />
据我了解,Tomcat中没有使用OOTB方式清除旧日志文件的方法.如何清除旧的访问日志文件?
From what I've read, there is no OOTB way in Tomcat to clean up old log files. What can I implement to clean up the old access log files?
推荐答案
您可以进行日志轮换,然后选择要删除的日志文件
You can have a log rotation and then choose what logs files to delete
<Valve className="org.apache.catalina.valves.AccessLogValve" directory="logs" prefix="localhost_access_log" suffix=".txt" rotatable="true" renameOnRotate="true" pattern="%h %l %u %t "%r" %s %b" />
由于旋转默认设置为true,因此您应该已经拥有它.然后您可以例如删除5天以上的日志:
As rotation is set to true by default you should already have it. Then you can for exemple delete logs older than 5 days:
要删除10天以上的日志文件,可以使用以下命令.
To delete log files older than 10 days the following commands can be used.
Unix
find /path/to/httplogs/ -name "*.log" -type f -mtime +10 -exec rm -f {} \;
For Windows Server OS:
forfiles /p "C:\path\to\httplogs" /s /m *.log /d -10 /c "cmd /c del @PATH"
这篇关于Tomcat localhost_access_log文件清理的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!