use of org.eclipse.jetty.server.RequestLogWriter in project spring-boot by spring-projects.
the class JettyWebServerFactoryCustomizer method customizeAccessLog.
private void customizeAccessLog(ConfigurableJettyWebServerFactory factory, ServerProperties.Jetty.Accesslog properties) {
factory.addServerCustomizers((server) -> {
RequestLogWriter logWriter = new RequestLogWriter();
String format = getLogFormat(properties);
CustomRequestLog log = new CustomRequestLog(logWriter, format);
if (!CollectionUtils.isEmpty(properties.getIgnorePaths())) {
log.setIgnorePaths(properties.getIgnorePaths().toArray(new String[0]));
}
if (properties.getFilename() != null) {
logWriter.setFilename(properties.getFilename());
}
if (properties.getFileDateFormat() != null) {
logWriter.setFilenameDateFormat(properties.getFileDateFormat());
}
logWriter.setRetainDays(properties.getRetentionPeriod());
logWriter.setAppend(properties.isAppend());
server.setRequestLog(log);
});
}
use of org.eclipse.jetty.server.RequestLogWriter in project spring-boot by spring-projects.
the class JettyWebServerFactoryCustomizerTests method accessLogCanBeCustomized.
@Test
void accessLogCanBeCustomized() throws IOException {
File logFile = File.createTempFile("jetty_log", ".log");
bind("server.jetty.accesslog.enabled=true", "server.jetty.accesslog.format=extended_ncsa", "server.jetty.accesslog.filename=" + logFile.getAbsolutePath().replace("\\", "\\\\"), "server.jetty.accesslog.file-date-format=yyyy-MM-dd", "server.jetty.accesslog.retention-period=42", "server.jetty.accesslog.append=true", "server.jetty.accesslog.ignore-paths=/a/path,/b/path");
JettyWebServer server = customizeAndGetServer();
CustomRequestLog requestLog = getRequestLog(server);
assertThat(requestLog.getFormatString()).isEqualTo(CustomRequestLog.EXTENDED_NCSA_FORMAT);
assertThat(requestLog.getIgnorePaths()).hasSize(2);
assertThat(requestLog.getIgnorePaths()).containsExactly("/a/path", "/b/path");
RequestLogWriter logWriter = getLogWriter(requestLog);
assertThat(logWriter.getFileName()).isEqualTo(logFile.getAbsolutePath());
assertThat(logWriter.getFilenameDateFormat()).isEqualTo("yyyy-MM-dd");
assertThat(logWriter.getRetainDays()).isEqualTo(42);
assertThat(logWriter.isAppend()).isTrue();
}
use of org.eclipse.jetty.server.RequestLogWriter in project spring-boot by spring-projects.
the class JettyWebServerFactoryCustomizerTests method accessLogCanBeEnabled.
@Test
void accessLogCanBeEnabled() {
bind("server.jetty.accesslog.enabled=true");
JettyWebServer server = customizeAndGetServer();
CustomRequestLog requestLog = getRequestLog(server);
assertThat(requestLog.getFormatString()).isEqualTo(CustomRequestLog.NCSA_FORMAT);
assertThat(requestLog.getIgnorePaths()).isNull();
RequestLogWriter logWriter = getLogWriter(requestLog);
assertThat(logWriter.getFileName()).isNull();
assertThat(logWriter.isAppend()).isFalse();
}
Aggregations