简体   繁体   English

正确记录Eclipse插件开发

[英]Proper Logging for Eclipse plug-in development

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. 我知道用户可以在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. 以下是我可以记录的几种不同方式...不确定哪种方式最好,用户在以这种方式记录时会看到什么。

  1. Simply print the stack trace. 只需打印堆栈跟踪即可。 Will this show in the "error log" view? 这会在“错误日志”视图中显示吗?
  2. 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. 在每个catch子句中,我可以使用与插件ID关联的Activator记录信息。

Are there betters way to log the error in eclipse? 是否有更好的方法来记录eclipse中的错误?

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). 打印堆栈跟踪不会进入错误日志,只会丢失(除非在Eclipse或控制台中运行)。

The Activator based logging is the usual way to log. 基于Activator的日志记录是记录的常用方法。 The code logging provided by the Plugin or AbstractUIPlugin class is: PluginAbstractUIPlugin类提供的代码记录是:

ILog log = Activator.getDefault().getLog();

log.log(new Status(....));

Status has a number of different constructors depending on exactly what you want to log. Status具有许多不同的构造函数,具体取决于您要记录的内容。 For example: 例如:

new Status(IStatus.ERROR, ID, errorNumber, message, exception);

new Status(IStatus.ERROR, message, exception);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM