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

  • SLF Logging - Am I Being Incredibly Stupid??

    Hi,

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

    Code:
    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);
    
    	@Override
    	public void start(BundleContext arg0) throws Exception {
    		LOG.error("Testing");
    	}
    
    	@Override
    	public void stop(BundleContext arg0) throws Exception {
    		// TODO Auto-generated method stub
    
    	}
    
    }
    in a bundle defined thus:

    Code:
    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:

    Code:
    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.

    Just
    Code:
    Import-Package: org.slf4j;version=1.5.10

    Comment


    • #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?

      Comment


      • #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.

        Comment


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

          Comment


          • #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.

            Comment

            Working...
            X