logging-log4j-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Remko Popma <remko.po...@gmail.com>
Subject Re: Discussion about correct inicialization of log4j2 in OSGi context.
Date Fri, 16 Aug 2013 05:22:04 GMT
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 <wgl@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
>
>

Mime
  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message