jetty.project icon indicating copy to clipboard operation
jetty.project copied to clipboard

logback-access no longer works with Jetty 9.3+

Open kevinjom opened this issue 10 years ago • 6 comments

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?

kevinjom avatar Apr 13 '16 03:04 kevinjom

I'm wondering too.... I also note that RequestLogCollection does not implement LifeCycle (it should probably be a ContainerLifeCycle )

gregw avatar Apr 13 '16 05:04 gregw

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 {}

gregw avatar Apr 13 '16 05:04 gregw

Just a heads-up that there's already an issue raised about this for logback: qos-ch/logback#269

ajfitzpatrick avatar Apr 13 '16 05:04 ajfitzpatrick

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 avatar Apr 13 '16 15:04 joakime

@joakime can we push some doco for this at qos-ch/logback#269

gregw avatar Apr 13 '16 21:04 gregw

@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.

kevinjom avatar Apr 14 '16 15:04 kevinjom