[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [Newsgroup Home]
[news.eclipse.platform.rcp] Re: solution to classloading my custom java.util.logging.Handler class

John,

If you feel that this is just an expedient workaround and that buddy class loading should work even if the requesting class is in the system libraries, please file a bug against Platform Runtime.

They could also clarify whether this approach is too heavy for the start() method.

Nick

John J. Franey wrote:
I've discovered a quick and easy solution: Instantiate and configure the handler in my plugin's <code>start</code> method.

The Handler must be added to the right Loggers.  The right Loggers are the uppermost parent ('grandparent'?) logger that are common to the Loggers of the plugin.   For example, this code snippet will attach a handler to all Loggers who descend from 'org.open.project' (e.g., org.open.project.ui, org.open.project.model, ..).

<code>
package org.open.project;

PluginLogHandler h = new PuginLogHandler(context.getBundle().getSymbolicName());
Logger.getLogger("org.open.project").addHandler(h);
</code>


There may be more than one 'right' logger if the plugin contains diverse packages.

Hopefully, this isn't too much work for the <code>start</code> method.

It is not necessary to put the Handler onto the 'handlers' property in the logging.properties file.  Of course, doing so doesn't hurt, but prints ClassNotFound exception to the console, which is certainly misleading.  An exception from LogManager would also occur if in logging.properties the Handler is added to any Logger using <code><Logger>.handlers</code> property.

This Handler and the plugin's Loggers <b>can</b> be otherwise configured from the logging.properties file.  The Handler's implementation must use LogManager.getProperty() to configure itself.

For example, these lines in logging.properties would be effective:
<code>
# set Handler's properties
org.open.project.PluginLogHandler.level=FINE
org.open.project.PluginLogHandler.formatter=someFormatter

# set a Logger's properies
org.open.project.ui.level=SEVERE
</code>

Regards,
John


--
View in EZ forum: http://www.eclipsezone.com/eclipse/forums/m91950035.html