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.



On Fri, Feb 12, 2021 at 1:29 PM Alain Picard <[email protected]>
wrote:

> 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".
>
>
>
>
> On Fri, Feb 12, 2021 at 12:24 PM Alain Picard <
> [email protected]> wrote:
>
>> 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 <http://logback.qos.ch/access.html#jetty>:
>>
>> 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.
>> <http://ops4j.github.io/pax/web/6.x/User-Guide.html#adding-specialized-contexthandlers>
>>
>> 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
>>
>> --
>> --
>> ------------------
>> OPS4J - http://www.ops4j.org - [email protected]
>>
>> ---
>> 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
>> [email protected].
>> To view this discussion on the web visit
>> https://groups.google.com/d/msgid/ops4j/cafa4d6c-5eda-49e5-a72f-d17e1bd256edn%40googlegroups.com
>> <https://groups.google.com/d/msgid/ops4j/cafa4d6c-5eda-49e5-a72f-d17e1bd256edn%40googlegroups.com?utm_medium=email&utm_source=footer>
>> .
>>
>

-- 
-- 
------------------
OPS4J - http://www.ops4j.org - [email protected]

--- 
You received this message because you are subscribed to the Google Groups 
"OPS4J" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/ops4j/CAAq-gCxko%2BqVBb5JCetYsS5zpjGLQuvfifUdKHT7%2B%3DK674vfbA%40mail.gmail.com.

Reply via email to