Using log4j with Equinox OSGi [message #491755] |
Thu, 15 October 2009 16:57 |
Tom H Messages: 18 Registered: July 2009 |
Junior Member |
|
|
Hi experts,
I have an integration project to include a OSGi application into an existing non-OSGi based application.
I am starting the Equinox OSGi framework programmatcially via:
EclipseStarter.setInitialProperties(buildProps());
g_bundleContext = EclipseStarter.startup(new String[] {}, null);
And then start the OSGi application via reflection:
Bundle myBundle = findMyInstalledBundle(g_bundleContext);
Class entryPointClass =
myBundle
.loadClass("com.mybundle.MainClass");
entryPointInstance = entryPointClass.newInstance();
// swap the class loader
Thread.currentThread().setContextClassLoader(
entryPointClass.getClassLoader())
// then invoke a public static main method using reflection
Method m =
entryPointClass.getMethod("runTransaction", new String[] {}
.getClass());
returnObj =
m.invoke(entryPointInstance, (Object) cmdList
.toArray(new String[] {}));
Now my problem is that the calling code of the above OSGi trickery is non-OSGi based and has already some LOG4j defined in its java classpath when launched. However, the code constructed in OSGi also has another set of log4j as bundles. What is the best way for OSGi bundles to use messages to the log4j classes of the calling code?
ie:
Class A- non osgi based
logs to /tmp/app.log /tmp/app.trc
OSGi B called via reflection from A
logs also to /tmp/app.log and /tmp/app.trc
Right now the problem is that the log4j classes loaded inside the OSGi bundles use the OSGi bundle classloader, which is different than the Class A's classloader. And I do not know how to convert them or re-direct the log messages programmatically.
Thanks,
Tom
[Updated on: Thu, 15 October 2009 16:57] Report message to a moderator
|
|
|
Powered by
FUDForum. Page generated in 0.02700 seconds