diff --git a/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/web/ServerProperties.java b/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/web/ServerProperties.java index db89aa46b2e..3a30986772e 100644 --- a/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/web/ServerProperties.java +++ b/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/web/ServerProperties.java @@ -986,6 +986,7 @@ public class ServerProperties valve.setRequestAttributesEnabled( this.accesslog.isRequestAttributesEnabled()); valve.setRotatable(this.accesslog.isRotate()); + valve.setBuffered(this.accesslog.isBuffered()); factory.addEngineValves(valve); } @@ -1046,6 +1047,11 @@ public class ServerProperties */ private boolean requestAttributesEnabled; + /** + * Buffer output such that it is only flushed periodically. + */ + private boolean buffered = true; + public boolean isEnabled() { return this.enabled; } @@ -1110,6 +1116,14 @@ public class ServerProperties this.requestAttributesEnabled = requestAttributesEnabled; } + public boolean isBuffered() { + return this.buffered; + } + + public void setBuffered(boolean buffered) { + this.buffered = buffered; + } + } } diff --git a/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/web/ServerPropertiesTests.java b/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/web/ServerPropertiesTests.java index 3c1a7ace6b7..d74bfc233eb 100644 --- a/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/web/ServerPropertiesTests.java +++ b/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/web/ServerPropertiesTests.java @@ -31,6 +31,7 @@ import javax.servlet.SessionTrackingMode; import org.apache.catalina.Context; import org.apache.catalina.Valve; +import org.apache.catalina.valves.AccessLogValve; import org.apache.catalina.valves.RemoteIpValve; import org.apache.coyote.AbstractProtocol; import org.junit.Before; @@ -140,6 +141,48 @@ public class ServerPropertiesTests { assertThat(this.properties.getServletPrefix()).isEqualTo("/foo"); } + @Test + public void tomcatAccessLogIsDisabledByDefault() { + TomcatEmbeddedServletContainerFactory tomcatContainer = new TomcatEmbeddedServletContainerFactory(); + this.properties.customize(tomcatContainer); + assertThat(tomcatContainer.getEngineValves()).isEmpty(); + } + + @Test + public void tomcatAccessLogCanBeEnabled() { + TomcatEmbeddedServletContainerFactory tomcatContainer = new TomcatEmbeddedServletContainerFactory(); + Map map = new HashMap(); + map.put("server.tomcat.accesslog.enabled", "true"); + bindProperties(map); + this.properties.customize(tomcatContainer); + assertThat(tomcatContainer.getEngineValves()).hasSize(1); + assertThat(tomcatContainer.getEngineValves()).first() + .isInstanceOf(AccessLogValve.class); + } + + @Test + public void tomcatAccessLogIsBufferedByDefault() { + TomcatEmbeddedServletContainerFactory tomcatContainer = new TomcatEmbeddedServletContainerFactory(); + Map map = new HashMap(); + map.put("server.tomcat.accesslog.enabled", "true"); + bindProperties(map); + this.properties.customize(tomcatContainer); + assertThat(((AccessLogValve) tomcatContainer.getEngineValves().iterator().next()) + .isBuffered()).isTrue(); + } + + @Test + public void tomcatAccessLogBufferingCanBeDisabled() { + TomcatEmbeddedServletContainerFactory tomcatContainer = new TomcatEmbeddedServletContainerFactory(); + Map map = new HashMap(); + map.put("server.tomcat.accesslog.enabled", "true"); + map.put("server.tomcat.accesslog.buffered", "false"); + bindProperties(map); + this.properties.customize(tomcatContainer); + assertThat(((AccessLogValve) tomcatContainer.getEngineValves().iterator().next()) + .isBuffered()).isFalse(); + } + @Test public void testTomcatBinding() throws Exception { Map map = new HashMap();