logging-log4j-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Ralph Goers <ralph.go...@dslextreme.com>
Subject Re: Using BasicContextSelector in OSGI application
Date Fri, 28 Sep 2018 17:34:27 GMT
It sounds related to LOG4J2-920 but the solution provided there has to be incorrect. There
is no way the Log4j API should be declaring any requirements on Log4j Core stuff, especially
since the Log4j API doesn’t have a clue what a ContextSelector is. That is only use by the
Log4jContextFactory. I suspect the problem is that LoaderUtil resides in log4j-api and since
it is actually doing the loading it is causing the problem. That means we are either doing
the loading wrong or there is something broken in OSGi.

Ralph

> On Sep 28, 2018, at 10:20 AM, Rob Gansevles <rgansevles@gmail.com> wrote:
> 
> Yes, that makes sense, but it seems they are still loaded by the log4j-api.
> I guess this is the reason there are a few optional import-package
> declarations in the manifest-generation in the pom for log4j-api:
> 
>      <plugin>
>        <groupId>org.apache.felix</groupId>
>        <artifactId>maven-bundle-plugin</artifactId>
>        <configuration>
>          <instructions>
>            <Export-Package>org.apache.logging.log4j.*</Export-Package>
>            <Import-Package>
>              sun.reflect;resolution:=optional,
>              org.apache.logging.log4j.core.osgi;resolution:=optional,
>              org.apache.logging.log4j.core.util;resolution:=optional,
>              org.apache.logging.log4j.core.async;resolution:=optional,
>              *
>            </Import-Package>
> 
> <Bundle-Activator>org.apache.logging.log4j.util.Activator</Bundle-Activator>
>            <_fixupmessages>"Classes found in the wrong
> directory";is:=warning</_fixupmessages>
>          </instructions>
>        </configuration>
>      </plugin>
> 
> I get the error below when I use the BasicContextSelector, and when I add
> org.apache.logging.log4j.core.selector to the imports in the manifest it
> works.
> 
> Maybe it is the same issue as discussed in LOG4J2-920 but then
> for BundleContextSelector and should a similar patch being applied.
> What do you think?
> 
> ERROR StatusLogger Unable to create custom ContextSelector. Falling back to
> default.
> java.lang.ClassNotFoundException:
> org.apache.logging.log4j.core.selector.BasicContextSelector cannot be found
> by org.apache.logging.log4j.api_2.11.2.SNAPSHOT
> at
> org.eclipse.osgi.internal.loader.BundleLoader.findClassInternal(BundleLoader.java:508)
> at
> org.eclipse.osgi.internal.loader.BundleLoader.findClass(BundleLoader.java:419)
> at
> org.eclipse.osgi.internal.loader.BundleLoader.findClass(BundleLoader.java:411)
> at
> org.eclipse.osgi.internal.loader.ModuleClassLoader.loadClass(ModuleClassLoader.java:150)
> at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
> at java.lang.Class.forName0(Native Method)
> at java.lang.Class.forName(Class.java:264)
> at org.apache.logging.log4j.util.LoaderUtil.loadClass(LoaderUtil.java:168)
> at
> org.apache.logging.log4j.util.LoaderUtil.newInstanceOf(LoaderUtil.java:207)
> at
> org.apache.logging.log4j.util.LoaderUtil.newCheckedInstanceOf(LoaderUtil.java:228)
> at
> org.apache.logging.log4j.util.LoaderUtil.newCheckedInstanceOfProperty(LoaderUtil.java:253)
> at
> org.apache.logging.log4j.core.impl.Log4jContextFactory.createContextSelector(Log4jContextFactory.java:98)
> at
> org.apache.logging.log4j.core.impl.Log4jContextFactory.<init>(Log4jContextFactory.java:59)
> at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
> at
> sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
> at
> sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
> at java.lang.reflect.Constructor.newInstance(Constructor.java:423)
> at java.lang.Class.newInstance(Class.java:442)
> at org.apache.logging.log4j.LogManager.<clinit>(LogManager.java:94)
> at
> org.apache.logging.log4j.spi.AbstractLoggerAdapter.getContext(AbstractLoggerAdapter.java:121)
> at
> org.apache.logging.slf4j.Log4jLoggerFactory.getContext(Log4jLoggerFactory.java:49)
> at
> org.apache.logging.log4j.spi.AbstractLoggerAdapter.getLogger(AbstractLoggerAdapter.java:46)
> at
> org.apache.logging.slf4j.Log4jLoggerFactory.getLogger(Log4jLoggerFactory.java:29)
> at org.slf4j.LoggerFactory.getLogger(LoggerFactory.java:355)
> at org.slf4j.LoggerFactory.getLogger(LoggerFactory.java:380)
> at com.servoy.j2db.server.main.Activator.<clinit>(Activator.java:44)
> at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
> at
> sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
> at
> sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
> at java.lang.reflect.Constructor.newInstance(Constructor.java:423)
> at java.lang.Class.newInstance(Class.java:442)
> at
> org.eclipse.osgi.internal.framework.BundleContextImpl.loadBundleActivator(BundleContextImpl.java:763)
> at
> org.eclipse.osgi.internal.framework.BundleContextImpl.start(BundleContextImpl.java:716)
> at
> org.eclipse.osgi.internal.framework.EquinoxBundle.startWorker0(EquinoxBundle.java:1002)
> at
> org.eclipse.osgi.internal.framework.EquinoxBundle$EquinoxModule.startWorker(EquinoxBundle.java:354)
> at org.eclipse.osgi.container.Module.doStart(Module.java:581)
> at org.eclipse.osgi.container.Module.start(Module.java:449)
> at org.eclipse.osgi.framework.util.SecureAction.start(SecureAction.java:468)
> at
> org.eclipse.osgi.internal.hooks.EclipseLazyStarter.postFindLocalClass(EclipseLazyStarter.java:114)
> at
> org.eclipse.osgi.internal.loader.classpath.ClasspathManager.findLocalClass(ClasspathManager.java:505)
> at
> org.eclipse.osgi.internal.loader.ModuleClassLoader.findLocalClass(ModuleClassLoader.java:328)
> at
> org.eclipse.osgi.internal.loader.BundleLoader.findLocalClass(BundleLoader.java:392)
> at
> org.eclipse.osgi.internal.loader.sources.SingleSourcePackage.loadClass(SingleSourcePackage.java:36)
> at
> org.eclipse.osgi.internal.loader.BundleLoader.findClassInternal(BundleLoader.java:466)
> at
> org.eclipse.osgi.internal.loader.BundleLoader.findClass(BundleLoader.java:419)
> at
> org.eclipse.osgi.internal.loader.BundleLoader.findClass(BundleLoader.java:411)
> at
> org.eclipse.osgi.internal.loader.ModuleClassLoader.loadClass(ModuleClassLoader.java:150)
> at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
> 
> 
> On Fri, Sep 28, 2018 at 6:01 PM Ralph Goers <ralph.goers@dslextreme.com>
> wrote:
> 
>> All ContextSelectors are part of log4j-core, not log4j-api.
>> 
>> Ralph
>> 
>>> On Sep 28, 2018, at 7:59 AM, Rob Gansevles <rgansevles@gmail.com> wrote:
>>> 
>>> Hi,
>>> 
>>> I would like to use the BasicContextSelector in our OSGI application so
>>> have a single global log4j connfiguration as described in
>>> http://logging.apache.org/log4j/2.x/manual/logsep.html
>>> 
>>> However, BasicContextSelector lives in
>>> package org.apache.logging.log4j.core.selector which does not seem to be
>>> usable from log4j-api.
>>> 
>>> This package is not imported in the manifest of log4j-api like other
>>> packages (for example org.apache.logging.log4j.core.async).
>>> 
>>> Is this missing, or am I missing something?
>>> 
>>> I am using log4j 2.11.1
>>> 
>>> Regards,
>>> 
>>> Rob
>> 
>> 
>> 
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: log4j-user-unsubscribe@logging.apache.org
>> For additional commands, e-mail: log4j-user-help@logging.apache.org
>> 
>> 



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


Mime
View raw message