Search in sources :

Example 1 with RequestLogWriter

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);
    });
}
Also used : CustomRequestLog(org.eclipse.jetty.server.CustomRequestLog) RequestLogWriter(org.eclipse.jetty.server.RequestLogWriter)

Example 2 with RequestLogWriter

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();
}
Also used : CustomRequestLog(org.eclipse.jetty.server.CustomRequestLog) RequestLogWriter(org.eclipse.jetty.server.RequestLogWriter) File(java.io.File) JettyWebServer(org.springframework.boot.web.embedded.jetty.JettyWebServer) Test(org.junit.jupiter.api.Test)

Example 3 with RequestLogWriter

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();
}
Also used : CustomRequestLog(org.eclipse.jetty.server.CustomRequestLog) RequestLogWriter(org.eclipse.jetty.server.RequestLogWriter) JettyWebServer(org.springframework.boot.web.embedded.jetty.JettyWebServer) Test(org.junit.jupiter.api.Test)

Aggregations

CustomRequestLog (org.eclipse.jetty.server.CustomRequestLog)3 RequestLogWriter (org.eclipse.jetty.server.RequestLogWriter)3 Test (org.junit.jupiter.api.Test)2 JettyWebServer (org.springframework.boot.web.embedded.jetty.JettyWebServer)2 File (java.io.File)1