logging-log4j-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Roland Weiglhofer (JIRA)" <j...@apache.org>
Subject [jira] [Updated] (LOG4J2-373) Classloader issue in OSGi-environment
Date Tue, 27 Aug 2013 09:28:52 GMT

     [ https://issues.apache.org/jira/browse/LOG4J2-373?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
]

Roland Weiglhofer updated LOG4J2-373:
-------------------------------------

    Description: 
Using Log4j2 in a bundle causes following error:
ERROR StatusLogger org.apache.logging.log4j.core.impl.Log4jContextFactory does not implement
org.apache.logging.log4j.spi.LoggerContextFactory
ERROR StatusLogger Unable to locate a logging implementation, using SimpleLogger

printing the ClassLoaders in LogManager gives me following output:

org.apache.logging.log4j.spi.LoggerContextFactory loaded by org.apache.logging.log4j-api [13]
org.apache.logging.log4j.core.impl.Log4jContextFactory loaded by sun.misc.Launcher$AppClassLoader@35a16869

We have two different ClassLoaders. That's why the implementation is not assignable. The core
uses the bootstrap-classloader and the api uses the bundle-classloader.

Workaround needed. Thx

addendum:
ProviderUtil.findClassLoader() returns the bootstrap-classloader but not the bundle-classloader
of the log4j2-core. The log4j2-core is a fragment of the log4j2-api bundle. Thus, ProviderUtil.findClassLoader()
must return the bundle-classloader of log4j2-api. This a bug for the case that log4j2-core
is used as the implementation. There are other cases that will also cause problems. Further
investigations are necessary.

Workaround:
1. check if log4j2 runs in an OSGI container.
Bundle mybundle = org.osgi.framework.FrameworkUtil.getBundle(MyClass.this);
2. if(mybundle != null), than get bundle-classloader of log4j2-api.
mybundle.adapt(BundleWiring.class).getClassLoader();

  was:
Using Log4j2 in a bundle causes following error:
ERROR StatusLogger org.apache.logging.log4j.core.impl.Log4jContextFactory does not implement
org.apache.logging.log4j.spi.LoggerContextFactory
ERROR StatusLogger Unable to locate a logging implementation, using SimpleLogger

printing the ClassLoaders in LogManager gives me following output:

org.apache.logging.log4j.spi.LoggerContextFactory loaded by org.apache.logging.log4j-api [13]
org.apache.logging.log4j.core.impl.Log4jContextFactory loaded by sun.misc.Launcher$AppClassLoader@35a16869

We have two different ClassLoaders. That's why the implementation is not assignable. The core
uses the bootstrap-classloader and the api uses the bundle-classloader.

Workaround needed. Thx

addendum:
ProviderUtil.findClassLoader() returns the bootstrap-classloader but not the bundle-classloader
of the log4j2-core. The log4j2-core is a fragment of the log4j2-api bundle. Thus, ProviderUtil.findClassLoader()
must return the bundle-classloader of log4j2-api. This a bug for the case that log4j2-core
is used as the implementation. There are other cases that will also cause problems. Further
investigations are necessary.

Workaround:
1. check if log4j2 runs in an OSGI container.
Bundle mybundle = org.osgi.framework.FrameworkUtil.getBundle(MyClass.this);
2. if(mybundle != null), than get bundle-classloader of log4j2-implementation.
mybundle.adapt(BundleWiring.class).getClassLoader();

    
> Classloader issue in OSGi-environment
> -------------------------------------
>
>                 Key: LOG4J2-373
>                 URL: https://issues.apache.org/jira/browse/LOG4J2-373
>             Project: Log4j 2
>          Issue Type: Bug
>          Components: API, Core
>    Affects Versions: 2.0-beta9
>         Environment: OSGi R5 / R4 (Apache Felix 4.x)
>            Reporter: Roland Weiglhofer
>            Priority: Critical
>              Labels: ClassLoader, OSGI
>         Attachments: log4j-api.patch
>
>
> Using Log4j2 in a bundle causes following error:
> ERROR StatusLogger org.apache.logging.log4j.core.impl.Log4jContextFactory does not implement
org.apache.logging.log4j.spi.LoggerContextFactory
> ERROR StatusLogger Unable to locate a logging implementation, using SimpleLogger
> printing the ClassLoaders in LogManager gives me following output:
> org.apache.logging.log4j.spi.LoggerContextFactory loaded by org.apache.logging.log4j-api
[13]
> org.apache.logging.log4j.core.impl.Log4jContextFactory loaded by sun.misc.Launcher$AppClassLoader@35a16869
> We have two different ClassLoaders. That's why the implementation is not assignable.
The core uses the bootstrap-classloader and the api uses the bundle-classloader.
> Workaround needed. Thx
> addendum:
> ProviderUtil.findClassLoader() returns the bootstrap-classloader but not the bundle-classloader
of the log4j2-core. The log4j2-core is a fragment of the log4j2-api bundle. Thus, ProviderUtil.findClassLoader()
must return the bundle-classloader of log4j2-api. This a bug for the case that log4j2-core
is used as the implementation. There are other cases that will also cause problems. Further
investigations are necessary.
> Workaround:
> 1. check if log4j2 runs in an OSGI container.
> Bundle mybundle = org.osgi.framework.FrameworkUtil.getBundle(MyClass.this);
> 2. if(mybundle != null), than get bundle-classloader of log4j2-api.
> mybundle.adapt(BundleWiring.class).getClassLoader();

--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators
For more information on JIRA, see: http://www.atlassian.com/software/jira

---------------------------------------------------------------------
To unsubscribe, e-mail: log4j-dev-unsubscribe@logging.apache.org
For additional commands, e-mail: log4j-dev-help@logging.apache.org


Mime
View raw message