Search in sources :

Example 16 with RequestLog

use of org.eclipse.jetty.server.RequestLog in project javalin by tipsy.

the class TestCustomJetty method test_embeddedServer_withHandlerChain.

@Test
public void test_embeddedServer_withHandlerChain() throws Exception {
    AtomicLong logCount = new AtomicLong(0);
    RequestLog requestLog = (request, response) -> logCount.incrementAndGet();
    RequestLogHandler requestLogHandler = new RequestLogHandler();
    requestLogHandler.setRequestLog(requestLog);
    StatisticsHandler handlerChain = new StatisticsHandler();
    handlerChain.setHandler(requestLogHandler);
    Javalin app = Javalin.create().port(0).embeddedServer(new EmbeddedJettyFactory(() -> {
        Server server = new Server();
        server.setHandler(handlerChain);
        return server;
    })).get("/", ctx -> ctx.result("Hello World")).start();
    String origin = "http://localhost:" + app.port();
    int requests = 10;
    for (int i = 0; i < requests; i++) {
        assertThat(Unirest.get(origin + "/").asString().getBody(), is("Hello World"));
        assertThat(Unirest.get(origin + "/not_there").asString().getStatus(), is(404));
    }
    assertThat(handlerChain.getDispatched(), is(requests * 2));
    assertThat(handlerChain.getResponses2xx(), is(requests));
    assertThat(handlerChain.getResponses4xx(), is(requests));
    assertThat(logCount.get(), is((long) (requests * 2)));
    app.stop();
}
Also used : CoreMatchers.is(org.hamcrest.CoreMatchers.is) AtomicLong(java.util.concurrent.atomic.AtomicLong) RequestLogHandler(org.eclipse.jetty.server.handler.RequestLogHandler) Unirest(com.mashape.unirest.http.Unirest) RequestLog(org.eclipse.jetty.server.RequestLog) StatisticsHandler(org.eclipse.jetty.server.handler.StatisticsHandler) EmbeddedJettyFactory(io.javalin.embeddedserver.jetty.EmbeddedJettyFactory) Test(org.junit.Test) MatcherAssert.assertThat(org.hamcrest.MatcherAssert.assertThat) Server(org.eclipse.jetty.server.Server) EmbeddedJettyFactory(io.javalin.embeddedserver.jetty.EmbeddedJettyFactory) AtomicLong(java.util.concurrent.atomic.AtomicLong) RequestLog(org.eclipse.jetty.server.RequestLog) Server(org.eclipse.jetty.server.Server) RequestLogHandler(org.eclipse.jetty.server.handler.RequestLogHandler) StatisticsHandler(org.eclipse.jetty.server.handler.StatisticsHandler) Test(org.junit.Test)

Example 17 with RequestLog

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

the class LogbackClassicRequestLogFactory method build.

@Override
public RequestLog build(String name) {
    final Logger logger = (Logger) LoggerFactory.getLogger("http.request");
    logger.setAdditive(false);
    final LoggerContext context = logger.getLoggerContext();
    final LevelFilterFactory<ILoggingEvent> levelFilterFactory = new NullLevelFilterFactory<>();
    final AsyncAppenderFactory<ILoggingEvent> asyncAppenderFactory = new AsyncLoggingEventAppenderFactory();
    final LayoutFactory<ILoggingEvent> layoutFactory = (c, tz) -> new RequestLogLayout(c);
    final AppenderAttachableImpl<ILoggingEvent> attachable = new AppenderAttachableImpl<>();
    for (AppenderFactory<ILoggingEvent> appender : appenders) {
        attachable.addAppender(appender.build(context, name, layoutFactory, levelFilterFactory, asyncAppenderFactory));
    }
    return new CustomRequestLog(new DropwizardSlf4jRequestLogWriter(attachable), ClassicLogFormat.pattern(timeZone));
}
Also used : Context(ch.qos.logback.core.Context) JsonProperty(com.fasterxml.jackson.annotation.JsonProperty) ConsoleAppenderFactory(io.dropwizard.logging.ConsoleAppenderFactory) ILoggingEvent(ch.qos.logback.classic.spi.ILoggingEvent) LoggerFactory(org.slf4j.LoggerFactory) AsyncLoggingEventAppenderFactory(io.dropwizard.logging.async.AsyncLoggingEventAppenderFactory) LoggerContext(ch.qos.logback.classic.LoggerContext) Valid(javax.validation.Valid) JsonTypeName(com.fasterxml.jackson.annotation.JsonTypeName) RequestLogFactory(io.dropwizard.request.logging.RequestLogFactory) NullLevelFilterFactory(io.dropwizard.logging.filter.NullLevelFilterFactory) Map(java.util.Map) JsonIgnore(com.fasterxml.jackson.annotation.JsonIgnore) CoreConstants(ch.qos.logback.core.CoreConstants) PatternLayoutBase(ch.qos.logback.core.pattern.PatternLayoutBase) AppenderAttachableImpl(ch.qos.logback.core.spi.AppenderAttachableImpl) RequestLog(org.eclipse.jetty.server.RequestLog) LayoutFactory(io.dropwizard.logging.layout.LayoutFactory) TimeZone(java.util.TimeZone) AppenderFactory(io.dropwizard.logging.AppenderFactory) LevelFilterFactory(io.dropwizard.logging.filter.LevelFilterFactory) NotNull(javax.validation.constraints.NotNull) List(java.util.List) Logger(ch.qos.logback.classic.Logger) CustomRequestLog(org.eclipse.jetty.server.CustomRequestLog) AsyncAppenderFactory(io.dropwizard.logging.async.AsyncAppenderFactory) Collections(java.util.Collections) CustomRequestLog(org.eclipse.jetty.server.CustomRequestLog) NullLevelFilterFactory(io.dropwizard.logging.filter.NullLevelFilterFactory) AppenderAttachableImpl(ch.qos.logback.core.spi.AppenderAttachableImpl) Logger(ch.qos.logback.classic.Logger) ILoggingEvent(ch.qos.logback.classic.spi.ILoggingEvent) LoggerContext(ch.qos.logback.classic.LoggerContext) AsyncLoggingEventAppenderFactory(io.dropwizard.logging.async.AsyncLoggingEventAppenderFactory)

Example 18 with RequestLog

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

the class HttpServer method createLogHandler.

private RequestLogHandler createLogHandler(final HttpServerConfig config) {
    final RequestLogHandler logHandler = new RequestLogHandler();
    final RequestLog requestLog = new NCSARequestLog(config.getLogPath());
    logHandler.setRequestLog(requestLog);
    return logHandler;
}
Also used : NCSARequestLog(org.eclipse.jetty.server.NCSARequestLog) RequestLog(org.eclipse.jetty.server.RequestLog) RequestLogHandler(org.eclipse.jetty.server.handler.RequestLogHandler) NCSARequestLog(org.eclipse.jetty.server.NCSARequestLog)

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