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();
}
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));
}
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;
}
Aggregations