Spring BootでJettyのログを有効にする

  • 3
    Like
  • 0
    Comment

参考先 http://wiki.eclipse.org/Jetty/Tutorial/RequestLog

@Configuration
public class WebConfig {
    @Bean
    public EmbeddedServletContainerFactory jettyEmbeddedServletContainerFactory() {
        JettyEmbeddedServletContainerFactory factory = new JettyEmbeddedServletContainerFactory();
        factory.addServerCustomizers(new JettyServerCustomizer() {
            @Override
            public void customize(Server server) {
                HandlerCollection handlers = new HandlerCollection();
                RequestLogHandler requestLogHandler = new RequestLogHandler();
                for (Handler handler : server.getHandlers()) {
                    handlers.addHandler(handler);
                }

                NCSARequestLog requestLog = new NCSARequestLog("/var/log/jetty-yyyy_mm_dd.request.log");
                requestLog.setRetainDays(90);
                requestLog.setAppend(true);
                requestLog.setExtended(false);
                requestLog.setLogTimeZone("GMT");
                requestLogHandler.setRequestLog(requestLog);
                handlers.addHandler(requestLogHandler);
                server.setHandler(handlers);
            }
        });
        return factory;
    }
}