Polish contribution

Also add rotate attribute to Undertow

Closes gh-7225
pull/7216/merge
Stephane Nicoll 8 years ago
parent 1d95219c4b
commit ed7de8eb60

@ -956,7 +956,7 @@ public class ServerProperties
valve.setPrefix(this.accesslog.getPrefix());
valve.setSuffix(this.accesslog.getSuffix());
valve.setRenameOnRotate(this.accesslog.isRenameOnRotate());
valve.setRotatable(this.accesslog.isRotatable());
valve.setRotatable(this.accesslog.isRotate());
factory.addEngineValves(valve);
}
@ -1002,14 +1002,14 @@ public class ServerProperties
private String suffix = ".log";
/**
* Defer inclusion of the date stamp in the file name until rotate time.
* Enable access log rotation.
*/
private boolean renameOnRotate;
private boolean rotate = true;
/**
* Enable access log rotation.
* Defer inclusion of the date stamp in the file name until rotate time.
*/
private boolean rotatable = true;
private boolean renameOnRotate;
public boolean isEnabled() {
return this.enabled;
@ -1051,6 +1051,14 @@ public class ServerProperties
this.suffix = suffix;
}
public boolean isRotate() {
return this.rotate;
}
public void setRotate(boolean rotate) {
this.rotate = rotate;
}
public boolean isRenameOnRotate() {
return this.renameOnRotate;
}
@ -1059,13 +1067,6 @@ public class ServerProperties
this.renameOnRotate = renameOnRotate;
}
public boolean isRotatable() {
return this.rotatable;
}
public void setRotatable(boolean rotatable) {
this.rotatable = rotatable;
}
}
}
@ -1309,21 +1310,14 @@ public class ServerProperties
if (this.directBuffers != null) {
factory.setDirectBuffers(this.directBuffers);
}
if (this.accesslog.dir != null) {
factory.setAccessLogDirectory(this.accesslog.dir);
}
if (this.accesslog.pattern != null) {
factory.setAccessLogPattern(this.accesslog.pattern);
}
if (this.accesslog.prefix != null) {
factory.setAccessLogPrefix(this.accesslog.prefix);
}
if (this.accesslog.suffix != null) {
factory.setAccessLogSuffix(this.accesslog.suffix);
}
if (this.accesslog.enabled != null) {
factory.setAccessLogEnabled(this.accesslog.enabled);
}
factory.setAccessLogDirectory(this.accesslog.dir);
factory.setAccessLogPattern(this.accesslog.pattern);
factory.setAccessLogPrefix(this.accesslog.prefix);
factory.setAccessLogSuffix(this.accesslog.suffix);
factory.setAccessLogRotate(this.accesslog.rotate);
factory.setUseForwardHeaders(serverProperties.getOrDeduceUseForwardHeaders());
if (serverProperties.getMaxHttpHeaderSize() > 0) {
customizeMaxHttpHeaderSize(factory,
@ -1406,6 +1400,11 @@ public class ServerProperties
*/
private File dir = new File("logs");
/**
* Enable access log rotation.
*/
private boolean rotate = true;
public Boolean getEnabled() {
return this.enabled;
}
@ -1446,6 +1445,13 @@ public class ServerProperties
this.dir = dir;
}
public boolean isRotate() {
return this.rotate;
}
public void setRotate(boolean rotate) {
this.rotate = rotate;
}
}
}

@ -137,8 +137,8 @@ public class ServerPropertiesTests {
Map<String, String> map = new HashMap<String, String>();
map.put("server.tomcat.accesslog.pattern", "%h %t '%r' %s %b");
map.put("server.tomcat.accesslog.prefix", "foo");
map.put("server.tomcat.accesslog.rotate", "false");
map.put("server.tomcat.accesslog.rename-on-rotate", "true");
map.put("server.tomcat.accesslog.rotatable", "false");
map.put("server.tomcat.accesslog.suffix", "-bar.log");
map.put("server.tomcat.protocol_header", "X-Forwarded-Protocol");
map.put("server.tomcat.remote_ip_header", "Remote-Ip");
@ -148,8 +148,8 @@ public class ServerPropertiesTests {
ServerProperties.Tomcat tomcat = this.properties.getTomcat();
assertThat(tomcat.getAccesslog().getPattern()).isEqualTo("%h %t '%r' %s %b");
assertThat(tomcat.getAccesslog().getPrefix()).isEqualTo("foo");
assertThat(tomcat.getAccesslog().isRotate()).isFalse();
assertThat(tomcat.getAccesslog().isRenameOnRotate()).isTrue();
assertThat(tomcat.getAccesslog().isRotatable()).isFalse();
assertThat(tomcat.getAccesslog().getSuffix()).isEqualTo("-bar.log");
assertThat(tomcat.getRemoteIpHeader()).isEqualTo("Remote-Ip");
assertThat(tomcat.getProtocolHeader()).isEqualTo("X-Forwarded-Protocol");
@ -466,6 +466,28 @@ public class ServerPropertiesTests {
.getProtocolHandler()).getMaxConnections()).isEqualTo(5);
}
@Test
public void customizeUndertowAccessLog() {
Map<String, String> map = new HashMap<String, String>();
map.put("server.undertow.accesslog.enabled", "true");
map.put("server.undertow.accesslog.pattern", "foo");
map.put("server.undertow.accesslog.prefix", "test_log");
map.put("server.undertow.accesslog.suffix", "txt");
map.put("server.undertow.accesslog.dir", "test-logs");
map.put("server.undertow.accesslog.rotate", "false");
bindProperties(map);
UndertowEmbeddedServletContainerFactory container = spy(
new UndertowEmbeddedServletContainerFactory());
this.properties.getUndertow().customizeUndertow(this.properties, container);
verify(container).setAccessLogEnabled(true);
verify(container).setAccessLogPattern("foo");
verify(container).setAccessLogPrefix("test_log");
verify(container).setAccessLogSuffix("txt");
verify(container).setAccessLogDirectory(new File("test-logs"));
verify(container).setAccessLogRotate(false);
}
@Test
public void defaultUseForwardHeadersUndertow() throws Exception {
UndertowEmbeddedServletContainerFactory container = spy(

@ -199,6 +199,7 @@ content into your application; rather pick only the properties that you need.
server.tomcat.accesslog.pattern=common # Format pattern for access logs.
server.tomcat.accesslog.prefix=access_log # Log file name prefix.
server.tomcat.accesslog.rename-on-rotate=false # Defer inclusion of the date stamp in the file name until rotate time.
server.tomcat.accesslog.rotate=true # Enable access log rotation.
server.tomcat.accesslog.suffix=.log # Log file name suffix.
server.tomcat.background-processor-delay=30 # Delay in seconds between the invocation of backgroundProcess methods.
server.tomcat.basedir= # Tomcat base directory. If not specified a temporary directory will be used.
@ -222,6 +223,7 @@ content into your application; rather pick only the properties that you need.
server.undertow.accesslog.enabled=false # Enable access log.
server.undertow.accesslog.pattern=common # Format pattern for access logs.
server.undertow.accesslog.prefix=access_log. # Log file name prefix.
server.undertow.accesslog.rotate=true # Enable access log rotation.
server.undertow.accesslog.suffix=log # Log file name suffix.
server.undertow.buffer-size= # Size of each buffer in bytes.
server.undertow.buffers-per-region= # Number of buffer per region.

@ -126,6 +126,8 @@ public class UndertowEmbeddedServletContainerFactory
private boolean accessLogEnabled = false;
private boolean accessLogRotate = true;
private boolean useForwardHeaders;
/**
@ -411,7 +413,7 @@ public class UndertowEmbeddedServletContainerFactory
: "access_log.");
AccessLogReceiver accessLogReceiver = new DefaultAccessLogReceiver(
createWorker(), this.accessLogDirectory, prefix,
this.accessLogSuffix);
this.accessLogSuffix, this.accessLogRotate);
String formatString = (this.accessLogPattern != null) ? this.accessLogPattern
: "common";
return new AccessLogHandler(handler, accessLogReceiver, formatString,
@ -584,6 +586,10 @@ public class UndertowEmbeddedServletContainerFactory
return this.accessLogEnabled;
}
public void setAccessLogRotate(boolean accessLogRotate) {
this.accessLogRotate = accessLogRotate;
}
protected final boolean isUseForwardHeaders() {
return this.useForwardHeaders;
}

Loading…
Cancel
Save