title: Apache Felix OSGi logging with Logback
body: <p>My current application uses <a href="http://logback.qos.ch/" rel="nofollow">Logback</a> for logging. I have used Apache Felix to deploy an OSGi framework that allows bundles to be dynamically registered at runtime. The Felix setup is as follows:</p>
  
  <pre><code>    ...
  
      //System.out.println("Building OSGi Framework");
      FrameworkFactory frameworkFactory = ServiceLoader.load(FrameworkFactory.class).iterator().next();
      Map&lt;String, String&gt; config = new HashMap&lt;&gt;();
  
      // specify the class loader
      config.put(Constants.FRAMEWORK_BUNDLE_PARENT, Constants.FRAMEWORK_BUNDLE_PARENT_FRAMEWORK);
  
      // specify the osgi cache directory
      config.put(Constants.FRAMEWORK_STORAGE, appConfig.getOsgiCacheDir());
  
      // make sure the cache is cleaned
      config.put(Constants.FRAMEWORK_STORAGE_CLEAN, Constants.FRAMEWORK_STORAGE_CLEAN_ONFIRSTINIT);
  
      // expose api
      config.put(Constants.FRAMEWORK_SYSTEMPACKAGES_EXTRA, "list.of.packages.to.export");
  
      // more properties available at: http://felix.apache.org/documentation/subprojects/apache-felix-service-component-runtime.html
      config.put("ds.showtrace", "false");
      config.put("ds.showerrors", "true");
      config.put("felix.fileinstall.dir", appConfig.getActiveOsgiExtDir());
      config.put("felix.fileinstall.tmpdir", appConfig.getTempOsgiExtDir());
      config.put("felix.fileinstall.bundles.startTransient","true");
      config.put("felix.fileinstall.poll","5000");
      config.put("felix.fileinstall.bundles.new.start", "true");
  
      LOG.debug("OSGi config: " + config.toString());
  
      framework = frameworkFactory.newFramework(config);
  
      try {
          framework.init();
          FrameworkEvent event;
  
          do {
              framework.start();
      ...
  </code></pre>
  
  <p>The only problem is that there seems to be no logging with Felix. When a bundle fails to load for some reason I can't see why! I know that I can use the following in the bundle to obtain the parent logger:</p>
  
  <pre><code>ServiceReference ref = bundleContext.getServiceReference(LogService.class.getName());
  if (ref != null) {
      LogService log = (LogService) bundleContext.getService(ref);
      ...
     }
  </code></pre>
  
  <p>However, I don't understand how I can get felix to use logback as the logger in the first place.</p>