[logback-user] SLF4J in OSGi ?

John Shooab jshooab at gmail.com
Mon Jul 1 20:11:04 CEST 2013


Hi Christopher,

We did a Prove Of Concept today and I like a lot what we got...

We created our own implementation of LogService and ExtendendLogService 
using Logback in the back stage.

Then, we create a DS component implementing ILoggerFactory and another 
DS factory component implementing Logger...

then in our abstract service component we bind a reference of the Logger 
service instead to use the Static factory:
@Reference()
     protected void bindLogger(Logger logger) {}

and we use Config Admin to setup programmatically the Root log level, 
appenders and its string pattern.

well, now we just need to learn how to use MDC and Markers...

But we agree to use Logback in our OSGi application...

Many thanks for your tips !

cheers,

John

On 29/06/13 05:41, Christopher BROWN wrote:
>
> Hi,
>
> Wé use SLF4J and the LogService with OSGi. We provide an 
> implementation of LogService that uses SLF4J to perform logging, 
> instead of using any other implementation (which keeps things consistent).
>
> I find the MDC (Mapped Diagnostic Context) to be very helpful for 
> distinguishing log messages relating to specific transactions, a big 
> win over the basic LogService (which benefits from MDC too in this 
> scenario).
>
> Specifically:
> - we use an embedded instance of Apache Felix
> - the host application uses native file watching to handle bundle 
> updates and detect runtime configuration changes... And configures logging
> - therefore, SLF4J is NOT deployed as a bundle, because we want to log 
> the host application's activity before the framework starts.
> - the host application exports the SLF4J packages, but NOT Logback, 
> it's the host application that binds LogBack and SLF4J, so that 
> applications do not see the implementation.
> - we configure SLF4J programmatically, using our own configuration in 
> the host application (avoids headaches finding the configuration in 
> the classpath for OSGi bundles).
> -  the only disadvantage being the inability to update SLF4J / Logback 
> without an application restart, but it's outweighed by not having any 
> period without a logger available.
>
> For implementing the LogService with SLF4J, look into 
> LocationAwareLogger.  Implement it in the host application and 
> register it as a service from the framework's BundleContext. Also, 
> export SLF4J (but not logback) using the "system packages extra" property.
>
> That way, you can mix SLF4J and LogService without any inconsistency.
>
> Hope that helps.
>
> Le 29 juin 2013 03:54, "John Shooab" <jshooab at gmail.com 
> <mailto:jshooab at gmail.com>> a écrit :
>
>     Hi,
>
>     In our company we develop OSGi based applications and use
>     LogService to logging. We use a Log Reader service that writes the
>     logging of all bundles to a group of files.
>
>     But there are some coworkers that vote to use SLF4J and Logback in
>     a new application because it has a interface with more intuitive
>     methods. but I'm reluctant. I don't see with good yes the use of
>     the static factory method in OSGi.
>
>     I would appreciate if anyone using Logback on OSGi share any
>     experience and point any advantage of its use instead of the
>     LogService.
>
>     thanks a lot,
>
>     John
>     _______________________________________________
>     Logback-user mailing list
>     Logback-user at qos.ch <mailto:Logback-user at qos.ch>
>     http://mailman.qos.ch/mailman/listinfo/logback-user
>
>
>
> _______________________________________________
> Logback-user mailing list
> Logback-user at qos.ch
> http://mailman.qos.ch/mailman/listinfo/logback-user

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mailman.qos.ch/pipermail/logback-user/attachments/20130701/292ad002/attachment-0001.html>


More information about the Logback-user mailing list