Issue
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.
- Simply print the stack trace. Will this show in the "error log" view?
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?
Solution
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.
Answered By - greg-449
Answer Checked By - Dawn Plyler (JavaFixing Volunteer)