Add appropriate bundle to log messages. (FELIX-2555)


git-svn-id: https://svn.apache.org/repos/asf/felix/trunk@997501 13f79535-47bb-0310-9956-ffa450edef68
diff --git a/framework/src/main/java/org/apache/felix/framework/BundleContextImpl.java b/framework/src/main/java/org/apache/felix/framework/BundleContextImpl.java
index 2c16eb7..fd39434 100644
--- a/framework/src/main/java/org/apache/felix/framework/BundleContextImpl.java
+++ b/framework/src/main/java/org/apache/felix/framework/BundleContextImpl.java
@@ -262,7 +262,7 @@
         }
         catch (InvalidSyntaxException ex)
         {
-            m_logger.log(Logger.LOG_ERROR, "BundleContextImpl: " + ex);
+            m_logger.log(m_bundle, Logger.LOG_ERROR, "BundleContextImpl: " + ex);
         }
         return null;
     }
diff --git a/framework/src/main/java/org/apache/felix/framework/BundleImpl.java b/framework/src/main/java/org/apache/felix/framework/BundleImpl.java
index 599b791..c1e4b21 100644
--- a/framework/src/main/java/org/apache/felix/framework/BundleImpl.java
+++ b/framework/src/main/java/org/apache/felix/framework/BundleImpl.java
@@ -107,6 +107,7 @@
             catch (Exception ex)
             {
                 getFramework().getLogger().log(
+                    this,
                     Logger.LOG_ERROR,
                     "Unable to close archive revisions.", ex);
             }
@@ -153,7 +154,7 @@
     {
         if (isExtension() && (getFramework().getState() != Bundle.STOPPING))
         {
-            getFramework().getLogger().log(Logger.LOG_WARNING,
+            getFramework().getLogger().log(this, Logger.LOG_WARNING,
                 "Framework restart on extension bundle refresh not implemented.");
         }
         else
@@ -202,7 +203,8 @@
 
         if (sm != null)
         {
-           ((SecurityManager) sm).checkPermission(new AdminPermission(this, AdminPermission.CONTEXT));
+           ((SecurityManager) sm).checkPermission(
+               new AdminPermission(this, AdminPermission.CONTEXT));
         }
 
         return m_context;
@@ -222,6 +224,7 @@
         catch (Exception ex)
         {
             getFramework().getLogger().log(
+                this,
                 Logger.LOG_ERROR,
                 "Error getting the identifier from bundle archive.",
                 ex);
@@ -371,8 +374,8 @@
 
             if (!localize)
             {
-                // If localization is not needed, just cache the headers and return them as-is
-                // Not sure if this is useful
+                // If localization is not needed, just cache the headers and return
+                // them as-is. Not sure if this is useful
                 updateHeaderCache(locale, headers);
             }
             else
@@ -386,7 +389,8 @@
 
                 // Create ordered list of modules to search for localization
                 // property resources.
-                List moduleList = createLocalizationModuleList((ModuleImpl) getCurrentModule());
+                List moduleList = createLocalizationModuleList(
+                    (ModuleImpl) getCurrentModule());
 
                 // Create ordered list of files to load properties from
                 List resourceList = createLocalizationResourceList(basename, locale);
@@ -405,7 +409,8 @@
                             found = true;
                             try
                             {
-                                mergedProperties.load(temp.openConnection().getInputStream());
+                                mergedProperties.load(
+                                    temp.openConnection().getInputStream());
                             }
                             catch (IOException ex)
                             {
@@ -523,6 +528,7 @@
         catch (Exception ex)
         {
             getFramework().getLogger().log(
+                this,
                 Logger.LOG_ERROR,
                 "Error reading last modification time from bundle archive.",
                 ex);
@@ -539,6 +545,7 @@
         catch (Exception ex)
         {
             getFramework().getLogger().log(
+                this,
                 Logger.LOG_ERROR,
                 "Error writing last modification time to bundle archive.",
                 ex);
@@ -566,6 +573,7 @@
         catch (Exception ex)
         {
             getFramework().getLogger().log(
+                this,
                 Logger.LOG_ERROR,
                 "Error getting location from bundle archive.",
                 ex);
@@ -586,8 +594,8 @@
         {
             try
             {
-                ((SecurityManager) sm).checkPermission(new AdminPermission(this,
-                    AdminPermission.RESOURCE));
+                ((SecurityManager) sm).checkPermission(
+                    new AdminPermission(this, AdminPermission.RESOURCE));
             }
             catch (Exception e)
             {
@@ -606,8 +614,8 @@
         {
             try
             {
-                ((SecurityManager) sm).checkPermission(new AdminPermission(this,
-                    AdminPermission.RESOURCE));
+                ((SecurityManager) sm).checkPermission(
+                    new AdminPermission(this, AdminPermission.RESOURCE));
             }
             catch (Exception e)
             {
@@ -686,8 +694,8 @@
             {
                 try
                 {
-                    ((SecurityManager) sm).checkPermission(new ServicePermission(
-                        refs[i], ServicePermission.GET));
+                    ((SecurityManager) sm).checkPermission(
+                        new ServicePermission(refs[i], ServicePermission.GET));
 
                     result.add(refs[i]);
                 }
@@ -728,6 +736,7 @@
         catch (Exception ex)
         {
             getFramework().getLogger().log(
+                this,
                 Logger.LOG_ERROR,
                 "Error reading persistent state from bundle archive.",
                 ex);
@@ -743,7 +752,7 @@
         }
         catch (Exception ex)
         {
-            getFramework().getLogger().log(Logger.LOG_ERROR,
+            getFramework().getLogger().log(this, Logger.LOG_ERROR,
                 "Error writing persistent state to bundle archive.",
                 ex);
         }
@@ -758,6 +767,7 @@
         catch (Exception ex)
         {
             getFramework().getLogger().log(
+                this,
                 Logger.LOG_ERROR,
                 "Error writing persistent state to bundle archive.",
                 ex);
@@ -773,6 +783,7 @@
         catch (Exception ex)
         {
             getFramework().getLogger().log(
+                this,
                 Logger.LOG_ERROR,
                 "Error writing persistent state to bundle archive.",
                 ex);
@@ -787,6 +798,7 @@
         catch (Exception ex)
         {
             getFramework().getLogger().log(
+                this,
                 Logger.LOG_ERROR,
                 "Error writing persistent state to bundle archive.",
                 ex);
@@ -802,6 +814,7 @@
         catch (Exception ex)
         {
             getFramework().getLogger().log(
+                this,
                 Logger.LOG_ERROR,
                 "Error reading start level from bundle archive.",
                 ex);
@@ -818,6 +831,7 @@
         catch (Exception ex)
         {
             getFramework().getLogger().log(
+                this,
                 Logger.LOG_ERROR,
                 "Error writing start level to bundle archive.",
                 ex);
diff --git a/framework/src/main/java/org/apache/felix/framework/ExtensionManager.java b/framework/src/main/java/org/apache/felix/framework/ExtensionManager.java
index ff6fa7f..5c5fb42 100644
--- a/framework/src/main/java/org/apache/felix/framework/ExtensionManager.java
+++ b/framework/src/main/java/org/apache/felix/framework/ExtensionManager.java
@@ -199,6 +199,7 @@
         {
             m_capabilities = new ArrayList<Capability>(0);
             m_logger.log(
+                felix,
                 Logger.LOG_ERROR,
                 "Error parsing system bundle export statement: "
                 + syspkgs, ex);
@@ -325,6 +326,7 @@
             catch (Exception ex)
             {
                 m_logger.log(
+                    bundle,
                     Logger.LOG_ERROR,
                     "Error parsing extension bundle export statement: "
                     + bundle.getCurrentModule().getHeaders().get(Constants.EXPORT_PACKAGE), ex);
@@ -340,7 +342,7 @@
             else
             {
                 // We don't support extensions (i.e., the parent is not an URLClassLoader).
-                m_logger.log(Logger.LOG_WARNING,
+                m_logger.log(bundle, Logger.LOG_WARNING,
                     "Unable to add extension bundle to FrameworkClassLoader - Maybe not an URLClassLoader?");
                 throw new UnsupportedOperationException(
                     "Unable to add extension bundle to FrameworkClassLoader - Maybe not an URLClassLoader?");
@@ -394,7 +396,7 @@
             }
             catch (Throwable ex)
             {
-                m_logger.log(Logger.LOG_WARNING,
+                m_logger.log(bundle, Logger.LOG_WARNING,
                     "Unable to start Felix Extension Activator", ex);
             }
         }
diff --git a/framework/src/main/java/org/apache/felix/framework/Felix.java b/framework/src/main/java/org/apache/felix/framework/Felix.java
index 9604a69..aa45768 100644
--- a/framework/src/main/java/org/apache/felix/framework/Felix.java
+++ b/framework/src/main/java/org/apache/felix/framework/Felix.java
@@ -1107,7 +1107,7 @@
                     if (impl.getState() != Bundle.UNINSTALLED)
                     {
                         fireFrameworkEvent(FrameworkEvent.ERROR, impl, ex);
-                        m_logger.log(
+                        m_logger.log(impl,
                             Logger.LOG_ERROR,
                             "Error locking " + impl._getLocation(), ex);
                     }
@@ -1145,7 +1145,7 @@
                         catch (Throwable th)
                         {
                             fireFrameworkEvent(FrameworkEvent.ERROR, impl, th);
-                            m_logger.log(
+                            m_logger.log(impl,
                                 Logger.LOG_ERROR,
                                 "Error starting " + impl._getLocation(), th);
                         }
@@ -1174,7 +1174,7 @@
                         catch (Throwable th)
                         {
                             fireFrameworkEvent(FrameworkEvent.ERROR, impl, th);
-                            m_logger.log(
+                            m_logger.log(impl,
                                 Logger.LOG_ERROR,
                                 "Error stopping " + impl._getLocation(), th);
                         }
@@ -1289,7 +1289,7 @@
         catch (IllegalStateException ex)
         {
             fireFrameworkEvent(FrameworkEvent.ERROR, impl, ex);
-            m_logger.log(
+            m_logger.log(impl,
                 Logger.LOG_ERROR,
                 "Error locking " + impl._getLocation(), ex);
             return;
@@ -1330,12 +1330,16 @@
                 catch (Throwable th)
                 {
                     rethrow = th;
-                    m_logger.log(Logger.LOG_ERROR, "Error starting/stopping bundle.", th);
+                    m_logger.log(
+                        impl,
+                        Logger.LOG_ERROR, "Error starting/stopping bundle.", th);
                 }
             }
             else
             {
-                m_logger.log(Logger.LOG_WARNING, "Bundle start level must be greater than zero.");
+                m_logger.log(
+                    impl,
+                    Logger.LOG_WARNING, "Bundle start level must be greater than zero.");
             }
         }
         finally
@@ -1554,6 +1558,7 @@
             catch (Exception ex)
             {
                 m_logger.log(
+                    bundle,
                     Logger.LOG_WARNING,
                     "Exception while evaluating the permission.",
                     ex);
@@ -1988,7 +1993,8 @@
                     }
                     catch (Exception busted)
                     {
-                        m_logger.log(Logger.LOG_ERROR, "Unable to rollback.", busted);
+                        m_logger.log(
+                            bundle, Logger.LOG_ERROR, "Unable to rollback.", busted);
                     }
 
                     throw ex;
@@ -1996,7 +2002,8 @@
             }
             catch (Throwable ex)
             {
-                m_logger.log(Logger.LOG_ERROR, "Unable to update the bundle.", ex);
+                m_logger.log(
+                    bundle, Logger.LOG_ERROR, "Unable to update the bundle.", ex);
                 rethrow = ex;
             }
 
@@ -2035,7 +2042,7 @@
                             }
                             catch (Exception ex)
                             {
-                                m_logger.log(
+                                m_logger.log(bundle,
                                     Logger.LOG_ERROR,
                                     "Unable to immediately purge the bundle revisions.", ex);
                             }
@@ -2054,7 +2061,7 @@
             if ((oldState == Bundle.ACTIVE) && Util.isFragment(bundle.getCurrentModule()))
             {
                 bundle.setPersistentStateInactive();
-                m_logger.log(Logger.LOG_WARNING,
+                m_logger.log(bundle, Logger.LOG_WARNING,
                     "Previously active bundle was updated to a fragment, resetting state to inactive: "
                     + bundle);
             }
@@ -2092,7 +2099,7 @@
             }
             catch (Exception ex)
             {
-                m_logger.log(Logger.LOG_ERROR, "Unable to close input stream.", ex);
+                m_logger.log(bundle, Logger.LOG_ERROR, "Unable to close input stream.", ex);
             }
 
             // Release bundle lock.
@@ -2192,7 +2199,7 @@
                 }
                 catch (Throwable th)
                 {
-                    m_logger.log(Logger.LOG_ERROR, "Error stopping bundle.", th);
+                    m_logger.log(bundle, Logger.LOG_ERROR, "Error stopping bundle.", th);
                     rethrow = th;
                 }
             }
@@ -2335,7 +2342,7 @@
 
             if (target == null)
             {
-                m_logger.log(
+                m_logger.log(bundle,
                     Logger.LOG_ERROR, "Unable to remove bundle from installed map!");
             }
 
@@ -2378,7 +2385,7 @@
                     }
                     catch (Exception ex)
                     {
-                        m_logger.log(
+                        m_logger.log(bundle,
                             Logger.LOG_ERROR,
                             "Unable to immediately garbage collect the bundle.", ex);
                     }
@@ -2551,7 +2558,7 @@
                     }
                     catch (Exception ex1)
                     {
-                        m_logger.log(
+                        m_logger.log(bundle,
                             Logger.LOG_ERROR,
                             "Could not remove from cache.", ex1);
                     }
@@ -2622,7 +2629,7 @@
             }
             catch (IOException ex)
             {
-                m_logger.log(
+                m_logger.log(bundle,
                     Logger.LOG_ERROR,
                     "Unable to close input stream.", ex);
                 // Not much else we can do.
@@ -3032,7 +3039,7 @@
         }
         catch (Exception ex)
         {
-            m_logger.log(Logger.LOG_ERROR, ex.getMessage());
+            m_logger.log(bundle, Logger.LOG_ERROR, ex.getMessage());
             return null;
         }
     }
@@ -3379,7 +3386,7 @@
                 catch (BundleException ex)
                 {
                     result = false;
-                    m_logger.log(
+                    m_logger.log(targets[i],
                         Logger.LOG_WARNING,
                         "Unable to resolve bundle " + targets[i].getBundleId(),
                         ex);
@@ -4071,7 +4078,10 @@
                             wires.addAll(module.getWires());
                             wires.add(candidateWire);
                             ((ModuleImpl) module).setWires(wires);
-m_logger.log(Logger.LOG_DEBUG, "DYNAMIC WIRE: " + wires.get(wires.size() - 1));
+                            m_logger.log(
+                                module.getBundle(),
+                                Logger.LOG_DEBUG,
+                                "DYNAMIC WIRE: " + wires.get(wires.size() - 1));
                         }
                     }
                 }
@@ -4164,7 +4174,7 @@
                     // only modules may not have wires.
                     for (int wireIdx = 0; wireIdx < wires.size(); wireIdx++)
                     {
-                        m_logger.log(
+                        m_logger.log(module.getBundle(),
                             Logger.LOG_DEBUG,
                             "WIRE: " + wires.get(wireIdx));
                     }
@@ -4177,7 +4187,7 @@
                         ((ModuleImpl) fragments.get(i)).setResolved();
                         // Update the state of the module's bundle to resolved as well.
                         markBundleResolved(fragments.get(i));
-                        m_logger.log(
+                        m_logger.log(((ModuleImpl) fragments.get(i)).getBundle(),
                             Logger.LOG_DEBUG,
                             "FRAGMENT WIRE: " + fragments.get(i) + " -> hosted by -> " + module);
                     }
@@ -4215,7 +4225,7 @@
                 {
                     if (bundle.getState() != Bundle.INSTALLED)
                     {
-                        m_logger.log(
+                        m_logger.log(bundle,
                             Logger.LOG_WARNING,
                             "Received a resolve event for a bundle that has already been resolved.");
                     }
@@ -4330,7 +4340,7 @@
                     catch (Exception ex)
                     {
                         fireFrameworkEvent(FrameworkEvent.ERROR, bundle, ex);
-                        m_logger.log(Logger.LOG_ERROR, "Unable to purge bundle "
+                        m_logger.log(bundle, Logger.LOG_ERROR, "Unable to purge bundle "
                             + bundle._getLocation(), ex);
                     }
                 }
@@ -4347,7 +4357,7 @@
                 }
                 catch (Exception ex)
                 {
-                    m_logger.log(
+                    m_logger.log(m_uninstalledBundles.get(i),
                         Logger.LOG_ERROR,
                         "Unable to remove "
                         + m_uninstalledBundles.get(i)._getLocation(), ex);
@@ -4371,7 +4381,7 @@
                 }
                 catch (Throwable throwable)
                 {
-                    m_logger.log(
+                    m_logger.log(Felix.this,
                         Logger.LOG_WARNING,
                         "Exception stopping a system bundle activator.",
                         throwable);
diff --git a/framework/src/main/java/org/apache/felix/framework/FelixResolverState.java b/framework/src/main/java/org/apache/felix/framework/FelixResolverState.java
index d7b5854..534d56f 100644
--- a/framework/src/main/java/org/apache/felix/framework/FelixResolverState.java
+++ b/framework/src/main/java/org/apache/felix/framework/FelixResolverState.java
@@ -174,7 +174,7 @@
             {
                 // Ignore
             }
-            m_logger.log(Logger.LOG_ERROR,
+            m_logger.log(host.getBundle(), Logger.LOG_ERROR,
                 "Serious error attaching fragments.", ex);
         }
     }
@@ -301,7 +301,7 @@
                     {
                         // Ignore
                     }
-                    m_logger.log(Logger.LOG_ERROR,
+                    m_logger.log(host.getBundle(), Logger.LOG_ERROR,
                         "Serious error attaching fragments.", ex);
                 }
 
@@ -360,7 +360,7 @@
                         {
                             // Ignore
                         }
-                        m_logger.log(Logger.LOG_ERROR,
+                        m_logger.log(host.getBundle(), Logger.LOG_ERROR,
                             "Serious error attaching fragments.", ex);
                     }
 
@@ -499,7 +499,7 @@
                 {
                     // Ignore
                 }
-                m_logger.log(Logger.LOG_ERROR,
+                m_logger.log(host.getBundle(), Logger.LOG_ERROR,
                     "Serious error attaching fragments.", ex);
             }
         }
@@ -538,7 +538,8 @@
         }
         catch (Exception ex)
         {
-            m_logger.log(Logger.LOG_ERROR, "Error detaching fragments.", ex);
+            m_logger.log(
+                host.getBundle(), Logger.LOG_ERROR, "Error detaching fragments.", ex);
         }
         // Set wires to null, which will remove the module from all
         // of its dependent modules.
diff --git a/framework/src/main/java/org/apache/felix/framework/Logger.java b/framework/src/main/java/org/apache/felix/framework/Logger.java
index 2b343c0..031868b 100644
--- a/framework/src/main/java/org/apache/felix/framework/Logger.java
+++ b/framework/src/main/java/org/apache/felix/framework/Logger.java
@@ -86,27 +86,40 @@
 
     public final void log(int level, String msg)
     {
-        _log(null, level, msg, null);
+        _log(null, null, level, msg, null);
     }
 
     public final void log(int level, String msg, Throwable throwable)
     {
-        _log(null, level, msg, throwable);
+        _log(null, null, level, msg, throwable);
     }
 
     public final void log(ServiceReference sr, int level, String msg)
     {
-        _log(sr, level, msg, null);
+        _log(null, sr, level, msg, null);
     }
 
     public final void log(ServiceReference sr, int level, String msg, Throwable throwable)
     {
-        _log(sr, level, msg, throwable);
+        _log(null, sr, level, msg, throwable);
     }
 
-    protected void doLog(ServiceReference sr, int level, String msg, Throwable throwable)
+    public final void log(Bundle bundle, int level, String msg)
+    {
+        _log(bundle, null, level, msg, null);
+    }
+
+    public final void log(Bundle bundle, int level, String msg, Throwable throwable)
+    {
+        _log(bundle, null, level, msg, throwable);
+    }
+
+    protected void doLog(
+        Bundle bundle, ServiceReference sr, int level,
+        String msg, Throwable throwable)
     {
         String s = (sr == null) ? null : "SvcRef " + sr;
+        s = (s == null) ? null : s + " Bundle '" + bundle.getBundleId() + "'";
         s = (s == null) ? msg : s + " " + msg;
         s = (throwable == null) ? s : s + " (" + throwable + ")";
         switch (level)
@@ -137,7 +150,9 @@
         }
     }
 
-    private void _log(ServiceReference sr, int level, String msg, Throwable throwable)
+    private void _log(
+        Bundle bundle, ServiceReference sr, int level,
+        String msg, Throwable throwable)
     {
         // Save our own copy just in case it changes. We could try to do
         // more conservative locking here, but let's be optimistic.
@@ -153,7 +168,7 @@
             // Otherwise, default logging action.
             else
             {
-                doLog(sr, level, msg, throwable);
+                doLog(bundle, sr, level, msg, throwable);
             }
         }
     }
diff --git a/framework/src/main/java/org/apache/felix/framework/ModuleImpl.java b/framework/src/main/java/org/apache/felix/framework/ModuleImpl.java
index 209649d..8d5a173 100644
--- a/framework/src/main/java/org/apache/felix/framework/ModuleImpl.java
+++ b/framework/src/main/java/org/apache/felix/framework/ModuleImpl.java
@@ -523,7 +523,8 @@
             }
             catch (Exception ex)
             {
-                m_logger.log(Logger.LOG_ERROR, "Unable to get module class path.", ex);
+                m_logger.log(
+                    m_bundle, Logger.LOG_ERROR, "Unable to get module class path.", ex);
             }
         }
         return m_contentPath;
@@ -603,7 +604,7 @@
                 {
 // TODO: FRAMEWORK - Per the spec, this should fire a FrameworkEvent.INFO event;
 //       need to create an "Eventer" class like "Logger" perhaps.
-                    m_logger.log(Logger.LOG_INFO,
+                    m_logger.log(m_bundle, Logger.LOG_INFO,
                         "Class path entry not found: "
                         + classPathStrings.get(i));
                 }
@@ -646,7 +647,7 @@
         }
         catch (ResourceNotFoundException ex)
         {
-            m_logger.log(
+            m_logger.log(m_bundle,
                 Logger.LOG_DEBUG,
                 ex.getMessage());
         }
@@ -1107,7 +1108,7 @@
          }
          catch (MalformedURLException ex)
          {
-             m_logger.log(
+             m_logger.log(m_bundle,
                  Logger.LOG_ERROR,
                  "Unable to create resource URL.",
                  ex);
diff --git a/framework/src/main/java/org/apache/felix/framework/ServiceRegistrationImpl.java b/framework/src/main/java/org/apache/felix/framework/ServiceRegistrationImpl.java
index 198e546..f26f887 100644
--- a/framework/src/main/java/org/apache/felix/framework/ServiceRegistrationImpl.java
+++ b/framework/src/main/java/org/apache/felix/framework/ServiceRegistrationImpl.java
@@ -263,7 +263,10 @@
             catch (Exception ex)
             {
                 m_registry.getLogger().log(
-                    Logger.LOG_ERROR, "ServiceRegistrationImpl: Error ungetting service.", ex);
+                    m_bundle,
+                    Logger.LOG_ERROR,
+                    "ServiceRegistrationImpl: Error ungetting service.",
+                    ex);
             }
         }
     }
diff --git a/framework/src/main/java/org/apache/felix/framework/resolver/ResolverImpl.java b/framework/src/main/java/org/apache/felix/framework/resolver/ResolverImpl.java
index d98aa5a..7c8f505 100644
--- a/framework/src/main/java/org/apache/felix/framework/resolver/ResolverImpl.java
+++ b/framework/src/main/java/org/apache/felix/framework/resolver/ResolverImpl.java
@@ -36,6 +36,7 @@
 import org.apache.felix.framework.capabilityset.Requirement;
 import org.apache.felix.framework.util.Util;
 import org.apache.felix.framework.util.manifestparser.RequirementImpl;
+import org.osgi.framework.Bundle;
 import org.osgi.framework.Constants;
 
 public class ResolverImpl implements Resolver
@@ -109,6 +110,7 @@
                     {
                         rethrow = ex;
                         m_logger.log(
+                            module.getBundle(),
                             Logger.LOG_DEBUG,
                             "Current candidate permutation failed, will try another if possible.",
                             ex);
@@ -189,6 +191,7 @@
                     {
                         rethrow = ex;
                         m_logger.log(
+                            module.getBundle(),
                             Logger.LOG_DEBUG,
                             "Current candidate permutation failed, will try another if possible.",
                             ex);
@@ -456,7 +459,11 @@
                 }
                 rethrow = new ResolveException(msg, module, req);
                 resultCache.put(module, rethrow);
-                m_logger.log(Logger.LOG_DEBUG, "No viable candidates", rethrow);
+                m_logger.log(
+                    module.getBundle(),
+                    Logger.LOG_DEBUG,
+                    "No viable candidates",
+                    rethrow);
                 throw rethrow;
             }
             // If we actually have candidates for the requirement, then
@@ -897,7 +904,11 @@
                             + module + " between an import "
                             + sourceBlame + " and a fragment import "
                             + blame, module, blame.m_reqs.get(0));
-                        m_logger.log(Logger.LOG_DEBUG, "Conflicting fragment import", ex);
+                        m_logger.log(
+                            module.getBundle(),
+                            Logger.LOG_DEBUG,
+                            "Conflicting fragment import",
+                            ex);
                         throw ex;
                     }
                 }
@@ -969,7 +980,13 @@
                 {
                     m_usesPermutations.add(permutation);
                 }
-                m_logger.log(Logger.LOG_DEBUG, "Conflict between an export and import", rethrow);
+                Bundle bundle =
+                    (rethrow.getModule() != null) ? rethrow.getModule().getBundle() : null;
+                m_logger.log(
+                    bundle,
+                    Logger.LOG_DEBUG,
+                    "Conflict between an export and import",
+                    rethrow);
                 throw rethrow;
             }
         }
@@ -1062,7 +1079,14 @@
                         permutateIfNeeded(candidateMap, req, m_importPermutations);
                     }
 
-                    m_logger.log(Logger.LOG_DEBUG, "Conflict between imports", rethrow);
+                    Bundle bundle =
+                        (rethrow.getModule() != null)
+                            ? rethrow.getModule().getBundle() : null;
+                    m_logger.log(
+                        bundle,
+                        Logger.LOG_DEBUG,
+                        "Conflict between imports",
+                        rethrow);
                     throw rethrow;
                 }
             }
diff --git a/framework/src/main/java/org/apache/felix/framework/util/EventDispatcher.java b/framework/src/main/java/org/apache/felix/framework/util/EventDispatcher.java
index 2df2a79..190dfdd 100644
--- a/framework/src/main/java/org/apache/felix/framework/util/EventDispatcher.java
+++ b/framework/src/main/java/org/apache/felix/framework/util/EventDispatcher.java
@@ -735,7 +735,7 @@
                 }
                 catch (Throwable th)
                 {
-                    logger.log(
+                    logger.log(bundle,
                         Logger.LOG_ERROR,
                         "EventDispatcher: Error during dispatch.", th);
                 }
diff --git a/framework/src/main/java/org/apache/felix/framework/util/manifestparser/ManifestParser.java b/framework/src/main/java/org/apache/felix/framework/util/manifestparser/ManifestParser.java
index 59e72e1..5601754 100644
--- a/framework/src/main/java/org/apache/felix/framework/util/manifestparser/ManifestParser.java
+++ b/framework/src/main/java/org/apache/felix/framework/util/manifestparser/ManifestParser.java
@@ -1183,7 +1183,10 @@
             String s = (String) headerMap.get(Constants.BUNDLE_SYMBOLICNAME);
             s = (s == null) ? (String) headerMap.get(Constants.BUNDLE_NAME) : s;
             s = (s == null) ? headerMap.toString() : s;
-            logger.log(Logger.LOG_WARNING, "Only R4 bundles can be fragments: " + s);
+            logger.log(
+                owner.getBundle(),
+                Logger.LOG_WARNING,
+                "Only R4 bundles can be fragments: " + s);
         }
 
         return reqs;