Announcement Announcement Module
No announcement yet.
SLF Logging - Am I Being Incredibly Stupid?? Page Title Module
Move Remove Collapse
Conversation Detail Module
  • Filter
  • Time
  • Show
Clear All
new posts

  • SLF Logging - Am I Being Incredibly Stupid??


    I've been trying to get a simple SLF logging bundle up, but failing miserably...

    package logtest;
    import org.osgi.framework.BundleActivator;
    import org.osgi.framework.BundleContext;
    import org.slf4j.Logger;
    import org.slf4j.LoggerFactory;
    public class LogTest implements BundleActivator {
    	private static final Logger LOG = LoggerFactory.getLogger(LogTest.class);
    	public void start(BundleContext arg0) throws Exception {
    	public void stop(BundleContext arg0) throws Exception {
    		// TODO Auto-generated method stub
    in a bundle defined thus:

    Manifest-Version: 1.0
    Bundle-Version: 1.0.0
    Bundle-Name: LogTest
    Bundle-ManifestVersion: 2
    Bundle-SymbolicName: LogTest
    Import-Bundle: com.springsource.slf4j.api;version="[1.5.10,1.5.10]"
    Import-Package: org.osgi.framework;version="[1.5.0,1.5.0]"
    However when the bundle starts I get:

    Unable to satisfy dependencies of bundle 'LogTest' at version '1.0.0': Cannot resolve: LogTest
        Resolver report:
            An Import-Package could not be resolved. Caused by missing constraint in bundle <LogTest_1.0.0>
                 constraint: <Import-Package: org.slf4j.spi; version="0.0.0"> constrained to bundle <com.springsource.slf4j.api> constrained bundle version range "[1.5.10,1.5.10]"
    I would have thought that the LogBack SPI would have already been available as that's what the dm Kernel uses right? What am I doing wrong?

    Thanks for the help...

  • #2
    There is no reason for you to import-bundle slf4j api.

    Import-Package: org.slf4j;version=1.5.10


    • #3
      OK, isn't direct bundle imports 'better' rather than magic selection by the platform? I mean, thanks yes this works fantastic... but is this the optimal or recommended method?


      • #4
        I don't understand what you mean by "magic selection by the platform"?

        But from a purist stand point - yes Import-Package is much better.


        • #5
          Ah... I was taught that Import-Bundle was better... I'll stand corrected. Thanks for the assistance.


          • #6
            Dmitry is right in this case.

            Import-Package has the virtue of being a standard OSGi header and so is portable to other OSGi containers, plus it imports specific packages and so narrows the dependencies of the bundle that uses it.

            Import-Bundle is better for cases where you need to obtain a set of packages which tend to be implementation specific and vary over time, e.g. types which will be woven into your code but which your code does not explicitly reference.