You are viewing a plain text version of this content. The canonical link for it is here.
Posted to log4j-user@logging.apache.org by Roland <wg...@ids.de> on 2013/08/15 17:33:49 UTC

Discussion about correct inicialization of log4j2 in OSGi context.

Hi all Log4j2 / OSGi experts!

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

I recognize that there is a need for discussion how log4j2 can be configured
and started correctly in an OSGi environment.

The standard procedure with configuration files in OSGi is to place them in
a fragmented bundle, so that the host finds the file in the classpath.
Obviously, there are still problems in beta9.

Error-msg: StatusLogger Unable to locate a logging implementation, using
SimpleLogger

Having spent 2 hours figuring out how Log4j2 reads the configurations I've
capitulated.

So,...I want to tell other readers how I would do it. Maybe I can help...

How I usually load configuration files from fragmented bundles:
1. Put the configuration file log4j2.xml to a fragmented bundle.
(->log4j2-users)
2. Implement the "BundleActivator"-interface (OSGi-core) for the
host-bundle. (->log4j2-devs.)
3. Add <Bundle-Activator>my.package.MyBundleActivator</Bundle-Activator> to
the maven-bundle-plugin instructions
(...<instructions><Bundle-Activator>...</Bundle-Activator></instructions>)
in the pom.
4. Implement the methode "start(BundleContext context)" so that it loads the
log4j2.xml on bundle-startup.
short expample...
private void readConfiguration(String directory, String filename)
  {
    URL url = null;
    Enumeration<URL> fileurls = null;
    InputStream is = null;
    //bundlecontext of host
    if(bundlecontext != null) {
      fileurls = bundlecontext.getBundle().findEntries(directory, filename,
true);  //get url of configuration 
    }
    if((fileurls != null) && (fileurls.hasMoreElements())) {
      url = fileurls.nextElement();  //take the first
    }
    if(url != null) {
      is = url.openStream();
    }
    if(is != null) {
        ...
        //read stream
    }
  }

This is one of among many possibilities how it can be done.

Are there better ideas?

Regards
Roland



--
View this message in context: http://apache-logging.6191.n7.nabble.com/Discussion-about-correct-inicialization-of-log4j2-in-OSGi-context-tp39733.html
Sent from the Log4j - Users mailing list archive at Nabble.com.

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


Re: Discussion about correct inicialization of log4j2 in OSGi context.

Posted by Roland <wg...@ids.de>.
Hello Remko,
Sorry I did not to clarified my intention.
I have a problem with log4j2 in an OSGi-environment (Unable to locate a
logging implementation...). So, I started to debug log4j2 but I was
unsuccessful. My intention was to present an easy way how log4j2 could load
a configuration within an OSGi-environment. The Users have only to create a
fragmented bundle including a log4j2.xml. The advantage of this approach is
that you  (as a log4j2-developer) do not have to think about which
ClassLoader you have to use to get the configuration.

Regards
Roland



--
View this message in context: http://apache-logging.6191.n7.nabble.com/Discussion-about-correct-initialization-of-log4j2-in-OSGi-context-tp39733p39751.html
Sent from the Log4j - Users mailing list archive at Nabble.com.

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


Re: Discussion about correct inicialization of log4j2 in OSGi context.

Posted by Remko Popma <re...@gmail.com>.
Roland,

Sorry, you lost me there...
Are these recommendations to people who want to use Log4j in their OSGi app?
Or changes that need to be made to the Log4j code? (I don't think so, just
wanted to clarify...)
Should this be added to the Log4j manual?

Remko


On Fri, Aug 16, 2013 at 12:33 AM, Roland <wg...@ids.de> wrote:

> Hi all Log4j2 / OSGi experts!
>
> Relates:
>
> https://issues.apache.org/jira/browse/LOG4J2-159?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
>
> I recognize that there is a need for discussion how log4j2 can be
> configured
> and started correctly in an OSGi environment.
>
> The standard procedure with configuration files in OSGi is to place them in
> a fragmented bundle, so that the host finds the file in the classpath.
> Obviously, there are still problems in beta9.
>
> Error-msg: StatusLogger Unable to locate a logging implementation, using
> SimpleLogger
>
> Having spent 2 hours figuring out how Log4j2 reads the configurations I've
> capitulated.
>
> So,...I want to tell other readers how I would do it. Maybe I can help...
>
> How I usually load configuration files from fragmented bundles:
> 1. Put the configuration file log4j2.xml to a fragmented bundle.
> (->log4j2-users)
> 2. Implement the "BundleActivator"-interface (OSGi-core) for the
> host-bundle. (->log4j2-devs.)
> 3. Add <Bundle-Activator>my.package.MyBundleActivator</Bundle-Activator> to
> the maven-bundle-plugin instructions
> (...<instructions><Bundle-Activator>...</Bundle-Activator></instructions>)
> in the pom.
> 4. Implement the methode "start(BundleContext context)" so that it loads
> the
> log4j2.xml on bundle-startup.
> short expample...
> private void readConfiguration(String directory, String filename)
>   {
>     URL url = null;
>     Enumeration<URL> fileurls = null;
>     InputStream is = null;
>     //bundlecontext of host
>     if(bundlecontext != null) {
>       fileurls = bundlecontext.getBundle().findEntries(directory, filename,
> true);  //get url of configuration
>     }
>     if((fileurls != null) && (fileurls.hasMoreElements())) {
>       url = fileurls.nextElement();  //take the first
>     }
>     if(url != null) {
>       is = url.openStream();
>     }
>     if(is != null) {
>         ...
>         //read stream
>     }
>   }
>
> This is one of among many possibilities how it can be done.
>
> Are there better ideas?
>
> Regards
> Roland
>
>
>
> --
> View this message in context:
> http://apache-logging.6191.n7.nabble.com/Discussion-about-correct-inicialization-of-log4j2-in-OSGi-context-tp39733.html
> Sent from the Log4j - Users mailing list archive at Nabble.com.
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: log4j-user-unsubscribe@logging.apache.org
> For additional commands, e-mail: log4j-user-help@logging.apache.org
>
>

Re: Discussion about correct inicialization of log4j2 in OSGi context.

Posted by Roland <wg...@ids.de>.
Yet another problem with log4j2 and OSGi (concerning classloaders):
https://issues.apache.org/jira/browse/LOG4J2-373



--
View this message in context: http://apache-logging.6191.n7.nabble.com/Discussion-about-correct-initialization-of-log4j2-in-OSGi-context-tp39733p40182.html
Sent from the Log4j - Users mailing list archive at Nabble.com.

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


Re: Discussion about correct inicialization of log4j2 in OSGi context.

Posted by Roland <wg...@ids.de>.
hi,
today I checked my poms. My mistake was that I didn't specified the
dependency on the core. However, the core library was in the same folder as
the API, according to the manual. So, if log4j2 is used in an
OSGi-environment, you have to specify the dependencies on the core and on
the api in the POM, otherwise the libraries are not added to the
bundle-ClassLoader. The manual should address this relation, because the
error message is misleading in this case.

Thx and regards



--
View this message in context: http://apache-logging.6191.n7.nabble.com/Discussion-about-correct-initialization-of-log4j2-in-OSGi-context-tp39733p40133.html
Sent from the Log4j - Users mailing list archive at Nabble.com.

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


Re: Discussion about correct inicialization of log4j2 in OSGi context.

Posted by Ralph Goers <ra...@dslextreme.com>.
Actually, I'd very much appreciate you NOT going back to log4j 1 and working through this.

LogManager calls ProviderUtils.getProviders().  ProviderUtil has a static initializer that calls the ClassLoader's getResources method looking for all instances of the file "META-INF/log4j-provider.properties".  A Log4j 2 implementation will have one of these files and specify what version of the Log4j 2 API it is compatible with, the LoggerContextFactory class name and the "priority" of the factory.  

What you are experiencing indicates that when the ProviderUtils class is loaded the Log4j 2 implementation is somehow not yet present.

Ralph


On Aug 16, 2013, at 2:17 AM, Roland wrote:

> some trace
> 
> LogManager line 58: factoryClass is null
>                   line 76: hasProviders() returns false
> 
> lb
> START LEVEL 4
>   ID|State      |Level|Name
>    0|Active     |    0|System Bundle (4.2.1)
>    4|Active     |    2|Apache Felix Bundle Repository (1.6.6)
>    5|Active     |    2|Apache Felix Configuration Admin Service (1.6.0)
>    6|Active     |    2|Apache Felix Gogo Command (0.12.0)
>    7|Active     |    2|Apache Felix Gogo Runtime (0.10.0)
>    8|Active     |    2|Apache Felix Gogo Shell (0.10.0)
>    9|Resolved   |    2|Apache Felix Security Provider (2.2.0)
>   10|Active     |    2|Apache Felix Shell Service (1.4.3)
>   11|Active     |    2|Apache Log4j 1.x Compatibility API
> (2.0.0.beta9-SNAPSHOT)
>   12|Active     |    2|Apache Log4j API (2.0.0.beta9-SNAPSHOT)
>   13|Active     |    2|Apache Log4j Commons Logging Bridge
> (2.0.0.beta9-SNAPSHOT)
>   14|Resolved   |    2|Apache Log4j Core (2.0.0.beta9-SNAPSHOT)
>   15|Active     |    2|Apache Log4j SLF4J Binding (2.0.0.beta9-SNAPSHOT)
>   16|Active     |    2|cal10n-api (0.7.4)
>   17|Active     |    2|Commons IO (2.4.0)
>   18|Active     |    2|Commons Lang (2.6.0)
>   19|Active     |    2|Disruptor Framework (3.1.1)
>   20|Active     |    2|Jackson-annotations (2.2.2)
>   21|Active     |    2|Jackson-core (2.2.2)
>   22|Active     |    2|jackson-databind (2.2.2)
>   23|Active     |    2|JSON.simple (1.1.1)
>   24|Active     |    2|MongoDB Java Driver (2.11.2.RELEASE)
>   25|Active     |    2|slf4j-api (1.7.5)
>   26|Active     |    2|slf4j-ext (1.7.5)
> 
> 
> g! inspect req * 14
> org.apache.logging.log4j-core [14] requires:
> --------------------------------------------
> osgi.wiring.host;
> (&(osgi.wiring.host=org.apache.logging.log4j-api)(bundle-version>=2.0.0.beta9-SNAPSHOT))
> resolved by:
>   osgi.wiring.host; org.apache.logging.log4j-api 2.0.0.beta9-SNAPSHOT from
> org.apache.logging.log4j-api [12]
> 
> g! inspect cap * 12
> org.apache.logging.log4j-api [12] provides:
> -------------------------------------------
> osgi.wiring.bundle; org.apache.logging.log4j-api 2.0.0.beta9-SNAPSHOT
> [UNUSED]
> osgi.wiring.host; org.apache.logging.log4j-api 2.0.0.beta9-SNAPSHOT required
> by:
>   org.apache.logging.log4j-core [14]
>   my.package.my-log4j2-config [1]
> osgi.wiring.package; org.apache.logging.log4j.message 2.0.0.beta9-SNAPSHOT
> required by:
>   org.apache.logging.log4j-1.2-api [11]
> osgi.wiring.package; org.apache.logging.log4j.util 2.0.0.beta9-SNAPSHOT
> [UNUSED]
> osgi.wiring.package; org.apache.logging.log4j.simple 2.0.0.beta9-SNAPSHOT
> [UNUSED]
> osgi.wiring.package; org.apache.logging.log4j.status 2.0.0.beta9-SNAPSHOT
> [UNUSED]
> osgi.wiring.package; org.apache.logging.log4j 2.0.0.beta9-SNAPSHOT required
> by:
>   de.ids.acos.rtu.osgi.bundles.acos-rtu-logservice [2]
>   org.apache.logging.log4j-1.2-api [11]
> osgi.wiring.package; org.apache.logging.log4j.spi 2.0.0.beta9-SNAPSHOT
> required by:
>   org.apache.logging.log4j-1.2-api [11]
> osgi.wiring.package; org.apache.logging.log4j.core.appender.rewrite
> 2.0.0.beta9-SNAPSHOT [UNUSED]
> osgi.wiring.package; org.apache.logging.log4j.core.impl 2.0.0.beta9-SNAPSHOT
> [UNUSED]
> osgi.wiring.package; org.apache.logging.log4j.core.pattern
> 2.0.0.beta9-SNAPSHOT [UNUSED]
> osgi.wiring.package; org.apache.logging.log4j.core.appender.db.jpa.converter
> 2.0.0.beta9-SNAPSHOT [UNUSED]
> osgi.wiring.package; org.apache.logging.log4j.core.web 2.0.0.beta9-SNAPSHOT
> [UNUSED]
> osgi.wiring.package; org.apache.logging.log4j.core.filter
> 2.0.0.beta9-SNAPSHOT [UNUSED]
> osgi.wiring.package; org.apache.logging.log4j.core 2.0.0.beta9-SNAPSHOT
> required by:
>   org.apache.logging.log4j-1.2-api [11]
> osgi.wiring.package; org.apache.logging.log4j.core.lookup
> 2.0.0.beta9-SNAPSHOT [UNUSED]
> osgi.wiring.package; org.apache.logging.log4j.core.appender.db.nosql
> 2.0.0.beta9-SNAPSHOT [UNUSED]
> osgi.wiring.package; org.apache.logging.log4j.core.appender.db.jdbc
> 2.0.0.beta9-SNAPSHOT [UNUSED]
> osgi.wiring.package; org.apache.logging.log4j.core.appender
> 2.0.0.beta9-SNAPSHOT [UNUSED]
> osgi.wiring.package; org.apache.logging.log4j.core.appender.db
> 2.0.0.beta9-SNAPSHOT [UNUSED]
> osgi.wiring.package; org.apache.logging.log4j.core.selector
> 2.0.0.beta9-SNAPSHOT [UNUSED]
> osgi.wiring.package; org.apache.logging.log4j.core.jmx 2.0.0.beta9-SNAPSHOT
> [UNUSED]
> osgi.wiring.package; org.apache.logging.log4j.core.appender.db.nosql.couch
> 2.0.0.beta9-SNAPSHOT [UNUSED]
> osgi.wiring.package; org.apache.logging.log4j.core.async
> 2.0.0.beta9-SNAPSHOT [UNUSED]
> osgi.wiring.package; org.apache.logging.log4j.core.helpers
> 2.0.0.beta9-SNAPSHOT required by:
>   org.apache.logging.log4j-1.2-api [11]
> osgi.wiring.package; org.apache.logging.log4j.core.config.plugins
> 2.0.0.beta9-SNAPSHOT [UNUSED]
> osgi.wiring.package; org.apache.logging.log4j.core.layout
> 2.0.0.beta9-SNAPSHOT [UNUSED]
> osgi.wiring.package; org.apache.logging.log4j.core.net 2.0.0.beta9-SNAPSHOT
> [UNUSED]
> osgi.wiring.package; org.apache.logging.log4j.core.config
> 2.0.0.beta9-SNAPSHOT [UNUSED]
> osgi.wiring.package; org.apache.logging.log4j.core.appender.rolling.helper
> 2.0.0.beta9-SNAPSHOT [UNUSED]
> osgi.wiring.package; org.apache.logging.log4j.core.appender.db.nosql.mongo
> 2.0.0.beta9-SNAPSHOT [UNUSED]
> osgi.wiring.package; org.apache.logging.log4j.core.appender.db.jpa
> 2.0.0.beta9-SNAPSHOT [UNUSED]
> osgi.wiring.package; org.apache.logging.log4j.core.appender.rolling
> 2.0.0.beta9-SNAPSHOT [UNUSED]
> osgi.wiring.package; org.apache.logging.log4j.core.appender.routing
> 2.0.0.beta9-SNAPSHOT [UNUSED]
> 
> 
> How does the LogManager seek the implementation? As you can see
> org.apache.logging.log4j.core.impl is unused.
> I'm running out of ideas...I'm thinking about switching back to the old
> log4j. Keep it simple, stupid.
> 
> 
> 
> --
> View this message in context: http://apache-logging.6191.n7.nabble.com/Discussion-about-correct-initialization-of-log4j2-in-OSGi-context-tp39733p39760.html
> Sent from the Log4j - Users mailing list archive at Nabble.com.
> 
> ---------------------------------------------------------------------
> 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


Re: Discussion about correct inicialization of log4j2 in OSGi context.

Posted by Roland <wg...@ids.de>.
some trace

LogManager line 58: factoryClass is null
                   line 76: hasProviders() returns false

lb
START LEVEL 4
   ID|State      |Level|Name
    0|Active     |    0|System Bundle (4.2.1)
    4|Active     |    2|Apache Felix Bundle Repository (1.6.6)
    5|Active     |    2|Apache Felix Configuration Admin Service (1.6.0)
    6|Active     |    2|Apache Felix Gogo Command (0.12.0)
    7|Active     |    2|Apache Felix Gogo Runtime (0.10.0)
    8|Active     |    2|Apache Felix Gogo Shell (0.10.0)
    9|Resolved   |    2|Apache Felix Security Provider (2.2.0)
   10|Active     |    2|Apache Felix Shell Service (1.4.3)
   11|Active     |    2|Apache Log4j 1.x Compatibility API
(2.0.0.beta9-SNAPSHOT)
   12|Active     |    2|Apache Log4j API (2.0.0.beta9-SNAPSHOT)
   13|Active     |    2|Apache Log4j Commons Logging Bridge
(2.0.0.beta9-SNAPSHOT)
   14|Resolved   |    2|Apache Log4j Core (2.0.0.beta9-SNAPSHOT)
   15|Active     |    2|Apache Log4j SLF4J Binding (2.0.0.beta9-SNAPSHOT)
   16|Active     |    2|cal10n-api (0.7.4)
   17|Active     |    2|Commons IO (2.4.0)
   18|Active     |    2|Commons Lang (2.6.0)
   19|Active     |    2|Disruptor Framework (3.1.1)
   20|Active     |    2|Jackson-annotations (2.2.2)
   21|Active     |    2|Jackson-core (2.2.2)
   22|Active     |    2|jackson-databind (2.2.2)
   23|Active     |    2|JSON.simple (1.1.1)
   24|Active     |    2|MongoDB Java Driver (2.11.2.RELEASE)
   25|Active     |    2|slf4j-api (1.7.5)
   26|Active     |    2|slf4j-ext (1.7.5)


g! inspect req * 14
org.apache.logging.log4j-core [14] requires:
--------------------------------------------
osgi.wiring.host;
(&(osgi.wiring.host=org.apache.logging.log4j-api)(bundle-version>=2.0.0.beta9-SNAPSHOT))
resolved by:
   osgi.wiring.host; org.apache.logging.log4j-api 2.0.0.beta9-SNAPSHOT from
org.apache.logging.log4j-api [12]

g! inspect cap * 12
org.apache.logging.log4j-api [12] provides:
-------------------------------------------
osgi.wiring.bundle; org.apache.logging.log4j-api 2.0.0.beta9-SNAPSHOT
[UNUSED]
osgi.wiring.host; org.apache.logging.log4j-api 2.0.0.beta9-SNAPSHOT required
by:
   org.apache.logging.log4j-core [14]
   my.package.my-log4j2-config [1]
osgi.wiring.package; org.apache.logging.log4j.message 2.0.0.beta9-SNAPSHOT
required by:
   org.apache.logging.log4j-1.2-api [11]
osgi.wiring.package; org.apache.logging.log4j.util 2.0.0.beta9-SNAPSHOT
[UNUSED]
osgi.wiring.package; org.apache.logging.log4j.simple 2.0.0.beta9-SNAPSHOT
[UNUSED]
osgi.wiring.package; org.apache.logging.log4j.status 2.0.0.beta9-SNAPSHOT
[UNUSED]
osgi.wiring.package; org.apache.logging.log4j 2.0.0.beta9-SNAPSHOT required
by:
   de.ids.acos.rtu.osgi.bundles.acos-rtu-logservice [2]
   org.apache.logging.log4j-1.2-api [11]
osgi.wiring.package; org.apache.logging.log4j.spi 2.0.0.beta9-SNAPSHOT
required by:
   org.apache.logging.log4j-1.2-api [11]
osgi.wiring.package; org.apache.logging.log4j.core.appender.rewrite
2.0.0.beta9-SNAPSHOT [UNUSED]
osgi.wiring.package; org.apache.logging.log4j.core.impl 2.0.0.beta9-SNAPSHOT
[UNUSED]
osgi.wiring.package; org.apache.logging.log4j.core.pattern
2.0.0.beta9-SNAPSHOT [UNUSED]
osgi.wiring.package; org.apache.logging.log4j.core.appender.db.jpa.converter
2.0.0.beta9-SNAPSHOT [UNUSED]
osgi.wiring.package; org.apache.logging.log4j.core.web 2.0.0.beta9-SNAPSHOT
[UNUSED]
osgi.wiring.package; org.apache.logging.log4j.core.filter
2.0.0.beta9-SNAPSHOT [UNUSED]
osgi.wiring.package; org.apache.logging.log4j.core 2.0.0.beta9-SNAPSHOT
required by:
   org.apache.logging.log4j-1.2-api [11]
osgi.wiring.package; org.apache.logging.log4j.core.lookup
2.0.0.beta9-SNAPSHOT [UNUSED]
osgi.wiring.package; org.apache.logging.log4j.core.appender.db.nosql
2.0.0.beta9-SNAPSHOT [UNUSED]
osgi.wiring.package; org.apache.logging.log4j.core.appender.db.jdbc
2.0.0.beta9-SNAPSHOT [UNUSED]
osgi.wiring.package; org.apache.logging.log4j.core.appender
2.0.0.beta9-SNAPSHOT [UNUSED]
osgi.wiring.package; org.apache.logging.log4j.core.appender.db
2.0.0.beta9-SNAPSHOT [UNUSED]
osgi.wiring.package; org.apache.logging.log4j.core.selector
2.0.0.beta9-SNAPSHOT [UNUSED]
osgi.wiring.package; org.apache.logging.log4j.core.jmx 2.0.0.beta9-SNAPSHOT
[UNUSED]
osgi.wiring.package; org.apache.logging.log4j.core.appender.db.nosql.couch
2.0.0.beta9-SNAPSHOT [UNUSED]
osgi.wiring.package; org.apache.logging.log4j.core.async
2.0.0.beta9-SNAPSHOT [UNUSED]
osgi.wiring.package; org.apache.logging.log4j.core.helpers
2.0.0.beta9-SNAPSHOT required by:
   org.apache.logging.log4j-1.2-api [11]
osgi.wiring.package; org.apache.logging.log4j.core.config.plugins
2.0.0.beta9-SNAPSHOT [UNUSED]
osgi.wiring.package; org.apache.logging.log4j.core.layout
2.0.0.beta9-SNAPSHOT [UNUSED]
osgi.wiring.package; org.apache.logging.log4j.core.net 2.0.0.beta9-SNAPSHOT
[UNUSED]
osgi.wiring.package; org.apache.logging.log4j.core.config
2.0.0.beta9-SNAPSHOT [UNUSED]
osgi.wiring.package; org.apache.logging.log4j.core.appender.rolling.helper
2.0.0.beta9-SNAPSHOT [UNUSED]
osgi.wiring.package; org.apache.logging.log4j.core.appender.db.nosql.mongo
2.0.0.beta9-SNAPSHOT [UNUSED]
osgi.wiring.package; org.apache.logging.log4j.core.appender.db.jpa
2.0.0.beta9-SNAPSHOT [UNUSED]
osgi.wiring.package; org.apache.logging.log4j.core.appender.rolling
2.0.0.beta9-SNAPSHOT [UNUSED]
osgi.wiring.package; org.apache.logging.log4j.core.appender.routing
2.0.0.beta9-SNAPSHOT [UNUSED]


How does the LogManager seek the implementation? As you can see
org.apache.logging.log4j.core.impl is unused.
I'm running out of ideas...I'm thinking about switching back to the old
log4j. Keep it simple, stupid.



--
View this message in context: http://apache-logging.6191.n7.nabble.com/Discussion-about-correct-initialization-of-log4j2-in-OSGi-context-tp39733p39760.html
Sent from the Log4j - Users mailing list archive at Nabble.com.

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


Re: Discussion about correct inicialization of log4j2 in OSGi context.

Posted by Roland <wg...@ids.de>.
I've thought about it and it should would work as is, since core api and
config have the same class loader. Maybe I have a bug in my patch...let me
see.



--
View this message in context: http://apache-logging.6191.n7.nabble.com/Discussion-about-correct-initialization-of-log4j2-in-OSGi-context-tp39733p39759.html
Sent from the Log4j - Users mailing list archive at Nabble.com.

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


Re: Discussion about correct inicialization of log4j2 in OSGi context.

Posted by Roland <wg...@ids.de>.
That is a important information! The implementation-bundle should be a host,
but it is a fragment of the api-bundle. Because fragmented bundles can not
have fragments it is not possible with this architecture to load
configurations of fragmented bundles. The usual approach with OSGi is not
possible. hm...
Configuration files should be deployed like the bundles, thats why they are
usually included in fragmented bundles. It would be nice if it would be
possible. This assumes that the implementation (the core?) is a host, right?

Regards
Roalnd



--
View this message in context: http://apache-logging.6191.n7.nabble.com/Discussion-about-correct-initialization-of-log4j2-in-OSGi-context-tp39733p39755.html
Sent from the Log4j - Users mailing list archive at Nabble.com.

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


Re: Discussion about correct inicialization of log4j2 in OSGi context.

Posted by Ralph Goers <rg...@apache.org>.
The implementation loads the configuration. If it can't find the implementation it will never load a configuration. Others have reported the have gotten at least that much to work so I have no idea what the issue is.

Sent from my iPad

On Aug 16, 2013, at 12:15 AM, Roland <wg...@ids.de> wrote:

> addendum:
> 
> Am I wrong? Are these two different errors having nothing in common?
> 
> Thanks
> Roalnd
> 
> 
> 
> --
> View this message in context: http://apache-logging.6191.n7.nabble.com/Discussion-about-correct-initialization-of-log4j2-in-OSGi-context-tp39733p39753.html
> Sent from the Log4j - Users mailing list archive at Nabble.com.
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: log4j-user-unsubscribe@logging.apache.org
> For additional commands, e-mail: log4j-user-help@logging

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


Re: Discussion about correct inicialization of log4j2 in OSGi context.

Posted by Roland <wg...@ids.de>.
addendum:

Am I wrong? Are these two different errors having nothing in common?

Thanks
Roalnd



--
View this message in context: http://apache-logging.6191.n7.nabble.com/Discussion-about-correct-initialization-of-log4j2-in-OSGi-context-tp39733p39753.html
Sent from the Log4j - Users mailing list archive at Nabble.com.

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


Re: Discussion about correct inicialization of log4j2 in OSGi context.

Posted by Roland <wg...@ids.de>.
Hello Ralph,
That's right. Log4j2 api can not find the implementation. Due to similar
error messages of other users I think that the configuration can not be
found and thus no implementation. I started to debug log4j2 and I do not
understand how log4j2 loads a configuration in an OSGi-environment. That's
why I want to discuss this.

Regards
Roland



--
View this message in context: http://apache-logging.6191.n7.nabble.com/Discussion-about-correct-initialization-of-log4j2-in-OSGi-context-tp39733p39752.html
Sent from the Log4j - Users mailing list archive at Nabble.com.

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


Re: Discussion about correct inicialization of log4j2 in OSGi context.

Posted by Ralph Goers <ra...@dslextreme.com>.
My first question is that the error message you show below indicates that a Log4j 2 implementation could not be located. Yet the rest of your email seems to be about locating the log4j 2 configuration.

Ralph

On Aug 15, 2013, at 8:33 AM, Roland wrote:

> Hi all Log4j2 / OSGi experts!
> 
> Relates:
> https://issues.apache.org/jira/browse/LOG4J2-159?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
> 
> I recognize that there is a need for discussion how log4j2 can be configured
> and started correctly in an OSGi environment.
> 
> The standard procedure with configuration files in OSGi is to place them in
> a fragmented bundle, so that the host finds the file in the classpath.
> Obviously, there are still problems in beta9.
> 
> Error-msg: StatusLogger Unable to locate a logging implementation, using
> SimpleLogger
> 
> Having spent 2 hours figuring out how Log4j2 reads the configurations I've
> capitulated.
> 
> So,...I want to tell other readers how I would do it. Maybe I can help...
> 
> How I usually load configuration files from fragmented bundles:
> 1. Put the configuration file log4j2.xml to a fragmented bundle.
> (->log4j2-users)
> 2. Implement the "BundleActivator"-interface (OSGi-core) for the
> host-bundle. (->log4j2-devs.)
> 3. Add <Bundle-Activator>my.package.MyBundleActivator</Bundle-Activator> to
> the maven-bundle-plugin instructions
> (...<instructions><Bundle-Activator>...</Bundle-Activator></instructions>)
> in the pom.
> 4. Implement the methode "start(BundleContext context)" so that it loads the
> log4j2.xml on bundle-startup.
> short expample...
> private void readConfiguration(String directory, String filename)
>  {
>    URL url = null;
>    Enumeration<URL> fileurls = null;
>    InputStream is = null;
>    //bundlecontext of host
>    if(bundlecontext != null) {
>      fileurls = bundlecontext.getBundle().findEntries(directory, filename,
> true);  //get url of configuration 
>    }
>    if((fileurls != null) && (fileurls.hasMoreElements())) {
>      url = fileurls.nextElement();  //take the first
>    }
>    if(url != null) {
>      is = url.openStream();
>    }
>    if(is != null) {
>        ...
>        //read stream
>    }
>  }
> 
> This is one of among many possibilities how it can be done.
> 
> Are there better ideas?
> 
> Regards
> Roland
> 
> 
> 
> --
> View this message in context: http://apache-logging.6191.n7.nabble.com/Discussion-about-correct-inicialization-of-log4j2-in-OSGi-context-tp39733.html
> Sent from the Log4j - Users mailing list archive at Nabble.com.
> 
> ---------------------------------------------------------------------
> 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