Reputation: 2314
When I am catching an exception that I have thrown, what is the proper logging of that exception? I know the user can see the "error log" view in eclipse.
Here are a couple different ways that I can log... Not sure which is the best and what exactly the user will see when I log it this way.
Activator.getDefault().log(e.getMessage(), e);
In each catch clause,
I can log the information with the Activator that is associated with
the plug-ins ID. Are there betters way to log the error in eclipse?
Upvotes: 6
Views: 3727
Reputation: 111217
Printing the stack trace will not go in the error log, it will just be lost (except when running from within Eclipse or with a console).
The Activator
based logging is the usual way to log. The code logging provided by the Plugin
or AbstractUIPlugin
class is:
ILog log = Activator.getDefault().getLog();
log.log(new Status(....));
Status
has a number of different constructors depending on exactly what you want to log. For example:
new Status(IStatus.ERROR, ID, errorNumber, message, exception);
new Status(IStatus.ERROR, message, exception);
Activator
is the class defined as the plug-in activator in the Bundle-Activator
in the plug-in's MANIFEST.MF.
If the plug-in does not have an activator you can get get the ILog
using:
ILog log = Platform.getLog(getClass());
or
ILog log = Platform.getLog(bundle);
where bundle
is the Bundle
for the plug-in.
Upvotes: 10