Search in sources :

Example 6 with RequestLog

use of org.eclipse.jetty.server.RequestLog in project felix by apache.

the class RequestLogTracker method addingService.

@Override
public RequestLog addingService(ServiceReference<RequestLog> reference) {
    RequestLog logSvc = context.getService(reference);
    logSvcs.put(reference, logSvc);
    return logSvc;
}
Also used : RequestLog(org.eclipse.jetty.server.RequestLog)

Example 7 with RequestLog

use of org.eclipse.jetty.server.RequestLog in project airlift by airlift.

the class HttpServer method createLogHandler.

private static RequestLogHandler createLogHandler(HttpServerConfig config, TraceTokenManager tokenManager, EventClient eventClient) throws IOException {
    // TODO: use custom (more easily-parseable) format
    // TODO: make retention & rotation configurable
    RequestLogHandler logHandler = new RequestLogHandler();
    File logFile = new File(config.getLogPath());
    if (logFile.exists() && !logFile.isFile()) {
        throw new IOException(format("Log path %s exists but is not a file", logFile.getAbsolutePath()));
    }
    File logPath = logFile.getParentFile();
    if (!logPath.mkdirs() && !logPath.exists()) {
        throw new IOException(format("Cannot create %s and path does not already exist", logPath.getAbsolutePath()));
    }
    RequestLog requestLog = new DelimitedRequestLog(config.getLogPath(), config.getLogHistory(), config.getLogQueueSize(), config.getLogMaxFileSize().toBytes(), tokenManager, eventClient, config.isLogCompressionEnabled());
    logHandler.setRequestLog(requestLog);
    return logHandler;
}
Also used : RequestLog(org.eclipse.jetty.server.RequestLog) RequestLogHandler(org.eclipse.jetty.server.handler.RequestLogHandler) IOException(java.io.IOException) File(java.io.File)

Example 8 with RequestLog

use of org.eclipse.jetty.server.RequestLog in project athenz by yahoo.

the class AthenzJettyContainerTest method testRequestLogHandler.

@Test
public void testRequestLogHandler() {
    System.setProperty(AthenzConsts.ATHENZ_PROP_ACCESS_LOG_RETAIN_DAYS, "3");
    System.setProperty(AthenzConsts.ATHENZ_PROP_MAX_THREADS, "100");
    AthenzJettyContainer container = new AthenzJettyContainer();
    container.createServer(100);
    container.addRequestLogHandler();
    // now retrieve the request log handler
    Handler[] handlers = container.getHandlers().getHandlers();
    RequestLogHandler logHandler = null;
    for (Handler handler : handlers) {
        if (handler instanceof RequestLogHandler) {
            logHandler = (RequestLogHandler) handler;
            break;
        }
    }
    assertNotNull(logHandler);
    RequestLog reqLog = logHandler.getRequestLog();
    assertNotNull(reqLog);
    assertEquals(reqLog.getClass(), AthenzRequestLog.class);
}
Also used : RequestLog(org.eclipse.jetty.server.RequestLog) AthenzRequestLog(com.yahoo.athenz.container.log.AthenzRequestLog) Slf4jRequestLog(org.eclipse.jetty.server.Slf4jRequestLog) RequestLogHandler(org.eclipse.jetty.server.handler.RequestLogHandler) ServletContextHandler(org.eclipse.jetty.servlet.ServletContextHandler) Handler(org.eclipse.jetty.server.Handler) RequestLogHandler(org.eclipse.jetty.server.handler.RequestLogHandler) Test(org.testng.annotations.Test)

Example 9 with RequestLog

use of org.eclipse.jetty.server.RequestLog in project dropwizard by dropwizard.

the class LayoutIntegrationTests method testLogAccessJsonToConsole.

@Test
void testLogAccessJsonToConsole() throws Exception {
    ConsoleAppenderFactory<IAccessEvent> consoleAppenderFactory = getAppenderFactory("yaml/json-access-log-default.yml");
    // Use sys.err, because there are some other log configuration messages in std.out
    consoleAppenderFactory.setTarget(ConsoleAppenderFactory.ConsoleStream.STDERR);
    final LogbackAccessRequestLogFactory requestLogHandler = new LogbackAccessRequestLogFactory();
    requestLogHandler.setAppenders(Collections.singletonList(consoleAppenderFactory));
    PrintStream old = System.err;
    ByteArrayOutputStream redirectedStream = new ByteArrayOutputStream();
    try {
        System.setErr(new PrintStream(redirectedStream));
        RequestLog requestLog = requestLogHandler.build("json-access-log-test");
        Request request = mock(Request.class);
        when(request.getRemoteAddr()).thenReturn("10.0.0.1");
        when(request.getTimeStamp()).thenReturn(TimeUnit.SECONDS.toMillis(1353042047));
        when(request.getMethod()).thenReturn("GET");
        when(request.getRequestURI()).thenReturn("/test/users");
        when(request.getProtocol()).thenReturn("HTTP/1.1");
        when(request.getParameterNames()).thenReturn(Collections.enumeration(Arrays.asList("age", "city")));
        when(request.getParameterValues("age")).thenReturn(new String[] { "22" });
        when(request.getParameterValues("city")).thenReturn(new String[] { "LA" });
        when(request.getAttributeNames()).thenReturn(Collections.enumeration(Collections.emptyList()));
        when(request.getHeaderNames()).thenReturn(Collections.enumeration(Arrays.asList("Connection", "User-Agent")));
        when(request.getHeader("Connection")).thenReturn("keep-alive");
        when(request.getHeader("User-Agent")).thenReturn("Mozilla/5.0");
        Response response = mock(Response.class);
        when(response.getStatus()).thenReturn(200);
        when(response.getContentCount()).thenReturn(8290L);
        HttpFields httpFields = new HttpFields();
        httpFields.add("Date", "Mon, 16 Nov 2012 05:00:48 GMT");
        httpFields.add("Server", "Apache/2.4.12");
        when(response.getHttpFields()).thenReturn(httpFields);
        when(response.getHeaderNames()).thenReturn(Arrays.asList("Date", "Server"));
        when(response.getHeader("Date")).thenReturn("Mon, 16 Nov 2012 05:00:48 GMT");
        when(response.getHeader("Server")).thenReturn("Apache/2.4.12");
        requestLog.log(request, response);
        // Need to wait, because the logger is async
        await().atMost(1, TimeUnit.SECONDS).until(() -> !redirectedStream.toString().isEmpty());
        JsonNode jsonNode = objectMapper.readTree(redirectedStream.toString());
        assertThat(jsonNode.get("timestamp").isNumber()).isTrue();
        assertThat(jsonNode.get("requestTime").isNumber()).isTrue();
        assertThat(jsonNode.get("remoteAddress").asText()).isEqualTo("10.0.0.1");
        assertThat(jsonNode.get("status").asInt()).isEqualTo(200);
        assertThat(jsonNode.get("method").asText()).isEqualTo("GET");
        assertThat(jsonNode.get("uri").asText()).isEqualTo("/test/users");
        assertThat(jsonNode.get("protocol").asText()).isEqualTo("HTTP/1.1");
        assertThat(jsonNode.get("userAgent").asText()).isEqualTo("Mozilla/5.0");
        assertThat(jsonNode.get("contentLength").asInt()).isEqualTo(8290);
    } finally {
        System.setErr(old);
    }
}
Also used : Response(org.eclipse.jetty.server.Response) PrintStream(java.io.PrintStream) RequestLog(org.eclipse.jetty.server.RequestLog) IAccessEvent(ch.qos.logback.access.spi.IAccessEvent) HttpFields(org.eclipse.jetty.http.HttpFields) Request(org.eclipse.jetty.server.Request) JsonNode(com.fasterxml.jackson.databind.JsonNode) ByteArrayOutputStream(java.io.ByteArrayOutputStream) LogbackAccessRequestLogFactory(io.dropwizard.request.logging.LogbackAccessRequestLogFactory) Test(org.junit.jupiter.api.Test)

Example 10 with RequestLog

use of org.eclipse.jetty.server.RequestLog in project spring-boot by spring-projects.

the class JettyWebServerFactoryCustomizerTests method getRequestLog.

private CustomRequestLog getRequestLog(JettyWebServer server) {
    RequestLog requestLog = server.getServer().getRequestLog();
    assertThat(requestLog).isInstanceOf(CustomRequestLog.class);
    return (CustomRequestLog) requestLog;
}
Also used : RequestLog(org.eclipse.jetty.server.RequestLog) CustomRequestLog(org.eclipse.jetty.server.CustomRequestLog) CustomRequestLog(org.eclipse.jetty.server.CustomRequestLog)

Aggregations

RequestLog (org.eclipse.jetty.server.RequestLog)18 RequestLogHandler (org.eclipse.jetty.server.handler.RequestLogHandler)8 Test (org.junit.Test)6 NCSARequestLog (org.eclipse.jetty.server.NCSARequestLog)5 Request (org.eclipse.jetty.server.Request)3 Response (org.eclipse.jetty.server.Response)3 AthenzRequestLog (com.yahoo.athenz.container.log.AthenzRequestLog)2 HashMap (java.util.HashMap)2 Configuration (org.apache.hadoop.conf.Configuration)2 CustomRequestLog (org.eclipse.jetty.server.CustomRequestLog)2 Handler (org.eclipse.jetty.server.Handler)2 HttpConfiguration (org.eclipse.jetty.server.HttpConfiguration)2 IAccessEvent (ch.qos.logback.access.spi.IAccessEvent)1 Logger (ch.qos.logback.classic.Logger)1 LoggerContext (ch.qos.logback.classic.LoggerContext)1 ILoggingEvent (ch.qos.logback.classic.spi.ILoggingEvent)1 Context (ch.qos.logback.core.Context)1 CoreConstants (ch.qos.logback.core.CoreConstants)1 PatternLayoutBase (ch.qos.logback.core.pattern.PatternLayoutBase)1 AppenderAttachableImpl (ch.qos.logback.core.spi.AppenderAttachableImpl)1