Complete Jetty Access Log configuration properties support

See gh-16080
pull/15988/head
nicolas 6 years ago committed by Stephane Nicoll
parent a0b65a00b9
commit 55a5a26b95

@ -948,6 +948,16 @@ public class ServerProperties {
*/
private boolean logLatency;
/**
* Set request paths that will not be logged.
*/
private List<String> ignorePaths;
/**
* true - IP address from header will be logged, false - IP address from the connection will be logged
*/
private boolean preferProxiedForAddress = false;
public boolean isEnabled() {
return this.enabled;
}
@ -1044,6 +1054,21 @@ public class ServerProperties {
this.logLatency = logLatency;
}
public List<String> getIgnorePaths() {
return ignorePaths;
}
public void setIgnorePaths(List<String> ignorePaths) {
this.ignorePaths = ignorePaths;
}
public boolean getPreferProxiedForAddress(){
return preferProxiedForAddress;
}
public void setPreferProxiedForAddress(boolean preferProxiedForAddress){
this.preferProxiedForAddress = preferProxiedForAddress;
}
}
}

@ -167,9 +167,13 @@ public class JettyWebServerFactoryCustomizer implements
if (properties.getTimeZone() != null) {
log.setLogTimeZone(properties.getTimeZone().getID());
}
if (properties.getIgnorePaths() != null) {
log.setIgnorePaths(properties.getIgnorePaths().toArray(new String[0]));
}
log.setLogCookies(properties.isLogCookies());
log.setLogServer(properties.isLogServer());
log.setLogLatency(properties.isLogLatency());
log.setPreferProxiedForAddress(properties.getPreferProxiedForAddress());
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.ignore-paths[0]", "/a/path");
map.put("server.jetty.accesslog.ignore-paths[1]", "/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().getIgnorePaths().size()).isEqualTo(2);
assertThat(jetty.getAccesslog().getIgnorePaths().get(0)).isEqualTo("/a/path");
assertThat(jetty.getAccesslog().getIgnorePaths().get(1)).isEqualTo("/b/path");
}
@Test

@ -16,13 +16,16 @@
package org.springframework.boot.autoconfigure.web.embedded;
import static org.assertj.core.api.Assertions.assertThat;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.verify;
import java.io.File;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import java.util.Locale;
import java.util.TimeZone;
import org.eclipse.jetty.server.Connector;
import org.eclipse.jetty.server.HttpConfiguration;
import org.eclipse.jetty.server.HttpConfiguration.ConnectionFactory;
@ -30,7 +33,6 @@ import org.eclipse.jetty.server.NCSARequestLog;
import org.eclipse.jetty.server.RequestLog;
import org.junit.Before;
import org.junit.Test;
import org.springframework.boot.autoconfigure.web.ServerProperties;
import org.springframework.boot.context.properties.bind.Bindable;
import org.springframework.boot.context.properties.bind.Binder;
@ -41,10 +43,6 @@ import org.springframework.boot.web.embedded.jetty.JettyWebServer;
import org.springframework.mock.env.MockEnvironment;
import org.springframework.test.context.support.TestPropertySourceUtils;
import static org.assertj.core.api.Assertions.assertThat;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.verify;
/**
* Tests for {@link JettyWebServerFactoryCustomizer}.
*
@ -101,7 +99,10 @@ 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[0]=/a/path",
"server.jetty.accesslog.ignore-paths[1]=/b/path");
JettyWebServer server = customizeAndGetServer();
NCSARequestLog requestLog = getNCSARequestLog(server);
assertThat(requestLog.getFilename()).isEqualTo(logFile.getAbsolutePath());
@ -115,6 +116,10 @@ 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()[0]).isEqualTo("/a/path");
assertThat(requestLog.getIgnorePaths()[1]).isEqualTo("/b/path");
}
@Test
@ -128,6 +133,8 @@ public class JettyWebServerFactoryCustomizerTests {
assertThat(requestLog.getLogCookies()).isFalse();
assertThat(requestLog.getLogServer()).isFalse();
assertThat(requestLog.getLogLatency()).isFalse();
assertThat(requestLog.getIgnorePaths().length).isZero();
assertThat(requestLog.getPreferProxiedForAddress()).isFalse();
}
private NCSARequestLog getNCSARequestLog(JettyWebServer server) {

Loading…
Cancel
Save