Search code examples
jetty

Porting from Jetty 11 to Jetty 12. Missing RequestLogHandler


I am porting application that uses Jetty as a HTTP server from Jetty 11 to Jetty 12.

I have problem with RequestLogHandler class, which seems to be missing in Jetty 12.

var address = new InetSocketAddress(settings.getBindingInterface(), settings.getPort());
var jettyServer = new Server(address);
var handler = new ServletContextHandler(ServletContextHandler.NO_SESSIONS);
handler.setContextPath("/");

var statisticsHandler = new StatisticsHandler();
statisticsHandler.setHandler(handler);

var requestLogHandler = new RequestLogHandler();
requestLogHandler.setHandler(statisticsHandler);

var requestLog = new CustomRequestLog(new Slf4jRequestLogWriter(), CustomRequestLog.NCSA_FORMAT);
requestLogHandler.setRequestLog(requestLog);
handler.setErrorHandler(new MyErrorHandler());
jettyServer.setHandler(requestLogHandler);

Can you help me to:

  • confirm that RequestLogHandler is now gone (and not moved to a separate artifact)
  • optionally, find the pull request that introduced that change
  • write equivalent code in Jetty 12

Solution

  • Use Server.setRequestLog(RequestLog) instead.

    The RequestLogHandler was an artifact from the Jetty 5 thru Jetty 9 era.

    It was heavily neutered in Jetty 10, and does almost nothing compared to Jetty 9.

    The use of Server.setRequestLog(RequestLog) is even mentioned in the javadoc for RequestLogHandler in Jetty 10/11.

    The server level version logs all requests, even failures, errors, bad requests, request that don't have a path, request that don't match a context, etc...