spring-boot icon indicating copy to clipboard operation
spring-boot copied to clipboard

Access Log not flushed regularly

Open ukleeberger opened this issue 10 years ago • 6 comments

Hi,

since we are using Sring Boot 1.4.0.RELEASE (with embedded tomcat) the access log is not flushed regularly. Only on log rotation or after several hours the entries are written to the file. With version 1.3.7 the access log gets flushed in seconds to minutes. Is this the desired behavior or am i missing a setting?

ukleeberger avatar Aug 14 '16 11:08 ukleeberger

This appears to be an unwanted side-effect of moving the access log to the engine (#6311).

The access log has always been buffered. Previously, it was flushed every 30 seconds by the context's background processor thread. The engine has no such thread as its default backgroundProcessorDelay is -1.

You can work around the problem by adding the following bean to your application:

@Bean
public TomcatEmbeddedServletContainerFactory tomcatFactory() {
    return new TomcatEmbeddedServletContainerFactory() {

        @Override
        protected TomcatEmbeddedServletContainer getTomcatEmbeddedServletContainer(
                Tomcat tomcat) {
            tomcat.getEngine().setBackgroundProcessorDelay(30);
            return super.getTomcatEmbeddedServletContainer(tomcat);
        }
    };
}

wilkinsona avatar Aug 15 '16 09:08 wilkinsona

The configuration of the context's background processor delay was added to support the access log valve. Furthermore, a vanilla Tomcat 8.5.4 install has a single background process thread and its associated with the engine rather than the context. This works because the call to perform background processing is cascaded down to all of the descendants of the element that has the processor configured.

In short, we should move the background process up to the engine.

wilkinsona avatar Aug 15 '16 09:08 wilkinsona

I think the cleanest way to implement this would be by introducing a new TomcatEngineCustomizer interface. However, that would make the new-in-1.4 TomcatEmbeddedServletContainerFactory.setEngineValues() and TomcatEmbeddedServletContainerFactory.getEngineValves methods obsolete as the engine valve configuration could then be implemented as engine customizers instead.

wilkinsona avatar Aug 15 '16 09:08 wilkinsona

I have just spent a few hours on this problem. Figured out why was happening then when I came here to report found this already reported in this thread. I believe this to be a important issue to be fixed soon. Will use the workaround for now. Looking forward for the 1.4.1 release with a fix for this =]

michelzanini avatar Aug 16 '16 10:08 michelzanini

Hi, I think this issue is still in 1.4.2 release. I have 6 spring-boot micro-service apps which are upgraded from 1.2.5 to 1.4.2 recently. They have same configuration for access.log. However, after everyday log rolling, it takes unexpectable delay to create new access.log file, maybe after 5 requests or 100 requests , or in one of them even no access.log created for whole day.

mingzhi5626 avatar Nov 21 '16 18:11 mingzhi5626

@mingzhi5626 If the problem only occurs after rotation then it's a different problem to the one covered by this issue. Either way, this issue is closed so, if you'd like us to investigate your problem please open a new issue with a sample and some details on how to use it to recreate the problem.

wilkinsona avatar Nov 21 '16 19:11 wilkinsona