logback-access no longer works with Jetty 9.3+
We are working in a plain old servlet project, and we use embedded jetty (version 9.3.7.v20160115) as our servlet container, and we use RequestLogImpl from logback-access to log request log.
Here is some simple example code
Server server = new Server(8081);
RequestLogImpl requestLog = new RequestLogImpl();
requestLog.setResource("logback-access.xml");
RequestLogHandler logHandler = new RequestLogHandler();
logHandler.setRequestLog(requestLog);
server.setHandler(logHandler);
server.start();
server.dumpStdErr();
server.join();
But after we restarted the server, and make some requests, we didn't see any access log came out. Then we decided to debug and finally found out the reason is because RequestLog doesn't extend LifeCycle, so the start method of RequestLogImpl, which will init and configure the logback, will not be called.
Then we tried 9.2.15.v20160210, and it worked well.
So I am wondering why you made this change and if there is some better solution for our case?
I'm wondering too.... I also note that RequestLogCollection does not implement LifeCycle (it should probably be a ContainerLifeCycle )
Well this really should be up to ch.qos.logback.access.jetty to either extend AbstractLifeCycle or implement LifeCycle rather than just implement our LifeCycle signature without declaration. Hmmm although I guess we did change our RequestLog interface to not extend LifeCycle.
I think we need to suggest some changes and provide a wrapper class. Alternately, we could just take over RequestLogImpl and provide our own logback adaptor? @joakime, can you liaise with the ch.qos folks to find the best path to resolve this
@kevinjom for now, you probably need to either start explicitly or do something like:
class MyRequestLog extends RequestLogImpl implements LifeCycle {}
Just a heads-up that there's already an issue raised about this for logback: qos-ch/logback#269
The RequestLog has transitioned from being a traditional Handler in the Jetty sense, to being a specialized implementation that the HttpChannel uses.
This was done to address many bug with async request logging, along with request logging of bad requests (ones that cannot be sent to a context).
Since you are using slf4j & logback, you no longer need logback-access in Jetty 9.3+
Use the org.eclipse.jetty.server.Slf4jRequestLog implementation and just configure your normal logback to to route the named logging to the log appender of your choice.
@joakime can we push some doco for this at qos-ch/logback#269
@joakime the reason why we use logback-access is because it provides some easy ways to get and config the access info. We have created a custom RequestLog which extended RequestLogImpl and implemented LifeCycle just as @gregw pointed, and it worked fine for now. Thanks you guys for your reply and ideas.