Switching request log to logback access for Jetty

130 views
Skip to first unread message

Alain Picard

unread,
Feb 12, 2021, 12:24:47 PM2/12/21
to OPS4J
We're trying to switch Jetty request logging to logback access to get better control of options, especially compression on file rotation.

The instructions are here

Basically have to make sure that jetty.xml includes RequestLogHandler and then add a reference to it pointing to ch.qos.logback.access.jetty.RequestLogImpl

Now in the pax web documentation I would like to use the service registration approach as described here.

I created a small component with:
    @Activate
    private void activate(BundleContext context) {
        log.trace("Activating {}", getClass()); //$NON-NLS-1$
        RequestLogHandler requestLogHandler = new RequestLogHandler();
        context.registerService(Handler.class, requestLogHandler, null);
        RequestLogImpl requestLogImpl = new RequestLogImpl();
        Optional.ofNullable(irisConfig)
                .map(config -> config.getValue(ConfigConstants.NCSA_LOG_CONFIG))
                .ifPresentOrElse(requestLogImpl::setFileName,
                        () -> log.error("No configured NCSA request log file location")); //$NON-NLS-1$

        context.registerService(RequestLog.class, requestLogImpl, null);
    }

The code is invoked correctly but I put a breakpoint in RequestLogImpl#getConfigurationFileURL but it is never called. Looking at my log I have the feeling that paxweb is starting before my code runs.

So am I doing something wrong in registering the services or is it an issue of ordering or something else?

Any help will be greatly appreciated.

Cheers
Alain

Alain Picard

unread,
Feb 12, 2021, 1:30:24 PM2/12/21
to op...@googlegroups.com
After this I tried using the application and got an NPE which lead me to fix a few things and realize that it partly works.

Here is my newest code:
@Activate
private void activate(BundleContext context) {
  log.trace("Activating {}", getClass()); //$NON-NLS-1$

  RequestLogImpl requestLogImpl = new RequestLogImpl();
  requestLogImpl.setName("Logback Access Request Log");

  Optional.ofNullable(irisConfig)
     .map(config -> config.getValue(ConfigConstants.NCSA_LOG_CONFIG))
     .ifPresentOrElse(requestLogImpl::setFileName,
         () -> log.error("No configured NCSA request log file location")); //$NON-NLS-1$

  RequestLogHandler requestLogHandler = new RequestLogHandler();
  requestLogHandler.setRequestLog(requestLogImpl);
  context.registerService(Handler.class, requestLogHandler, null);
}

Now I can debug and see that Jetty has both the standard NCSA logger and the logback one and that it sends the log requests to both.

Issue now:
- How can I configure it to not have NCSA logger
- Log request going to logback don't even hit the previously mentioned breakpoint, indicating that it is not "started".




--
--
------------------
OPS4J - http://www.ops4j.org - op...@googlegroups.com

---
You received this message because you are subscribed to a topic in the Google Groups "OPS4J" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/ops4j/7eGUTokx_cw/unsubscribe.
To unsubscribe from this group and all its topics, send an email to ops4j+un...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/ops4j/cafa4d6c-5eda-49e5-a72f-d17e1bd256edn%40googlegroups.com.

Alain Picard

unread,
Feb 13, 2021, 5:53:00 AM2/13/21
to op...@googlegroups.com
Well I got it working with the following:
@Activate
private void activate(BundleContext context) {
   log.trace("Activating {}", getClass()); //$NON-NLS-1$

  Optional.ofNullable(irisConfig)
    .map(config -> config.getValue(ConfigConstants.NCSA_LOG_CONFIG))
    .ifPresentOrElse(logName -> {

      RequestLogImpl requestLogImpl = new RequestLogImpl();
      requestLogImpl.setName("Logback Access Request Log");
      requestLogImpl.setFileName(logName);
      requestLogImpl.start();

      RequestLogHandler requestLogHandler = new RequestLogHandler();
      requestLogHandler.setRequestLog(requestLogImpl);
      context.registerService(Handler.class, requestLogHandler, null);
    },
    () -> log.error("No configured NCSA request log file location")); //$NON-NLS-1$
}

And then log.ncsa.enabled=false in Pax Web.
Note that the issue with lack of content from logback forced me to add a start, which doesn't seem to be documented, but referenced in a forum.

Hopefully this can help others and provide an easy way to provide file rotation that includes compression with Pax Web/Jetty.


Reply all
Reply to author
Forward
0 new messages