Discussion:
[jira] [Created] (LOG4J2-373) Classloader issue in OSGi-environment
Roland Weiglhofer (JIRA)
2013-08-27 07:19:53 UTC
Permalink
Roland Weiglhofer created LOG4J2-373:
----------------------------------------

Summary: 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


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$***@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

--
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
Roland Weiglhofer (JIRA)
2013-08-27 08:29:51 UTC
Permalink
[ 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$***@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.

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$***@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
Post by Roland Weiglhofer (JIRA)
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
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
org.apache.logging.log4j.spi.LoggerContextFactory loaded by org.apache.logging.log4j-api [13]
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
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.
--
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
Roland Weiglhofer (JIRA)
2013-08-27 08:39:51 UTC
Permalink
[ https://issues.apache.org/jira/browse/LOG4J2-373?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

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

Attachment: Bug.png
Post by Roland Weiglhofer (JIRA)
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: Bug.png
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
org.apache.logging.log4j.spi.LoggerContextFactory loaded by org.apache.logging.log4j-api [13]
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
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.
--
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
Roland Weiglhofer (JIRA)
2013-08-27 08:46:54 UTC
Permalink
[ 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$***@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();

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$***@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.
Post by Roland Weiglhofer (JIRA)
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: Bug.png
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
org.apache.logging.log4j.spi.LoggerContextFactory loaded by org.apache.logging.log4j-api [13]
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
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.
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();
--
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
Roland Weiglhofer (JIRA)
2013-08-27 08:48:52 UTC
Permalink
[ https://issues.apache.org/jira/browse/LOG4J2-373?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

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

Attachment: (was: Bug.png)
Post by Roland Weiglhofer (JIRA)
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
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
org.apache.logging.log4j.spi.LoggerContextFactory loaded by org.apache.logging.log4j-api [13]
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
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.
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();
--
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
Roland Weiglhofer (JIRA)
2013-08-27 09:28:52 UTC
Permalink
[ https://issues.apache.org/jira/browse/LOG4J2-373?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

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

Attachment: log4j-api.patch

works for me but is not fully tested.
Post by Roland Weiglhofer (JIRA)
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
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
org.apache.logging.log4j.spi.LoggerContextFactory loaded by org.apache.logging.log4j-api [13]
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
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.
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();
--
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
Roland Weiglhofer (JIRA)
2013-08-27 09:28:52 UTC
Permalink
[ 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$***@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$***@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();
Post by Roland Weiglhofer (JIRA)
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
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
org.apache.logging.log4j.spi.LoggerContextFactory loaded by org.apache.logging.log4j-api [13]
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
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.
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
Roland Weiglhofer (JIRA)
2013-08-27 09:30:51 UTC
Permalink
[ 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$***@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-impl.
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$***@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();
Post by Roland Weiglhofer (JIRA)
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
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
org.apache.logging.log4j.spi.LoggerContextFactory loaded by org.apache.logging.log4j-api [13]
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
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.
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-impl.
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
Patrice Chalin (JIRA)
2013-11-29 15:26:36 UTC
Permalink
[ https://issues.apache.org/jira/browse/LOG4J2-373?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13835421#comment-13835421 ]

Patrice Chalin commented on LOG4J2-373:
---------------------------------------

Thanks for the patch; it works for me as well.
Post by Roland Weiglhofer (JIRA)
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
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
org.apache.logging.log4j.spi.LoggerContextFactory loaded by org.apache.logging.log4j-api [13]
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
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.
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-impl.
mybundle.adapt(BundleWiring.class).getClassLoader();
--
This message was sent by Atlassian JIRA
(v6.1#6144)
NiK (JIRA)
2013-12-12 21:27:08 UTC
Permalink
[ https://issues.apache.org/jira/browse/LOG4J2-373?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13846754#comment-13846754 ]

NiK commented on LOG4J2-373:
----------------------------

Hi,
I also see the same errors on the console.

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

How can I download this patch & apply.

I am using 2.0-beta9 version.

<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-core</artifactId>
<version>${log4j.version}</version>
</dependency>

<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-api</artifactId>
<version>${log4j.version}</version>
</dependency>
Post by Roland Weiglhofer (JIRA)
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
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
org.apache.logging.log4j.spi.LoggerContextFactory loaded by org.apache.logging.log4j-api [13]
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
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.
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-impl.
mybundle.adapt(BundleWiring.class).getClassLoader();
--
This message was sent by Atlassian JIRA
(v6.1.4#6159)
NiK (JIRA)
2013-12-12 21:33:08 UTC
Permalink
[ https://issues.apache.org/jira/browse/LOG4J2-373?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13846754#comment-13846754 ]

NiK edited comment on LOG4J2-373 at 12/12/13 9:32 PM:
------------------------------------------------------

Hi,
I also see the same errors on the console.

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

How can I download this patch & apply? Your help is appreciated.

I am using 2.0-beta9 version.

<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-core</artifactId>
<version>${log4j.version}</version>
</dependency>

<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-api</artifactId>
<version>${log4j.version}</version>
</dependency>


was (Author: ***@acemetrix.com):
Hi,
I also see the same errors on the console.

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

How can I download this patch & apply.

I am using 2.0-beta9 version.

<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-core</artifactId>
<version>${log4j.version}</version>
</dependency>

<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-api</artifactId>
<version>${log4j.version}</version>
</dependency>
Post by Roland Weiglhofer (JIRA)
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
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
org.apache.logging.log4j.spi.LoggerContextFactory loaded by org.apache.logging.log4j-api [13]
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
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.
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-impl.
mybundle.adapt(BundleWiring.class).getClassLoader();
--
This message was sent by Atlassian JIRA
(v6.1.4#6159)
Matt Sicker (JIRA)
2014-01-05 18:49:50 UTC
Permalink
[ https://issues.apache.org/jira/browse/LOG4J2-373?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13862627#comment-13862627 ]

Matt Sicker commented on LOG4J2-373:
------------------------------------

To apply the patch, download the source zip or tar.gz, download the patch file, then run {{patch -p1 < log4j-api.patch}} inside the source directory. Then you can run {{mvn install}} as per usual to put it in your local {{~/.m2/}} repository. Or if you've got your own internal Nexus, you can use the deploy target with your own profile (I'm not sure on the details; I'm more of a gradle guy myself).
Post by Roland Weiglhofer (JIRA)
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
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
org.apache.logging.log4j.spi.LoggerContextFactory loaded by org.apache.logging.log4j-api [13]
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
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.
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-impl.
mybundle.adapt(BundleWiring.class).getClassLoader();
--
This message was sent by Atlassian JIRA
(v6.1.5#6160)
Remko Popma (JIRA)
2014-01-06 04:45:56 UTC
Permalink
[ https://issues.apache.org/jira/browse/LOG4J2-373?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13862761#comment-13862761 ]

Remko Popma commented on LOG4J2-373:
------------------------------------

At the moment log4j2 users need at least log4j-api and log4j-core.

If I understand correctly, this patch would introduce dependencies from log4j-api to org.osgi.compendium and org.osgi.core. Does that mean that all log4j2 users would need to have these 2 jars in the classpath in order to use log4j2? I would prefer a solution that does not introduce such a dependency for non-OSGi users of log4j2.
Post by Roland Weiglhofer (JIRA)
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
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
org.apache.logging.log4j.spi.LoggerContextFactory loaded by org.apache.logging.log4j-api [13]
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
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.
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-impl.
mybundle.adapt(BundleWiring.class).getClassLoader();
--
This message was sent by Atlassian JIRA
(v6.1.5#6160)
Matt Sicker (JIRA)
2014-01-26 01:28:38 UTC
Permalink
[ https://issues.apache.org/jira/browse/LOG4J2-373?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13882132#comment-13882132 ]

Matt Sicker commented on LOG4J2-373:
------------------------------------

Shouldn't you be loading core as a bundle too?
Post by Roland Weiglhofer (JIRA)
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
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
org.apache.logging.log4j.spi.LoggerContextFactory loaded by org.apache.logging.log4j-api [13]
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
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.
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-impl.
mybundle.adapt(BundleWiring.class).getClassLoader();
--
This message was sent by Atlassian JIRA
(v6.1.5#6160)
Ralph Goers (JIRA)
2014-01-26 09:09:39 UTC
Permalink
[ https://issues.apache.org/jira/browse/LOG4J2-373?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13882238#comment-13882238 ]

Ralph Goers commented on LOG4J2-373:
------------------------------------

In core the osgi core jar is marked as provided since it would be expected to already be present in an OSGi environment. I would expect the same should be done for these dependencies. However, in core that code path will only execute if a bundleresource url is encountered. In this case it seems like it will invoke the OSGi framework for everything which clearly isn't OK. The patch should be reworked to detect if an OSGi environment is present (i.e. - detect if the FrameworkUtil class is present) before attempting to call it.
Post by Roland Weiglhofer (JIRA)
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
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
org.apache.logging.log4j.spi.LoggerContextFactory loaded by org.apache.logging.log4j-api [13]
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
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.
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-impl.
mybundle.adapt(BundleWiring.class).getClassLoader();
--
This message was sent by Atlassian JIRA
(v6.1.5#6160)
Matt Sicker (JIRA)
2014-01-26 20:39:40 UTC
Permalink
[ https://issues.apache.org/jira/browse/LOG4J2-373?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13882421#comment-13882421 ]

Matt Sicker commented on LOG4J2-373:
------------------------------------

I meant log4j-core, not osgi.
Post by Roland Weiglhofer (JIRA)
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
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
org.apache.logging.log4j.spi.LoggerContextFactory loaded by org.apache.logging.log4j-api [13]
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
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.
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-impl.
mybundle.adapt(BundleWiring.class).getClassLoader();
--
This message was sent by Atlassian JIRA
(v6.1.5#6160)
Matt Sicker (JIRA)
2014-02-02 22:30:10 UTC
Permalink
[ https://issues.apache.org/jira/browse/LOG4J2-373?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13889088#comment-13889088 ]

Matt Sicker commented on LOG4J2-373:
------------------------------------

Shouldn't you be loading the bundles like so: log4j-api is the host bundle, and then use the OSGi bundles from there. Log4j-api should be using its own class loader in this case.

I've got some ideas on how to approach this in an API modification, but I'll have to flesh them out first.
Post by Roland Weiglhofer (JIRA)
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
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
org.apache.logging.log4j.spi.LoggerContextFactory loaded by org.apache.logging.log4j-api [13]
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
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.
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-impl.
mybundle.adapt(BundleWiring.class).getClassLoader();
--
This message was sent by Atlassian JIRA
(v6.1.5#6160)
Norval Hope (JIRA)
2014-02-06 04:54:12 UTC
Permalink
[ https://issues.apache.org/jira/browse/LOG4J2-373?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13893035#comment-13893035 ]

Norval Hope commented on LOG4J2-373:
------------------------------------

Just wanted to add a note that this is not purely an OSGi issue and also broke unit tests we were running using the maven surefire plugin. Given this is probably a pretty common use case you make want to consider including the patch in your next rc / release.

Thanks
Post by Roland Weiglhofer (JIRA)
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
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
org.apache.logging.log4j.spi.LoggerContextFactory loaded by org.apache.logging.log4j-api [13]
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
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.
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-impl.
mybundle.adapt(BundleWiring.class).getClassLoader();
--
This message was sent by Atlassian JIRA
(v6.1.5#6160)
Remko Popma (JIRA)
2014-02-06 06:50:11 UTC
Permalink
[ https://issues.apache.org/jira/browse/LOG4J2-373?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13893107#comment-13893107 ]

Remko Popma commented on LOG4J2-373:
------------------------------------

Norval, it may be a good idea to raise the problem you are experiencing in a separate Jira ticket and link to this ticket.

That way you can provide more detail about the problem you are seeing (stack trace, perhaps source code for a failing unit test or some other way for us to reproduce the issue) by attaching to that ticket.

It is possible that the underlying cause is the same but it is difficult to tell at the moment.
Post by Roland Weiglhofer (JIRA)
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
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
org.apache.logging.log4j.spi.LoggerContextFactory loaded by org.apache.logging.log4j-api [13]
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
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.
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-impl.
mybundle.adapt(BundleWiring.class).getClassLoader();
--
This message was sent by Atlassian JIRA
(v6.1.5#6160)
Remko Popma (JIRA)
2014-02-06 06:58:10 UTC
Permalink
[ https://issues.apache.org/jira/browse/LOG4J2-373?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13893107#comment-13893107 ]

Remko Popma edited comment on LOG4J2-373 at 2/6/14 6:56 AM:
------------------------------------------------------------

Norval, it may be a good idea to raise the problem you are experiencing in a separate Jira ticket and link to this ticket.

That way you can provide more detail about the problem you are seeing (stack trace, perhaps source code for a failing unit test or some other way for us to reproduce the issue) by attaching to that ticket.

It is possible that the underlying cause is the same but it is difficult to tell at the moment.

EDIT:
Or did you mean that you have a unit test that fails with trunk but passes after applying the patch that is attached to this Jira? I think that would be useful!


was (Author: ***@yahoo.com):
Norval, it may be a good idea to raise the problem you are experiencing in a separate Jira ticket and link to this ticket.

That way you can provide more detail about the problem you are seeing (stack trace, perhaps source code for a failing unit test or some other way for us to reproduce the issue) by attaching to that ticket.

It is possible that the underlying cause is the same but it is difficult to tell at the moment.
Post by Roland Weiglhofer (JIRA)
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
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
org.apache.logging.log4j.spi.LoggerContextFactory loaded by org.apache.logging.log4j-api [13]
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
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.
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-impl.
mybundle.adapt(BundleWiring.class).getClassLoader();
--
This message was sent by Atlassian JIRA
(v6.1.5#6160)
Matt Sicker (JIRA)
2014-02-06 22:07:27 UTC
Permalink
[ https://issues.apache.org/jira/browse/LOG4J2-373?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13893877#comment-13893877 ]

Matt Sicker commented on LOG4J2-373:
------------------------------------

The patch provided is not realistic since it adds OSGi dependencies to the API. I have a better solution that involves pulling out the static initialization in LogManager into its own class. That way, the OSGi bundles can register the correct class loader when they get loaded.
Post by Roland Weiglhofer (JIRA)
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
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
org.apache.logging.log4j.spi.LoggerContextFactory loaded by org.apache.logging.log4j-api [13]
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
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.
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-impl.
mybundle.adapt(BundleWiring.class).getClassLoader();
--
This message was sent by Atlassian JIRA
(v6.1.5#6160)
Remko Popma (JIRA)
2014-02-17 14:56:22 UTC
Permalink
[ https://issues.apache.org/jira/browse/LOG4J2-373?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13903291#comment-13903291 ]

Remko Popma commented on LOG4J2-373:
------------------------------------

Matt, you mentioned that what you have in mind may require API changes.

I think previously we were thinking to work on OSGi after the 2.0 GA release, but if proper OSGi support requires API changes then perhaps we should make these changes _before_ the 2.0 GA release.

Could you clarify what you have in mind for the API changes you mentioned, or perhaps provide a patch?
Post by Roland Weiglhofer (JIRA)
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
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
org.apache.logging.log4j.spi.LoggerContextFactory loaded by org.apache.logging.log4j-api [13]
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
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.
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-impl.
mybundle.adapt(BundleWiring.class).getClassLoader();
--
This message was sent by Atlassian JIRA
(v6.1.5#6160)
Matt Sicker (JIRA)
2014-02-18 04:27:23 UTC
Permalink
[ https://issues.apache.org/jira/browse/LOG4J2-373?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13903770#comment-13903770 ]

Matt Sicker commented on LOG4J2-373:
------------------------------------

Oh wow, never mind. I found a super simple fix for this. The API change that I mean is an OSGi API change. It would be preferable to have them match with the project version to some degree. There may be a need to automate an API change analyzer to enforce proper version numbering in the bundle.
Post by Roland Weiglhofer (JIRA)
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: 0001-Fix-OSGi-bundle-inheritance-problem.patch, log4j-api.patch
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
org.apache.logging.log4j.spi.LoggerContextFactory loaded by org.apache.logging.log4j-api [13]
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
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.
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-impl.
mybundle.adapt(BundleWiring.class).getClassLoader();
--
This message was sent by Atlassian JIRA
(v6.1.5#6160)
Matt Sicker (JIRA)
2014-02-18 04:27:23 UTC
Permalink
[ https://issues.apache.org/jira/browse/LOG4J2-373?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Matt Sicker updated LOG4J2-373:
-------------------------------

Attachment: 0001-Fix-OSGi-bundle-inheritance-problem.patch
Post by Roland Weiglhofer (JIRA)
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: 0001-Fix-OSGi-bundle-inheritance-problem.patch, log4j-api.patch
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
org.apache.logging.log4j.spi.LoggerContextFactory loaded by org.apache.logging.log4j-api [13]
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
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.
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-impl.
mybundle.adapt(BundleWiring.class).getClassLoader();
--
This message was sent by Atlassian JIRA
(v6.1.5#6160)
Matt Sicker (JIRA)
2014-02-18 04:29:20 UTC
Permalink
[ https://issues.apache.org/jira/browse/LOG4J2-373?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Matt Sicker updated LOG4J2-373:
-------------------------------

Attachment: (was: 0001-Fix-OSGi-bundle-inheritance-problem.patch)
Post by Roland Weiglhofer (JIRA)
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
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
org.apache.logging.log4j.spi.LoggerContextFactory loaded by org.apache.logging.log4j-api [13]
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
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.
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-impl.
mybundle.adapt(BundleWiring.class).getClassLoader();
--
This message was sent by Atlassian JIRA
(v6.1.5#6160)
Matt Sicker (JIRA)
2014-02-18 04:29:22 UTC
Permalink
[ https://issues.apache.org/jira/browse/LOG4J2-373?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13903772#comment-13903772 ]

Matt Sicker commented on LOG4J2-373:
------------------------------------

Wait, scratch that, the core-reduced bundle shouldn't be the one exporting the log4j API. Let me rework that a little bit.
Post by Roland Weiglhofer (JIRA)
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
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
org.apache.logging.log4j.spi.LoggerContextFactory loaded by org.apache.logging.log4j-api [13]
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
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.
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-impl.
mybundle.adapt(BundleWiring.class).getClassLoader();
--
This message was sent by Atlassian JIRA
(v6.1.5#6160)
Matt Sicker (JIRA)
2014-02-18 05:22:22 UTC
Permalink
[ https://issues.apache.org/jira/browse/LOG4J2-373?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13903792#comment-13903792 ]

Matt Sicker commented on LOG4J2-373:
------------------------------------

I'm looking into this bug right now. In the meantime, let me clarify that most of the API changes that would be useful for bundles would be focused in the log4j-core package structure. If that API can change in 2.x version upgrades, then that won't be a problem. We'd be able to get a nice modular OSGi version of core to really make it useful. This might also offer an alternative to the "fat" JARs like log4j-core.
Post by Roland Weiglhofer (JIRA)
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
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
org.apache.logging.log4j.spi.LoggerContextFactory loaded by org.apache.logging.log4j-api [13]
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
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.
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-impl.
mybundle.adapt(BundleWiring.class).getClassLoader();
--
This message was sent by Atlassian JIRA
(v6.1.5#6160)
Remko Popma (JIRA)
2014-02-18 06:35:20 UTC
Permalink
[ https://issues.apache.org/jira/browse/LOG4J2-373?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13903823#comment-13903823 ]

Remko Popma commented on LOG4J2-373:
------------------------------------

I see. Personally, if changes to log4j-core are necessary, I would prefer to make them before the 2.0 GA release.

Are you suggesting to split up the log4j-core jar? Hopefully that would only result in many small jars for OSGi users, and non-OSGi users can continue to use the single log4j-core jar that exists currently, does that match what you have in mind?
Post by Roland Weiglhofer (JIRA)
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
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
org.apache.logging.log4j.spi.LoggerContextFactory loaded by org.apache.logging.log4j-api [13]
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
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.
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-impl.
mybundle.adapt(BundleWiring.class).getClassLoader();
--
This message was sent by Atlassian JIRA
(v6.1.5#6160)
Christophe Bordier (JIRA)
2014-02-26 15:09:20 UTC
Permalink
[ https://issues.apache.org/jira/browse/LOG4J2-373?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13912997#comment-13912997 ]

Christophe Bordier commented on LOG4J2-373:
-------------------------------------------

I'm surprised that nobody uploaded a correct jar with the patch applied. Here it is. I called it "RC 2" but please note that this is NOT an official release ! https://drive.google.com/file/d/0B-wGewYKm47hRjA4U2E1eFA2Q2s/edit?usp=sharing
Post by Roland Weiglhofer (JIRA)
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
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
org.apache.logging.log4j.spi.LoggerContextFactory loaded by org.apache.logging.log4j-api [13]
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
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.
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-impl.
mybundle.adapt(BundleWiring.class).getClassLoader();
--
This message was sent by Atlassian JIRA
(v6.1.5#6160)
Matt Sicker (JIRA)
2014-04-27 20:17:16 UTC
Permalink
[ https://issues.apache.org/jira/browse/LOG4J2-373?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13982452#comment-13982452 ]

Matt Sicker commented on LOG4J2-373:
------------------------------------

This issue may be solved with the recent OSGi updates. I'll follow up later with the results of my own testing, but in theory, this should work now.
Post by Roland Weiglhofer (JIRA)
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
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
org.apache.logging.log4j.spi.LoggerContextFactory loaded by org.apache.logging.log4j-api [13]
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
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.
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-impl.
mybundle.adapt(BundleWiring.class).getClassLoader();
--
This message was sent by Atlassian JIRA
(v6.2#6252)
Matt Sicker (JIRA)
2014-07-20 02:18:38 UTC
Permalink
[ https://issues.apache.org/jira/browse/LOG4J2-373?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Matt Sicker resolved LOG4J2-373.
--------------------------------

Resolution: Fixed
Fix Version/s: 2.0.1
Assignee: Matt Sicker

Fixed in revision 1612002. Please verify and close.
Post by Roland Weiglhofer (JIRA)
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
Assignee: Matt Sicker
Priority: Critical
Labels: ClassLoader, OSGI
Fix For: 2.0.1
Attachments: log4j-api.patch
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
org.apache.logging.log4j.spi.LoggerContextFactory loaded by org.apache.logging.log4j-api [13]
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
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.
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-impl.
mybundle.adapt(BundleWiring.class).getClassLoader();
--
This message was sent by Atlassian JIRA
(v6.2#6252)
Snehadeep Sethia (JIRA)
2014-09-04 21:33:25 UTC
Permalink
[ https://issues.apache.org/jira/browse/LOG4J2-373?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=14122001#comment-14122001 ]

Snehadeep Sethia commented on LOG4J2-373:
-----------------------------------------

I'm get the following message on an OSGi project. "ERROR StatusLogger Log4j2 could not find a logging implementation. Please add log4j-core to the classpath. Using SimpleLogger to log to the console...", I'm using log4j-api v2.0.2 and log4j-core v2.0.2; The logger works very well on a stand alone java project but fails on an eclipse project. Any pointers?
Post by Roland Weiglhofer (JIRA)
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
Assignee: Matt Sicker
Priority: Critical
Labels: ClassLoader, OSGI
Fix For: 2.0.1
Attachments: log4j-api.patch
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
org.apache.logging.log4j.spi.LoggerContextFactory loaded by org.apache.logging.log4j-api [13]
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
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.
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-impl.
mybundle.adapt(BundleWiring.class).getClassLoader();
--
This message was sent by Atlassian JIRA
(v6.3.4#6332)
Matt Sicker (JIRA)
2014-09-05 02:53:27 UTC
Permalink
[ https://issues.apache.org/jira/browse/LOG4J2-373?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=14122318#comment-14122318 ]

Matt Sicker commented on LOG4J2-373:
------------------------------------

I think I found a race condition between the bundle activator and LogManager. I've fixed this in the master branch. Could you try out the latest git version?
Post by Roland Weiglhofer (JIRA)
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
Assignee: Matt Sicker
Priority: Critical
Labels: ClassLoader, OSGI
Fix For: 2.0.1
Attachments: log4j-api.patch
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
org.apache.logging.log4j.spi.LoggerContextFactory loaded by org.apache.logging.log4j-api [13]
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
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.
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-impl.
mybundle.adapt(BundleWiring.class).getClassLoader();
--
This message was sent by Atlassian JIRA
(v6.3.4#6332)
Snehadeep Sethia (JIRA)
2014-09-05 13:14:29 UTC
Permalink
[ https://issues.apache.org/jira/browse/LOG4J2-373?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=14122911#comment-14122911 ]

Snehadeep Sethia commented on LOG4J2-373:
-----------------------------------------

I get Compilation errors on the log4j-api project

[ERROR] COMPILATION ERROR :
[INFO] -------------------------------------------------------------
[ERROR] c:\Users\SD\Desktop\log4j master\logging-log4j2\log4j-api\src\test\java\org\apache\logging\log4j\message\LocalizedMessageTest.java:[36,45] type parameters of <T>T cannot be determi
ned; no unique maximal instance exists for type variable T with upper bounds T,java.lang.Object
[INFO] 1 error

I checked out master from here https://github.com/apache/logging-log4j2.git

[~jvz] I see the pom version as 2.1-SNAPSHOT, did you fix it on 2.0.1 or 2.0.2?
Post by Roland Weiglhofer (JIRA)
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
Assignee: Matt Sicker
Priority: Critical
Labels: ClassLoader, OSGI
Fix For: 2.0.1
Attachments: log4j-api.patch
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
org.apache.logging.log4j.spi.LoggerContextFactory loaded by org.apache.logging.log4j-api [13]
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
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.
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-impl.
mybundle.adapt(BundleWiring.class).getClassLoader();
--
This message was sent by Atlassian JIRA
(v6.3.4#6332)
Snehadeep Sethia (JIRA)
2014-09-05 13:42:28 UTC
Permalink
[ https://issues.apache.org/jira/browse/LOG4J2-373?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=14122911#comment-14122911 ]

Snehadeep Sethia edited comment on LOG4J2-373 at 9/5/14 1:41 PM:
-----------------------------------------------------------------

I get Compilation errors on the log4j-api project

[ERROR] COMPILATION ERROR :
[INFO] -------------------------------------------------------------
[ERROR] c:\Users\SD\Desktop\log4j master\logging-log4j2\log4j-api\src\test\java\org\apache\logging\log4j\message\LocalizedMessageTest.java:[36,45] type parameters of <T>T cannot be determi
ned; no unique maximal instance exists for type variable T with upper bounds T,java.lang.Object
[INFO] 1 error

for the time being I've commented the test and proceed with mvn clean install on the project.
I checked out master from here https://github.com/apache/logging-log4j2.git

I still don't see the issue being resolved. I still get the same error (I verified that the jars in the class path were log4j-api-2.1-SNAPSHOT and log4j-core-2.1-SNAPSHOT)
[~jvz] I see the pom version as 2.1-SNAPSHOT, did you fix it on 2.0.1 or 2.0.2?


was (Author: ssethia):
I get Compilation errors on the log4j-api project

[ERROR] COMPILATION ERROR :
[INFO] -------------------------------------------------------------
[ERROR] c:\Users\SD\Desktop\log4j master\logging-log4j2\log4j-api\src\test\java\org\apache\logging\log4j\message\LocalizedMessageTest.java:[36,45] type parameters of <T>T cannot be determi
ned; no unique maximal instance exists for type variable T with upper bounds T,java.lang.Object
[INFO] 1 error

I checked out master from here https://github.com/apache/logging-log4j2.git

[~jvz] I see the pom version as 2.1-SNAPSHOT, did you fix it on 2.0.1 or 2.0.2?
Post by Roland Weiglhofer (JIRA)
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
Assignee: Matt Sicker
Priority: Critical
Labels: ClassLoader, OSGI
Fix For: 2.0.1
Attachments: log4j-api.patch
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
org.apache.logging.log4j.spi.LoggerContextFactory loaded by org.apache.logging.log4j-api [13]
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
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.
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-impl.
mybundle.adapt(BundleWiring.class).getClassLoader();
--
This message was sent by Atlassian JIRA
(v6.3.4#6332)
Matt Sicker (JIRA)
2014-09-05 16:38:29 UTC
Permalink
[ https://issues.apache.org/jira/browse/LOG4J2-373?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=14123125#comment-14123125 ]

Matt Sicker commented on LOG4J2-373:
------------------------------------

The race condition part was fixed in 2.1-SNAPSHOT. The general ClassLoader issue was fixed in 2.0.1 to some extent. There's still probably more issues to work out, but the main showstoppers seem to be all fixed.
Post by Roland Weiglhofer (JIRA)
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
Assignee: Matt Sicker
Priority: Critical
Labels: ClassLoader, OSGI
Fix For: 2.0.1
Attachments: log4j-api.patch
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
org.apache.logging.log4j.spi.LoggerContextFactory loaded by org.apache.logging.log4j-api [13]
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
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.
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-impl.
mybundle.adapt(BundleWiring.class).getClassLoader();
--
This message was sent by Atlassian JIRA
(v6.3.4#6332)
Gary Gregory (JIRA)
2014-09-05 16:35:28 UTC
Permalink
[ https://issues.apache.org/jira/browse/LOG4J2-373?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=14123120#comment-14123120 ]

Gary Gregory commented on LOG4J2-373:
-------------------------------------

Make sure you have the latest Java 6 JDK (or Java 7)

Gary
Post by Roland Weiglhofer (JIRA)
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
Assignee: Matt Sicker
Priority: Critical
Labels: ClassLoader, OSGI
Fix For: 2.0.1
Attachments: log4j-api.patch
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
org.apache.logging.log4j.spi.LoggerContextFactory loaded by org.apache.logging.log4j-api [13]
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
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.
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-impl.
mybundle.adapt(BundleWiring.class).getClassLoader();
--
This message was sent by Atlassian JIRA
(v6.3.4#6332)
Snehadeep Sethia (JIRA)
2014-09-05 17:25:28 UTC
Permalink
[ https://issues.apache.org/jira/browse/LOG4J2-373?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=14123191#comment-14123191 ]

Snehadeep Sethia commented on LOG4J2-373:
-----------------------------------------

I'm on Java6u45, I built the 2.1-SNAPSHOT and still see the same issue on all 3 versions (2.1-SNAPSHOT, 2.0.1 and 2.0.2)
Post by Roland Weiglhofer (JIRA)
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
Assignee: Matt Sicker
Priority: Critical
Labels: ClassLoader, OSGI
Fix For: 2.0.1
Attachments: log4j-api.patch
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
org.apache.logging.log4j.spi.LoggerContextFactory loaded by org.apache.logging.log4j-api [13]
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
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.
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-impl.
mybundle.adapt(BundleWiring.class).getClassLoader();
--
This message was sent by Atlassian JIRA
(v6.3.4#6332)
Snehadeep Sethia (JIRA)
2014-09-05 17:33:29 UTC
Permalink
[ https://issues.apache.org/jira/browse/LOG4J2-373?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=14123191#comment-14123191 ]

Snehadeep Sethia edited comment on LOG4J2-373 at 9/5/14 5:32 PM:
-----------------------------------------------------------------

I'm on Java6u45, I built the 2.1-SNAPSHOT and still see the same issue on all 3 versions (2.1-SNAPSHOT, 2.0.1 and 2.0.2).

Should the manifest have something specific that I'm missing? Can you point me to a sample plugin project that seems to work for you [~jvz].


was (Author: ssethia):
I'm on Java6u45, I built the 2.1-SNAPSHOT and still see the same issue on all 3 versions (2.1-SNAPSHOT, 2.0.1 and 2.0.2)
Post by Roland Weiglhofer (JIRA)
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
Assignee: Matt Sicker
Priority: Critical
Labels: ClassLoader, OSGI
Fix For: 2.0.1
Attachments: log4j-api.patch
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
org.apache.logging.log4j.spi.LoggerContextFactory loaded by org.apache.logging.log4j-api [13]
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
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.
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-impl.
mybundle.adapt(BundleWiring.class).getClassLoader();
--
This message was sent by Atlassian JIRA
(v6.3.4#6332)
Matt Sicker (JIRA)
2014-09-05 17:35:29 UTC
Permalink
[ https://issues.apache.org/jira/browse/LOG4J2-373?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=14123207#comment-14123207 ]

Matt Sicker commented on LOG4J2-373:
------------------------------------

Are you using any custom plugins? Or is this purely log4j-api and log4j-core?
Post by Roland Weiglhofer (JIRA)
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
Assignee: Matt Sicker
Priority: Critical
Labels: ClassLoader, OSGI
Fix For: 2.0.1
Attachments: log4j-api.patch
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
org.apache.logging.log4j.spi.LoggerContextFactory loaded by org.apache.logging.log4j-api [13]
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
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.
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-impl.
mybundle.adapt(BundleWiring.class).getClassLoader();
--
This message was sent by Atlassian JIRA
(v6.3.4#6332)
Snehadeep Sethia (JIRA)
2014-09-05 17:37:29 UTC
Permalink
[ https://issues.apache.org/jira/browse/LOG4J2-373?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=14123212#comment-14123212 ]

Snehadeep Sethia commented on LOG4J2-373:
-----------------------------------------

The plugin has a few other dependencies including junit and powermock.
Post by Roland Weiglhofer (JIRA)
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
Assignee: Matt Sicker
Priority: Critical
Labels: ClassLoader, OSGI
Fix For: 2.0.1
Attachments: log4j-api.patch
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
org.apache.logging.log4j.spi.LoggerContextFactory loaded by org.apache.logging.log4j-api [13]
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
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.
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-impl.
mybundle.adapt(BundleWiring.class).getClassLoader();
--
This message was sent by Atlassian JIRA
(v6.3.4#6332)
Snehadeep Sethia (JIRA)
2014-09-05 17:38:28 UTC
Permalink
[ https://issues.apache.org/jira/browse/LOG4J2-373?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=14123212#comment-14123212 ]

Snehadeep Sethia edited comment on LOG4J2-373 at 9/5/14 5:38 PM:
-----------------------------------------------------------------

The plugin has a few other dependencies including junit and powermock. The product has a lot of custom plugins.


was (Author: ssethia):
The plugin has a few other dependencies including junit and powermock.
Post by Roland Weiglhofer (JIRA)
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
Assignee: Matt Sicker
Priority: Critical
Labels: ClassLoader, OSGI
Fix For: 2.0.1
Attachments: log4j-api.patch
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
org.apache.logging.log4j.spi.LoggerContextFactory loaded by org.apache.logging.log4j-api [13]
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
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.
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-impl.
mybundle.adapt(BundleWiring.class).getClassLoader();
--
This message was sent by Atlassian JIRA
(v6.3.4#6332)
Matt Sicker (JIRA)
2014-09-05 17:40:30 UTC
Permalink
[ https://issues.apache.org/jira/browse/LOG4J2-373?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=14123216#comment-14123216 ]

Matt Sicker commented on LOG4J2-373:
------------------------------------

I mean custom Log4j plugins.
Post by Roland Weiglhofer (JIRA)
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
Assignee: Matt Sicker
Priority: Critical
Labels: ClassLoader, OSGI
Fix For: 2.0.1
Attachments: log4j-api.patch
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
org.apache.logging.log4j.spi.LoggerContextFactory loaded by org.apache.logging.log4j-api [13]
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
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.
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-impl.
mybundle.adapt(BundleWiring.class).getClassLoader();
--
This message was sent by Atlassian JIRA
(v6.3.4#6332)
Snehadeep Sethia (JIRA)
2014-09-05 17:42:29 UTC
Permalink
[ https://issues.apache.org/jira/browse/LOG4J2-373?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=14123222#comment-14123222 ]

Snehadeep Sethia commented on LOG4J2-373:
-----------------------------------------

none except log4j-api and log4j-core
Post by Roland Weiglhofer (JIRA)
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
Assignee: Matt Sicker
Priority: Critical
Labels: ClassLoader, OSGI
Fix For: 2.0.1
Attachments: log4j-api.patch
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
org.apache.logging.log4j.spi.LoggerContextFactory loaded by org.apache.logging.log4j-api [13]
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
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.
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-impl.
mybundle.adapt(BundleWiring.class).getClassLoader();
--
This message was sent by Atlassian JIRA
(v6.3.4#6332)
Gary Gregory (JIRA)
2014-09-05 17:42:30 UTC
Permalink
[ https://issues.apache.org/jira/browse/LOG4J2-373?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=14123224#comment-14123224 ]

Gary Gregory commented on LOG4J2-373:
-------------------------------------

I am sorry you are having trouble.

Here, I was able to run {{mvn clean compile}} OK using:

{noformat}
mvn -version

Apache Maven 3.2.3 (33f8c3e1027c3ddde99d3cdebad2656a31e8fdf4; 2014-08-11T16:58:10-04:00)
Maven home: C:\Java\apache-maven-3.2.3
Java version: 1.6.0_45, vendor: Sun Microsystems Inc.
Java home: C:\Program Files\Java\jdk1.6.0_45\jre
Default locale: en_US, platform encoding: Cp1252
OS name: "windows 7", version: "6.1", arch: "amd64", family: "windows"
{noformat}
Post by Roland Weiglhofer (JIRA)
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
Assignee: Matt Sicker
Priority: Critical
Labels: ClassLoader, OSGI
Fix For: 2.0.1
Attachments: log4j-api.patch
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
org.apache.logging.log4j.spi.LoggerContextFactory loaded by org.apache.logging.log4j-api [13]
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
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.
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-impl.
mybundle.adapt(BundleWiring.class).getClassLoader();
--
This message was sent by Atlassian JIRA
(v6.3.4#6332)
Gary Gregory (JIRA)
2014-09-05 17:55:29 UTC
Permalink
[ https://issues.apache.org/jira/browse/LOG4J2-373?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=14123256#comment-14123256 ]

Gary Gregory commented on LOG4J2-373:
-------------------------------------

Just to make sure the obvious has been taken care: you ran "mvn clean install" to put the 2.1-SNAPSHOT in your local repo? Or, are you putting the jar files on your classpath differently?
Post by Roland Weiglhofer (JIRA)
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
Assignee: Matt Sicker
Priority: Critical
Labels: ClassLoader, OSGI
Fix For: 2.0.1
Attachments: log4j-api.patch
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
org.apache.logging.log4j.spi.LoggerContextFactory loaded by org.apache.logging.log4j-api [13]
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
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.
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-impl.
mybundle.adapt(BundleWiring.class).getClassLoader();
--
This message was sent by Atlassian JIRA
(v6.3.4#6332)
Gary Gregory (JIRA)
2014-09-05 17:56:28 UTC
Permalink
[ https://issues.apache.org/jira/browse/LOG4J2-373?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=14123256#comment-14123256 ]

Gary Gregory edited comment on LOG4J2-373 at 9/5/14 5:55 PM:
-------------------------------------------------------------

Just to make sure the obvious has been taken care of: you ran "mvn clean install" to put the 2.1-SNAPSHOT in your local repo? Or, are you putting the jar files on your classpath differently?


was (Author: garydgregory):
Just to make sure the obvious has been taken care: you ran "mvn clean install" to put the 2.1-SNAPSHOT in your local repo? Or, are you putting the jar files on your classpath differently?
Post by Roland Weiglhofer (JIRA)
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
Assignee: Matt Sicker
Priority: Critical
Labels: ClassLoader, OSGI
Fix For: 2.0.1
Attachments: log4j-api.patch
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
org.apache.logging.log4j.spi.LoggerContextFactory loaded by org.apache.logging.log4j-api [13]
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
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.
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-impl.
mybundle.adapt(BundleWiring.class).getClassLoader();
--
This message was sent by Atlassian JIRA
(v6.3.4#6332)
Snehadeep Sethia (JIRA)
2014-09-05 18:35:28 UTC
Permalink
[ https://issues.apache.org/jira/browse/LOG4J2-373?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=14123338#comment-14123338 ]

Snehadeep Sethia commented on LOG4J2-373:
-----------------------------------------

I ran "mvn clean install" to install it to my local m2 repo. The issue building 2.1-SNAPSHOT was maven version, I was using 2.2.1 and later switched to 3.1.0 and it seems to install fine.

Step taken so far
1. Ran mvn clean install on log4j-api and log4j-core cloned from https://github.com/apache/logging-log4j2.git and git checkout master
2. Ran "mvn eclipse:eclipse -DdownloadSources=true -Declipse.useProjectReferences=false -DdownloadJavadocs=true -U" on the plugin whose pom.xml has log4j-api and log4j-core as dependencies
3. Ram mvn copyresource to generate MANIFEST.MF on the plugin project
4. Ran "mvn eclipse:eclipse -DdownloadSources=true -Declipse.useProjectReferences=false -DdownloadJavadocs=true -U" on the main product
5. Ran "mvn clean install" on the main product
6. Ran the main product and get the exception "ERROR StatusLogger Log4j2 could not find a logging implementation. Please add log4j-core to the classpath. Using SimpleLogger to log to the console..."

I'm using
jdk1.6.0_45 (32 bit)
maven 3 to build the log4j jars
maven 2 to build the plugin and the product (we have a maven 2 constraint on the product)
org.eclipse.osgi version "3.8.1-SDK-4.2.1"
Post by Roland Weiglhofer (JIRA)
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
Assignee: Matt Sicker
Priority: Critical
Labels: ClassLoader, OSGI
Fix For: 2.0.1
Attachments: log4j-api.patch
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
org.apache.logging.log4j.spi.LoggerContextFactory loaded by org.apache.logging.log4j-api [13]
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
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.
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-impl.
mybundle.adapt(BundleWiring.class).getClassLoader();
--
This message was sent by Atlassian JIRA
(v6.3.4#6332)
Matt Sicker (JIRA)
2014-09-05 22:46:29 UTC
Permalink
[ https://issues.apache.org/jira/browse/LOG4J2-373?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=14123731#comment-14123731 ]

Matt Sicker commented on LOG4J2-373:
------------------------------------

Could you check out the latest code from here: http://git-wip-us.apache.org/repos/asf/logging-log4j2.git

And check out the branch called LOG4J2-809. I've been working on some ClassLoader-related code there which might affect this issue.
Post by Roland Weiglhofer (JIRA)
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
Assignee: Matt Sicker
Priority: Critical
Labels: ClassLoader, OSGI
Fix For: 2.0.1
Attachments: log4j-api.patch
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
org.apache.logging.log4j.spi.LoggerContextFactory loaded by org.apache.logging.log4j-api [13]
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
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.
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-impl.
mybundle.adapt(BundleWiring.class).getClassLoader();
--
This message was sent by Atlassian JIRA
(v6.3.4#6332)
Snehadeep Sethia (JIRA)
2014-09-08 15:22:30 UTC
Permalink
[ https://issues.apache.org/jira/browse/LOG4J2-373?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=14125667#comment-14125667 ]

Snehadeep Sethia commented on LOG4J2-373:
-----------------------------------------

I tried branch LOG4J2-809 from the link mentioned above, but still get the same issue.
A few things to note are the versions that I'm using, I'm not sure if these are conflicting/causing the trouble.

<org.osgi.core>4.3.1</org.osgi.core>
<org.eclipse.osgi.services>3.3.100-SDK-4.2.1</org.eclipse.osgi.services>
<org.eclipse.osgi>3.8.1-SDK-4.2.1</org.eclipse.osgi>
Post by Roland Weiglhofer (JIRA)
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
Assignee: Matt Sicker
Priority: Critical
Labels: ClassLoader, OSGI
Fix For: 2.0.1
Attachments: log4j-api.patch
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
org.apache.logging.log4j.spi.LoggerContextFactory loaded by org.apache.logging.log4j-api [13]
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
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.
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-impl.
mybundle.adapt(BundleWiring.class).getClassLoader();
--
This message was sent by Atlassian JIRA
(v6.3.4#6332)

Loading...