Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Plugin Development Environment (PDE) » Collecting all log4j "Logger" instances from all plugins
Collecting all log4j "Logger" instances from all plugins [message #635047] Mon, 25 October 2010 14:21
Maurice Okunek is currently offline Maurice OkunekFriend
Messages: 7
Registered: August 2010
Junior Member
Hi,

what I am trying to do here is surely not the clean way of using Eclipse and Plugin handling in general. Furthermore, I think I have to do some unwanted ClassLoader handling but let's see what you guys about it:

Here's the Use-Case:

I want to collect all Log4J Logger instances from the all plugins which were created when my Eclipse application has started. I want to that, because it is not practicable ATM to define some kind of Extension Point for that Use-Case. It should be a generic way to get all Loggers and configure them via a separate Editor oder View.

What i want to do is to obtain a Log4J Logger Class from a ClassLoader of a plugin like that way:

DefaultClassLoader loader = (DefaultClassLoader)Platform.getPlugin(pBundleId).getClass()
					.getClassLoader();


So i have the class loader (not sure if it is the one that I am looking for Smile), but now i need to collect the Logger instances that are used for a specific plugin. Because I am not able to fetch that directly, I will create a Dummy Logger with the plugin's Classloader and then I will obtain the parent Logger Object from the Dummy Logger, so that I'm able to get the Logger's hierarchy. From here on, the things are simple.

My greatest problem is to create a Logger instance with the ClassLoader from the given plugin:

Class pClass = loader.findLocalClass("org.apache.log4j.Logger");


I have used a "DefaultClassLoader" instance here, because the standard ClassLoader is not able to just return Classes without asking the Loader's hierarchy. That means i'm getting always the ClassLoader of my plugin from which i'm working and not given plugins Classloader. Here is what I mean:

Class pClass = loader.loadClass("org.apache.log4j.Logger");


That will always get me my current plugin, not the one specified by the "pBundleId" param as described above. Because i have a Dummy Logger in my executing plugin, that one will be returned.

The problem with

Class pClass = loader.findLocalClass("org.apache.log4j.Logger");


seems to be that I'm getting no class, ever. It seems to be the correct Loader, because I find the "pBundleId"'s Plugin Class there, but no Logger. I think that the Logger Object wasn't created because the Plugins Lifecycle does not load all Classes immediately.

Is there anyone out there who has some good advice on that? I know that I am trying to do non-nice stuff here, but if that will work, it would make my life a bit easier.

Kind regards,
Maurice
Previous Topic:OSGi debug - updating saved resources and refreshing bundles
Next Topic:Loading dependency at runtime
Goto Forum:
  


Current Time: Fri Dec 19 20:19:04 GMT 2014

Powered by FUDForum. Page generated in 0.02550 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software