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
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 "%r" %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