Make Tomcat Access Log's buffering configurable via the environment
Closes gh-7456
This commit is contained in:
@@ -1005,6 +1005,7 @@ public class ServerProperties
|
||||
valve.setRequestAttributesEnabled(
|
||||
this.accesslog.isRequestAttributesEnabled());
|
||||
valve.setRotatable(this.accesslog.isRotate());
|
||||
valve.setBuffered(this.accesslog.isBuffered());
|
||||
factory.addEngineValves(valve);
|
||||
}
|
||||
|
||||
@@ -1065,6 +1066,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;
|
||||
}
|
||||
@@ -1129,6 +1135,14 @@ public class ServerProperties
|
||||
this.requestAttributesEnabled = requestAttributesEnabled;
|
||||
}
|
||||
|
||||
public boolean isBuffered() {
|
||||
return this.buffered;
|
||||
}
|
||||
|
||||
public void setBuffered(boolean buffered) {
|
||||
this.buffered = buffered;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -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<String, String> map = new HashMap<String, String>();
|
||||
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<String, String> map = new HashMap<String, String>();
|
||||
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<String, String> map = new HashMap<String, String>();
|
||||
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<String, String> map = new HashMap<String, String>();
|
||||
|
||||
Reference in New Issue
Block a user