Search code examples
loggingosgipax

Is there a way to get all log events in osgi pax logging


Is there a way to get all log events in pax logging?. I tried to getthe log events using following code. But no luck. Any idea on how to get all log events?

logReaderService.addLogListener(new TestLogListener()); //org.osgi.service.log.LogReaderService 

//sample log listener
class TestLogListener implements org.osgi.service.log.LogListener {
    private static final Logger logger = LoggerFactory.getLogger(TestLogListener.class);
    @Override
    public void logged(LogEntry logEntry) {
        logger.info("LOG MESSAGE ::"+logEntry.getMessage());
    }
}


Solution

  • Take a look at the karaf logging service:

    https://github.com/apache/karaf/tree/master/log/src/main/java/org/apache/karaf/log/core

    It creates a PaxAppender and registers it as a service. This will hook into pax logging to receive all log events.