use of org.eclipse.jetty.server.handler.RequestLogHandler in project pulsar by yahoo.
the class WebService method start.
public void start() throws PulsarServerException {
try {
RequestLogHandler requestLogHandler = new RequestLogHandler();
Slf4jRequestLog requestLog = new Slf4jRequestLog();
requestLog.setExtended(true);
requestLog.setLogTimeZone(WebService.HANDLER_REQUEST_LOG_TZ);
requestLog.setLogLatency(true);
requestLogHandler.setRequestLog(requestLog);
handlers.add(0, new ContextHandlerCollection());
handlers.add(requestLogHandler);
ContextHandlerCollection contexts = new ContextHandlerCollection();
contexts.setHandlers(handlers.toArray(new Handler[handlers.size()]));
HandlerCollection handlerCollection = new HandlerCollection();
handlerCollection.setHandlers(new Handler[] { contexts, new DefaultHandler(), requestLogHandler });
server.setHandler(handlerCollection);
server.start();
log.info("Web Service started at {}", pulsar.getWebServiceAddress());
} catch (Exception e) {
throw new PulsarServerException(e);
}
}
use of org.eclipse.jetty.server.handler.RequestLogHandler in project athenz by yahoo.
the class AthenzJettyContainer method addRequestLogHandler.
public void addRequestLogHandler() {
RequestLogHandler requestLogHandler = new RequestLogHandler();
// check to see if have a slf4j logger name specified. if we don't
// then we'll just use our NCSARequestLog extended Athenz logger
// when using the slf4j logger we don't have the option to pass
// our audit logger to keep track of unauthenticated requests
String accessSlf4jLogger = System.getProperty(AthenzConsts.ATHENZ_PROP_ACCESS_SLF4J_LOGGER);
if (accessSlf4jLogger != null && !accessSlf4jLogger.isEmpty()) {
Slf4jRequestLog requestLog = new Slf4jRequestLog();
requestLog.setLoggerName(accessSlf4jLogger);
requestLog.setExtended(true);
requestLog.setPreferProxiedForAddress(true);
requestLog.setLogTimeZone("GMT");
requestLogHandler.setRequestLog(requestLog);
} else {
String logDir = System.getProperty(AthenzConsts.ATHENZ_PROP_ACCESS_LOG_DIR, getRootDir() + "/logs/athenz");
String logName = System.getProperty(AthenzConsts.ATHENZ_PROP_ACCESS_LOG_NAME, "access.yyyy_MM_dd.log");
AthenzRequestLog requestLog = new AthenzRequestLog(logDir + File.separator + logName);
requestLog.setAppend(true);
requestLog.setExtended(true);
requestLog.setPreferProxiedForAddress(true);
requestLog.setLogTimeZone("GMT");
String retainDays = System.getProperty(AthenzConsts.ATHENZ_PROP_ACCESS_LOG_RETAIN_DAYS, "31");
int days = Integer.parseInt(retainDays);
if (days > 0) {
requestLog.setRetainDays(days);
}
requestLogHandler.setRequestLog(requestLog);
}
handlers.addHandler(requestLogHandler);
}
use of org.eclipse.jetty.server.handler.RequestLogHandler in project athenz by yahoo.
the class AthenzJettyContainerTest method testSlf4jRequestLogHandler.
@Test
public void testSlf4jRequestLogHandler() {
System.setProperty(AthenzConsts.ATHENZ_PROP_ACCESS_SLF4J_LOGGER, "AthenzAccessLogger");
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(), Slf4jRequestLog.class);
assertEquals(((Slf4jRequestLog) reqLog).getLoggerName(), "AthenzAccessLogger");
System.clearProperty(AthenzConsts.ATHENZ_PROP_ACCESS_SLF4J_LOGGER);
}
use of org.eclipse.jetty.server.handler.RequestLogHandler 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.handler.RequestLogHandler in project incubator-pulsar by apache.
the class ProxyServer method start.
public void start() throws PulsarServerException {
log.info("Starting web socket proxy at port {}", conf.getWebServicePort());
try {
RequestLogHandler requestLogHandler = new RequestLogHandler();
Slf4jRequestLog requestLog = new Slf4jRequestLog();
requestLog.setExtended(true);
requestLog.setLogTimeZone(TimeZone.getDefault().getID());
requestLog.setLogLatency(true);
requestLogHandler.setRequestLog(requestLog);
handlers.add(0, new ContextHandlerCollection());
handlers.add(requestLogHandler);
ContextHandlerCollection contexts = new ContextHandlerCollection();
contexts.setHandlers(handlers.toArray(new Handler[handlers.size()]));
HandlerCollection handlerCollection = new HandlerCollection();
handlerCollection.setHandlers(new Handler[] { contexts, new DefaultHandler(), requestLogHandler });
server.setHandler(handlerCollection);
server.start();
} catch (Exception e) {
throw new PulsarServerException(e);
}
}
Aggregations