Skip to main content



      Home
Home » Eclipse Projects » Eclipse Platform » Using java.util.logging to wrap the Eclipse logger
Using java.util.logging to wrap the Eclipse logger [message #319979] Thu, 06 September 2007 17:08 Go to next message
Eclipse UserFriend
Originally posted by: rob.brainkandy-dot-org.org

Hi there,

At work we are considering using the java.util.logging package to be responsible
for all our logging, and add a custom handler to send all our logged messages to
the Eclipse ILogs.

Is this something people already do, and if so, what have they learned about it?
Can someone advise about abstraction incompatibilities (incompatible logging
levels, for instance), startup / BundleContext issues, et cetera?

Thanks for your help!

Robert
Re: Using java.util.logging to wrap the Eclipse logger [message #319982 is a reply to message #319979] Thu, 06 September 2007 20:40 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: wegener.cboenospam.com

Robert Konigsberg wrote:
> Hi there,
>
> At work we are considering using the java.util.logging package to be
> responsible for all our logging, and add a custom handler to send all
> our logged messages to the Eclipse ILogs.
>
> Is this something people already do, and if so, what have they learned
> about it? Can someone advise about abstraction incompatibilities
> (incompatible logging levels, for instance), startup / BundleContext
> issues, et cetera?
>
> Thanks for your help!
>
> Robert
Check out the following link on the Developer Works web site. It is a
little old, but should still be relevant and will at least get you started.

http://www.ibm.com/developerworks/opensource/library/os-eclo g/
Re: Using java.util.logging to wrap the Eclipse logger [message #320004 is a reply to message #319982] Fri, 07 September 2007 22:37 Go to previous messageGo to next message
Eclipse UserFriend
Robert,

We used the same article/jars for logging. It worked out extremely well for
our in house applications.

David Kyle

"David Wegener" <wegener@cboenospam.com> wrote in message
news:fbq6l5$dno$1@build.eclipse.org...
> Robert Konigsberg wrote:
>> Hi there,
>>
>> At work we are considering using the java.util.logging package to be
>> responsible for all our logging, and add a custom handler to send all our
>> logged messages to the Eclipse ILogs.
>>
>> Is this something people already do, and if so, what have they learned
>> about it? Can someone advise about abstraction incompatibilities
>> (incompatible logging levels, for instance), startup / BundleContext
>> issues, et cetera?
>>
>> Thanks for your help!
>>
>> Robert
> Check out the following link on the Developer Works web site. It is a
> little old, but should still be relevant and will at least get you
> started.
>
> http://www.ibm.com/developerworks/opensource/library/os-eclo g/
Re: Using java.util.logging to wrap the Eclipse logger [message #320005 is a reply to message #319979] Sat, 08 September 2007 05:53 Go to previous messageGo to next message
Eclipse UserFriend
Yes, we are using the same approach. Logging from the Core API's to
java.util.logging. In the Core API's we do not have any dependencies to
Eclipse packages.

To bring the logged Errors on top, we are using a Handler that passes
log events to the Eclipse ILog. This way we easily can show error
messages coming from the core parts of the API within the UI (using the
PDE Log View from the org.eclipse.pde.runtime Plugin).

One drawback: the custom handler cannot be added through the logger
properties file - cause java.util.logging is doing the class loading
stuff pretty bad. You have to add the handler explicitly from your
Plugin code:

Logger.getLogger("").addHandler(new PluginLogDelegateHandler());

Here is my Handler class:

public class PluginLogDelegateHandler extends Handler {

public void close() throws SecurityException {
}

public void flush() {
}

public void publish(LogRecord record) {
if (record.getLevel() == Level.SEVERE) {
Throwable t = record.getThrown();
String message = record.getMessage();

try {
if (record.getMessage() != null)
message = MessageFormat.format(record.getMessage(),
record
.getParameters());
} catch (Throwable e) {
e.printStackTrace();
}

if (t != null) {
if (t.getMessage() != null)
message = t.getMessage();
}

if (message == null)
message = "Fehler in " + record.getLoggerName();
final Status s = new Status(IStatus.ERROR,
record.getLoggerName(),
IStatus.ERROR, message, record.getThrown());
Bundle bundle = Platform.getBundle(record.getLoggerName());
if (bundle == null)
bundle = UiPlugin.getDefault().getBundle();
final Bundle fBundle = bundle;

Display.getDefault().asyncExec(new Runnable() {
public void run() {
try {

PlatformUI.getWorkbench().getActiveWorkbenchWindow()
.getActivePage().showView(
"org.eclipse.pde.runtime.LogView");
} catch (Throwable e) {
// ignorieren
}
Platform.getLog(fBundle).log(s);
}
});

}
}

}


Regards, Alex


Robert Konigsberg schrieb:
> Hi there,
>
> At work we are considering using the java.util.logging package to be
> responsible for all our logging, and add a custom handler to send all
> our logged messages to the Eclipse ILogs.
>
> Is this something people already do, and if so, what have they learned
> about it? Can someone advise about abstraction incompatibilities
> (incompatible logging levels, for instance), startup / BundleContext
> issues, et cetera?
>
> Thanks for your help!
>
> Robert
Re: Using java.util.logging to wrap the Eclipse logger [message #320369 is a reply to message #320005] Tue, 18 September 2007 13:38 Go to previous message
Eclipse UserFriend
Originally posted by: rob.brainkandy-dot-org.org

Thank you all for your help!

Alexander Karnstedt wrote:
> Yes, we are using the same approach. Logging from the Core API's to
> java.util.logging. In the Core API's we do not have any dependencies to
> Eclipse packages.
>
> To bring the logged Errors on top, we are using a Handler that passes
> log events to the Eclipse ILog. This way we easily can show error
> messages coming from the core parts of the API within the UI (using the
> PDE Log View from the org.eclipse.pde.runtime Plugin).
>
> One drawback: the custom handler cannot be added through the logger
> properties file - cause java.util.logging is doing the class loading
> stuff pretty bad. You have to add the handler explicitly from your
> Plugin code:
>
> Logger.getLogger("").addHandler(new PluginLogDelegateHandler());
>
> Here is my Handler class:
>
> public class PluginLogDelegateHandler extends Handler {
>
> public void close() throws SecurityException {
> }
>
> public void flush() {
> }
>
> public void publish(LogRecord record) {
> if (record.getLevel() == Level.SEVERE) {
> Throwable t = record.getThrown();
> String message = record.getMessage();
>
> try {
> if (record.getMessage() != null)
> message = MessageFormat.format(record.getMessage(),
> record
> .getParameters());
> } catch (Throwable e) {
> e.printStackTrace();
> }
>
> if (t != null) {
> if (t.getMessage() != null)
> message = t.getMessage();
> }
>
> if (message == null)
> message = "Fehler in " + record.getLoggerName();
> final Status s = new Status(IStatus.ERROR,
> record.getLoggerName(),
> IStatus.ERROR, message, record.getThrown());
> Bundle bundle = Platform.getBundle(record.getLoggerName());
> if (bundle == null)
> bundle = UiPlugin.getDefault().getBundle();
> final Bundle fBundle = bundle;
>
> Display.getDefault().asyncExec(new Runnable() {
> public void run() {
> try {
>
> PlatformUI.getWorkbench().getActiveWorkbenchWindow()
> .getActivePage().showView(
> "org.eclipse.pde.runtime.LogView");
> } catch (Throwable e) {
> // ignorieren
> }
> Platform.getLog(fBundle).log(s);
> }
> });
>
> }
> }
>
> }
>
>
> Regards, Alex
>
>
> Robert Konigsberg schrieb:
>
>> Hi there,
>>
>> At work we are considering using the java.util.logging package to be
>> responsible for all our logging, and add a custom handler to send all
>> our logged messages to the Eclipse ILogs.
>>
>> Is this something people already do, and if so, what have they learned
>> about it? Can someone advise about abstraction incompatibilities
>> (incompatible logging levels, for instance), startup / BundleContext
>> issues, et cetera?
>>
>> Thanks for your help!
>>
>> Robert
Previous Topic:IProject#open() causes OutOfMemoryError?
Next Topic:Organize favorites regression?
Goto Forum:
  


Current Time: Tue Jul 15 22:11:27 EDT 2025

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

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

Back to the top