Merge pull request #16080 from nhomble

* pr/16080:
  Polish "Complete Jetty Access Log configuration properties support"
  Complete Jetty Access Log configuration properties support
pull/15988/head
Stephane Nicoll 6 years ago
commit 1a05851fe2

@ -948,6 +948,17 @@ public class ServerProperties {
*/
private boolean logLatency;
/**
* Whether to log IP address from the "X-Forwarded-For" header rather than the
* one from the connection.
*/
private boolean preferProxiedForAddress = false;
/**
* Request paths that should not be logged.
*/
private List<String> ignorePaths;
public boolean isEnabled() {
return this.enabled;
}
@ -1044,6 +1055,22 @@ public class ServerProperties {
this.logLatency = logLatency;
}
public boolean isPreferProxiedForAddress() {
return this.preferProxiedForAddress;
}
public void setPreferProxiedForAddress(boolean preferProxiedForAddress) {
this.preferProxiedForAddress = preferProxiedForAddress;
}
public List<String> getIgnorePaths() {
return this.ignorePaths;
}
public void setIgnorePaths(List<String> ignorePaths) {
this.ignorePaths = ignorePaths;
}
}
}

@ -37,6 +37,7 @@ import org.springframework.boot.web.embedded.jetty.JettyServerCustomizer;
import org.springframework.boot.web.server.WebServerFactoryCustomizer;
import org.springframework.core.Ordered;
import org.springframework.core.env.Environment;
import org.springframework.util.CollectionUtils;
import org.springframework.util.unit.DataSize;
/**
@ -170,6 +171,10 @@ public class JettyWebServerFactoryCustomizer implements
log.setLogCookies(properties.isLogCookies());
log.setLogServer(properties.isLogServer());
log.setLogLatency(properties.isLogLatency());
log.setPreferProxiedForAddress(properties.isPreferProxiedForAddress());
if (!CollectionUtils.isEmpty(properties.getIgnorePaths())) {
log.setIgnorePaths(properties.getIgnorePaths().toArray(new String[0]));
}
server.setRequestLog(log);
});
}

@ -231,6 +231,8 @@ public class ServerPropertiesTests {
map.put("server.jetty.accesslog.file-date-format", "yyyymmdd");
map.put("server.jetty.accesslog.retention-period", "4");
map.put("server.jetty.accesslog.append", "true");
map.put("server.jetty.accesslog.prefer-proxied-for-address", "true");
map.put("server.jetty.accesslog.ignore-paths", "/a/path,/b/path");
bind(map);
ServerProperties.Jetty jetty = this.properties.getJetty();
assertThat(jetty.getAccesslog().isEnabled()).isTrue();
@ -238,6 +240,9 @@ public class ServerPropertiesTests {
assertThat(jetty.getAccesslog().getFileDateFormat()).isEqualTo("yyyymmdd");
assertThat(jetty.getAccesslog().getRetentionPeriod()).isEqualTo(4);
assertThat(jetty.getAccesslog().isAppend()).isTrue();
assertThat(jetty.getAccesslog().isPreferProxiedForAddress()).isTrue();
assertThat(jetty.getAccesslog().getIgnorePaths()).containsExactly("/a/path",
"/b/path");
}
@Test

@ -1,5 +1,5 @@
/*
* Copyright 2012-2018 the original author or authors.
* Copyright 2012-2019 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@ -101,7 +101,9 @@ public class JettyWebServerFactoryCustomizerTests {
"server.jetty.accesslog.time-zone=" + timezone,
"server.jetty.accesslog.log-cookies=true",
"server.jetty.accesslog.log-server=true",
"server.jetty.accesslog.log-latency=true");
"server.jetty.accesslog.log-latency=true",
"server.jetty.accesslog.prefer-proxied-for-address=true",
"server.jetty.accesslog.ignore-paths=/a/path,/b/path");
JettyWebServer server = customizeAndGetServer();
NCSARequestLog requestLog = getNCSARequestLog(server);
assertThat(requestLog.getFilename()).isEqualTo(logFile.getAbsolutePath());
@ -115,6 +117,9 @@ public class JettyWebServerFactoryCustomizerTests {
assertThat(requestLog.getLogCookies()).isTrue();
assertThat(requestLog.getLogServer()).isTrue();
assertThat(requestLog.getLogLatency()).isTrue();
assertThat(requestLog.getPreferProxiedForAddress()).isTrue();
assertThat(requestLog.getIgnorePaths().length).isEqualTo(2);
assertThat(requestLog.getIgnorePaths()).containsExactly("/a/path", "/b/path");
}
@Test
@ -128,6 +133,8 @@ public class JettyWebServerFactoryCustomizerTests {
assertThat(requestLog.getLogCookies()).isFalse();
assertThat(requestLog.getLogServer()).isFalse();
assertThat(requestLog.getLogLatency()).isFalse();
assertThat(requestLog.getPreferProxiedForAddress()).isFalse();
assertThat(requestLog.getIgnorePaths()).isNull();
}
private NCSARequestLog getNCSARequestLog(JettyWebServer server) {

Loading…
Cancel
Save