Search code examples
eclipseosgislf4jequinoxtycho

OSGi + Logback + slf4j - Eclipse Run Configuration


Here is my configuration:

We are developing an OSGi application and want to include logging. I decided to use slf4j + logback.

We are using Eclipse as an IDE and Tycho to benefit from the Eclipse IDE like Manifest Editor and so on.

So I have tried the following:

Created a new plugin with the following Manifest.mf:

Manifest-Version: 1.0
Bundle-ManifestVersion: 2
Bundle-Name: Createcommand
Bundle-SymbolicName: de.hswt.oms.ws.wsr.createcommand
Bundle-Version: 1.0.0.qualifier
Bundle-RequiredExecutionEnvironment: JavaSE-1.7
Import-Package: de.hswt.oms.ws.command.wsr,
 de.hswt.oms.ws.ds.core.data.impl,
org.slf4j
Service-Component: OSGI-INF/component.xml

Now when i move to Run -> Run Configurations -> OSGi Framework and select my Bundle and click "Add Required plugins" more than 100 Bundles will be selected and I get a lot of errors and exceptions.

So I came up with a new plugin from existing Jars which include the following three jars:

  • logback-classic-1.0.7
  • logback-core-1.0.7
  • com.springsource.slf4j.api-1.6.1 (I dont believe this is a good idea, but hey...)

If I create a new run configuration manually (not clicking "add required bundles" it works as expected but as far as I click "add required bundles" I come back to the more then 100 Bundles with a lot of errors (some Jetty stuff for example...)

So my Question is: How can I enable logback and slf4j in my OSGi application and use it within eclipse and configure it properly?

If you need more information please feel free to ask.


Solution

  • AFAIK there are some issues in the bundle manifest header in the current official Logback/SLF4J jars. However, you only need the following three jars/bundles. No other are required for the basic functionality.

    • SLF4J API
    • Logback Core
    • Logback Classic

    At Eclipse we put the bundles in Orbit for re-use across projects. We apply some modifications to the manifest header that we think are beneficial. For example, we deliver the actual SLF4J binding as a fragment to avoid the circular dependency of the original SLF4J API jar.

    Here are the download links to the bundles:

    You may also want:

    Please note that "Add Required plugins" is not smart enough. It may select too many or too few plug-ins. Sometimes service API is delivered in one bundle but the actual service implementation is delivered in a second bundle. It may not select that bundle.