Index: log4j-api/src/main/java/org/apache/logging/log4j/util/ProviderUtil.java =================================================================== --- log4j-api/src/main/java/org/apache/logging/log4j/util/ProviderUtil.java (revision 1517765) +++ log4j-api/src/main/java/org/apache/logging/log4j/util/ProviderUtil.java (working copy) @@ -25,9 +25,14 @@ import java.util.Properties; import org.apache.logging.log4j.Logger; +import org.apache.logging.log4j.spi.LoggerContextFactory; import org.apache.logging.log4j.spi.Provider; import org.apache.logging.log4j.status.StatusLogger; +import org.osgi.framework.Bundle; +import org.osgi.framework.FrameworkUtil; +import org.osgi.framework.wiring.BundleWiring; + /** * */ @@ -83,7 +88,11 @@ public static ClassLoader findClassLoader() { ClassLoader cl; - if (System.getSecurityManager() == null) { + Bundle bundle = FrameworkUtil.getBundle(LoggerContextFactory.class); + if(bundle != null) { + cl = bundle.adapt(BundleWiring.class).getClassLoader(); + } + else if (System.getSecurityManager() == null) { cl = Thread.currentThread().getContextClassLoader(); } else { cl = java.security.AccessController.doPrivileged( Index: log4j-api/pom.xml =================================================================== --- log4j-api/pom.xml (revision 1517765) +++ log4j-api/pom.xml (working copy) @@ -44,6 +44,18 @@ junit test + + org.osgi + org.osgi.compendium + 4.3.1 + compile + + + org.osgi + org.osgi.core + 5.0.0 + compile +