Friday, 12 March 2010

OSGi Tips&Tricks: Logging. OSGi to JUL. Forward OSGi logs to java.util.logging

Morning everybody,

There is a small tip - how to forward log entries from OSGi LogService to java.util.logging (JUL).
Steps that you have to do:
  1. Get org.osgi.service.log.LogReaderService from OSGi registry
  2. Add your implementation of org.osgi.service.log.LogListener interface to LogReaderService
  3. Initialize/get Java util Logger instance
  4. Implement LogListener method public void logged(LogEntry) to map OSGi LogEntry instance to Java LogRecord and publish it with Logger.

public void logged(LogEntry logEntry) {

You can configure name on Java Logger with system property "" with my reference implementation.

Have a nice day!

1 comment:

  1. Excellent article , you have indeed covered topic in details with code examples and explanation. I have also blogged some of my experience as 10 tips on logging in Java