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

拜拜、爱过 提交于 2019-12-08 02:08:08

问题


In tomcat http access log valve takes some time to write to file. Please note I have default configurations for org.apache.catalina.valves.AccessLogValve. Are there anyways to improve the latency? And what are the key reasons for this delay


回答1:


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.




回答2:


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



来源:https://stackoverflow.com/questions/31109090/tomcat-http-access-log-has-a-delay-in-writing-to-the-file

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