title: How do you properly handle logging in OSGi while separating service components?
body: <p>I am working with OSGi and declarative services (DS) and am currently thinking of how to handle the logging properly. Since i'm working with DS anyways, it seems natural to use the LogService specified by the OSGi service compendium as a mandatory service reference. I have been reading a lot on the net at <a href="http://ekkescorner.wordpress.com/blog-series/osgi-apps/" rel="nofollow noreferrer">ekkes corner</a> and <a href="http://blog.kornr.net/index.php/2008/12/16/writing-an-osgi-logging-back-end" rel="nofollow noreferrer">nogunners's blog</a>, but something is still unclear to me:</p>
  
  <p>How do I make a proper distinction of different service components (or different service component instances when using factored components)?</p>
  
  <p>If I look at nogunners implementation of the LogListener using Logback, he uses the Bundle-Id form the bundlecontext to differentiate those. Ok so far. But how would I differentiate the service components? The LogService object contains a reference to the BundleContext naturally, but (looking into the LogService interface) a ServiceReference must be given by the user (the one who actually logs something) itself? This seems fragile to me. Why can't the framework deliver this as it delivers the BundleContext?</p>
  
  <p>And while I'm at it, why does the OSGi spec use the verbose <code>logger.log(LogService.LOG_INFO,...)</code> instead of the quasi-standard <code>logger.info(...), logger.warn(..)</code> etc.? Is there some specific reason for that?</p>