Logging in OSGI Applications – SLF4J

Happy New Year

I wish you all a Happy New Year and hopefully meet many friends at EclipseCon 2010. I booked my flight from MUC to SFO last month – so I’ll be there. Together with all the local events like Eclipse Democamps the yearly EclipseCon is always the best way for me to get in contact with all the great people behind blogs, articles, projects…. – it’s much money if working as a freelancer, but for me it’s worth. In 2009 beside my regular job as consultant I spent (together with flo) much time on redView as you may know from my blogs or presentations.

My plan was to work on publishing redView between X-Mas and NewYear, but I decided to spend the time with my family.
Now its going on…. expect redView available to download this week.

Logging with SLF4J

redView and open-erp-ware are using SLF4J as Logging API, so I want to share the newest informations HowTo use SLF4J in Equinox / OSGI applications.
You should read the whole story about Logging in OSGI Applications at my blog here.

You can download the newest version 1.5.10 of SLF4J from here: http://www.slf4j.org/download.html.
A cool new feature of SLF4J 1.5.10 is localized Logging – this could be very helpful if you deploy Business Applications with the need to log localized mesages. I’ll write an extra blog entry about this later, because at the moment redView has priority.

SLF4J and OSGI Manifests

Thanks to Ceki (the developer of Log4J) there are some OSGI improvements:

Bundle log4j-over-slf4j-1.5.10.jar

You need this bundle if you want to catch Log4J Logging Events and per ex. log them using LogBack – the native Implementation of SLF4J API.
If you look at the MANIFEST.MF of log4j-over-slf4j-1.5.10.jar you’ll see that this was added:

Bundle-Description: Log4j implemented over SLF4J
Bundle-Version: 1.5.10
Implementation-Version: 1.5.10
Implementation-Title: log4j-over-slf4j
Bundle-SymbolicName: log4j.over.slf4j
Bundle-Name: log4j-over-slf4j
Bundle-Vendor: SLF4J.ORG
Export-Package: org.apache.log4j
Import-Package: org.slf4j, org.slf4j.spi

Now you can use this bundle after downloading SLF4J directly without the need of wrapping as I described in some older blogs.

I’m not only catching Logging Events from Log4J, but also from Bundles using JDK Logging, so I need the

Bundle jul-to-slf4j-1.5.10.jar

“jul” means “java.util.logging”. Unfortunately jul-to-slf4j-1.5.10.jar is missing OSGI informations about imported and exported packages:

Import-Package: org.slf4j;version="1.5.10", org.slf4j.spi;version="1.5.10"
Export-Package: org.slf4j.bridge;version="1.5.10"

I opened Bug 166: http://bugzilla.slf4j.org/show_bug.cgi?id=166
In the meantime you have to wrap this bundle and build your own one using PDE or you can download this bundle from SpringSource Enterprise Bundle Repository:

SpringSource Bundle: JUL to SLF4J bridge 1.5.10

http://www.springsource.com/repository/app/bundle/version/detail?name=com.springsource.slf4j.bridge&version=1.5.10

Of course I also looked at Eclipse Orbit, where I only found SLF4J API 1.5.6.

BTW: if you need to catch Log Events from “Commons Logging“, then you need the

bundle jcl-over-slf4j-1.5.10.jar

This Bundle already has a correct OSGI Manifest.

If you like to get more informations on “Logging in Equinox / OSGI applications” feel free to vote for my EclipseCon 2010 Session about Logging – if you like to get more about “redView” please vote for my EclipseCon 2010 Sessions about UI, Eclipse Modeling and Eclipse RT.
ekke

7 responses

  1. Hi Ekke, I already submitted the CQs some days ago shortly after I noticed the EPL licensing of Logback. The logging pieces should be in Orbit before EclipseCon.🙂

  2. Hi ekke,

    I followed your approach with making the jul-to-slf4j bridge OSGi-ready. Unfortunately it then starts logging the first log event once, the second log event twice, the third log event 3 times and so on. It looks like this:

    osgi> greet jul test
    22.04.2010 10:14:37 com.example.console_command.ConsoleExtension _greet
    INFO: JUL logs ‘test’
    XYZ 6266 [OSGi Console] INFO com.example.console_command.ConsoleExtension – JUL logs ‘test’

    osgi> greet jul test2
    22.04.2010 10:14:40 com.example.console_command.ConsoleExtension _greet
    INFO: JUL logs ‘test2’
    XYZ 9866 [OSGi Console] INFO com.example.console_command.ConsoleExtension – JUL logs ‘test2’
    XYZ 9866 [OSGi Console] INFO com.example.console_command.ConsoleExtension – JUL logs ‘test2’

    osgi> greet jul test3
    22.04.2010 10:14:44 com.example.console_command.ConsoleExtension _greet
    INFO: JUL logs ‘test3’
    XYZ 13767 [OSGi Console] INFO com.example.console_command.ConsoleExtension – JUL logs ‘test3’
    XYZ 13767 [OSGi Console] INFO com.example.console_command.ConsoleExtension – JUL logs ‘test3’
    XYZ 13767 [OSGi Console] INFO com.example.console_command.ConsoleExtension – JUL logs ‘test3’

    Have you ever seen such a behaviour? I guess not as you don’t mention it in your article. Anyway I personally prefer using AspectJ aspects with load-time weaving to catch JUL instead of using the bridge approach (for those of you interested in AspectJ LTW with Equinox see http://www.eclipse.org/equinox/incubator/aspects/).

    Cheers, Frieder

  3. Hi there Ekke!

    Is there any video of your talk in eclipsecon about this? Are the slides you used public?

    Thank you very much in advance.

    Cheers!

    • Hi, there should be something…. have to take a look at this…. please remember me next week, just deep inside another project… ekke

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 )

Twitter picture

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

Facebook photo

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

Google+ photo

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

Connecting to %s

%d bloggers like this: