首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Eclipse PDE日志记录

Eclipse PDE日志记录
EN

Stack Overflow用户
提问于 2011-11-14 22:09:33
回答 1查看 3.5K关注 0票数 3

我希望将插件的异常发送到Error Log,但我不希望它们显示在Eclipse控制台中。这就是我正在做的事情。

首先,我实现了ILogListener。

代码语言:javascript
复制
public class MyILogListener implements ILogListener {

    @Override
    public void logging(IStatus status, String plugin) {
        System.out.println("logging: " + plugin);

    }

}

我有这个样例Action来做测试。

代码语言:javascript
复制
public void run(IAction action) {

    ILogListener iL = new MyILogListener();
    Platform.addLogListener(iL);

    Bundle bundle = Platform.getBundle(test.Activator.PLUGIN_ID);
    ILog log = Platform.getLog(bundle);
    Object o = null;
    try {
        o.equals("sk");
    } catch (Exception e) {
        log.log(new Status(Status.ERROR, test.Activator.PLUGIN_ID, "test", e));


    }

}

异常被写在Eclipse应用程序的错误日志中,并显示在控制台中。

代码语言:javascript
复制
java.lang.NullPointerException
at test.actions.SampleAction.run(SampleAction.java:52)
at org.eclipse.ui.internal.PluginAction.runWithEvent(PluginAction.java:251)
at org.eclipse.ui.internal.WWinPluginAction.runWithEvent(WWinPluginAction.java:229)
at org.eclipse.jface.action.ActionContributionItem.handleWidgetSelection(ActionContributionItem.java:584)
at org.eclipse.jface.action.ActionContributionItem.access$2(ActionContributionItem.java:501)
at org.eclipse.jface.action.ActionContributionItem$5.handleEvent(ActionContributionItem.java:411)
at org.eclipse.swt.widgets.EventTable.sendEvent(EventTable.java:84)
at org.eclipse.swt.widgets.Widget.sendEvent(Widget.java:1258)
at org.eclipse.swt.widgets.Display.runDeferredEvents(Display.java:3588)
at org.eclipse.swt.widgets.Display.readAndDispatch(Display.java:3209)
at org.eclipse.ui.internal.Workbench.runEventLoop(Workbench.java:2696)
at org.eclipse.ui.internal.Workbench.runUI(Workbench.java:2660)
at org.eclipse.ui.internal.Workbench.access$4(Workbench.java:2494)
at org.eclipse.ui.internal.Workbench$7.run(Workbench.java:674)
at org.eclipse.core.databinding.observable.Realm.runWithDefault(Realm.java:332)
at org.eclipse.ui.internal.Workbench.createAndRunWorkbench(Workbench.java:667)
at org.eclipse.ui.PlatformUI.createAndRunWorkbench(PlatformUI.java:149)
at org.eclipse.ui.internal.ide.application.IDEApplication.start(IDEApplication.java:123)
at org.eclipse.equinox.internal.app.EclipseAppHandle.run(EclipseAppHandle.java:196)
at org.eclipse.core.runtime.internal.adaptor.EclipseAppLauncher.runApplication(EclipseAppLauncher.java:110)
at org.eclipse.core.runtime.internal.adaptor.EclipseAppLauncher.start(EclipseAppLauncher.java:79)
at org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseStarter.java:344)
at org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseStarter.java:179)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:616)
at org.eclipse.equinox.launcher.Main.invokeFramework(Main.java:622)
at org.eclipse.equinox.launcher.Main.basicRun(Main.java:577)
at org.eclipse.equinox.launcher.Main.run(Main.java:1410)
at org.eclipse.equinox.launcher.Main.main(Main.java:1386)

日志记录: org.eclipse.core.runtime

你可以看到MyILogListener正在打印"org.eclipse.core.runtime",我还以为它会打印我的插件ID,也就是"Test“。此外,在我的实现中,我没有向日志中写入任何内容,但异常出现在错误日志中。我只想在错误日志中写入异常,而不是在控制台中显示它。

我做错了什么?我在Eclipse 3.7.0和3.7.1中尝试了这一点。

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2011-11-15 15:22:41

根据Eclipse 3.7 documentation的说法

所有eclipse日志记录API现在都通过名为org.eclipse.equinox.logger的org.eclipse.equinox.log.Logger进行聚合。所有ILogListener实例都将收到通过此记录器记录的条目的通知。

这意味着通过将日志记录到包的日志中,将通知一组侦听器,其中之一是将状态记录到错误日志的Eclipse。

如果您只想记录到Eclipse error log (和Error log视图),那么您应该直接调用一个StatusManager.handle()方法。

票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/8122787

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档