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 21:08 |
Eclipse User |
|
|
|
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] |
Fri, 07 September 2007 00:40 |
Eclipse User |
|
|
|
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] |
Sat, 08 September 2007 02:37 |
David Kyle Messages: 125 Registered: July 2009 |
Senior Member |
|
|
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 09:53 |
Alexander Karnstedt Messages: 68 Registered: July 2009 |
Member |
|
|
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 17:38 |
Eclipse User |
|
|
|
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
|
|
|
Goto Forum:
Current Time: Fri Sep 27 03:40:40 GMT 2024
Powered by FUDForum. Page generated in 0.03435 seconds
|