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-unsubscr...@logging.apache.org For additional commands, e-mail: log4j-user-h...@logging.apache.org