OSGi LogListener for SLF4J



Slf4jLogListener (implements LogListener) forwards all the LogEntry‘s (logged by a LogService) to an SLF4J Logger that is assigned to the bundle that created the LogEntry. The name of the used Logger is constructed from the symbolic name and the version of the bundle.

The following log level mapping is used between the OSGi LogService and the SLF4J Logger:

LogService.LOG_DEBUG (4)   --> Logger.debug(..)
LogService.LOG_INFO (3)    --> Logger.info(..)
LogService.LOG_WARNING (2) --> Logger.warn(..)
LogService.LOG_ERROR (1)   --> Logger.error(..)
other user defined         --> Logger.warn(..) with logging the
                                               original level


The OSGi bundle of the Slf4jLogListener contains a BundleActivator that automatically opens a ServiceTracker for LogReaderService services. This ServiceTracker registers an Slf4jLogListener instance to the LogReaderService services by invoking addLogListener() method on them. The registered instance is removed from the LogReaderService when the service is removed.

Just activate the org.everit.osgi.loglistener.slf4j bundle in your OSGi container, configure an SLF4J implementaion (slf4j-simple, logback, etc.) and you…

View original post 149 more words

Posted in Uncategorized

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: