Tomcat HTTP Access log has a delay in writing to the file

风格不统一 提交于 2019-12-06 11:33:57

I found the answer for this. You can improve the delay by disabling buffering. Flag "buffered" determine if logging will be buffered. If set to false, then access logging will be written after each request. Default value: true. Therefore, adding BufferedLogs="false" will reduce the delay in writing to the log file. Another property is backgroundProcessorDelay. If not specified, the default value for this attribute is 10, which represent a 10 seconds delay. Therefore, by setting it to a lower value you can improve the delay writing http-access logs to a file.

the main reason is tomcat buffered the log message . we can disabled the buffer by changing the logger's default behaviors . we can find in $TOMCAT_HOME/conf/server.xml
tomcat version : tomcat-7.0.61

 <Valve className="org.apache.catalina.valves.AccessLogValve" directory="logs" buffered="false"  pattern="%h %l %u %t &quot;%r&quot; %s %b" prefix="localhost_access_log." suffix=".txt"/>

by setting buffered attribute to false , we can get the access information immediately. doc of AccessLogValve

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!