简体   繁体   English

Eclipse PDE日志记录

[英]Eclipse PDE Logging

I want to send the exceptions of my plugin to the Error Log, but I don't want them to be shown in the Eclipse console. 我想将我的插件的异常发送到错误日志,但我不希望它们在Eclipse控制台中显示。 This is what I am doing. 这就是我在做的事情。

First, I implemented ILogListener. 首先,我实现了ILogListener。

public class MyILogListener implements ILogListener {

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

    }

}

I have this sample Action to do the test. 我有这个示例Action来进行测试。

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));


    }

}

The exception is written in the Error Log of the Eclipse aplication and this is shown in the console. 异常写在Eclipse应用程序的错误日志中,并在控制台中显示。

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)

logging: org.eclipse.core.runtime logging:org.eclipse.core.runtime

You can see the MyILogListener is printing "org.eclipse.core.runtime", I thought it would print my plugin ID, which is "Test". 你可以看到MyILogListener正在打印“org.eclipse.core.runtime”,我以为它会打印我的插件ID,即“Test”。 Also, in my implementation I'm not writing anything to the log, but the exception appears in the Error Log. 此外,在我的实现中,我没有在日志中写任何内容,但错误日志中出现异常。 I only want to write the exception in the Error Log, and not show it in the console. 我只想在错误日志中编写异常,而不是在控制台中显示它。

What I am doing wrong? 我做错了什么? I'm trying this with Eclipse 3.7.0 and 3.7.1. 我正在尝试使用Eclipse 3.7.0和3.7.1。

According to Eclipse 3.7 documentation : 根据Eclipse 3.7文档

All eclipse logging APIs are now aggregated through the org.eclipse.equinox.log.Logger with the name org.eclipse.equinox.logger. 现在,所有eclipse日志API都通过org.eclipse.equinox.log.Logger与名称org.eclipse.equinox.logger进行聚合。 All ILogListener instances will be notified of entries logged through this logger. 将通过此记录器通知所有ILogListener实例。

This means that by logging to a bundle's log a bunch of listeners will be notified, one of them being Eclipse StatusManager which logs the status to error log. 这意味着通过记录到包的日志,将通知一堆侦听器,其中一个是Eclipse StatusManager ,它将状态记录到错误日志中。

If you only want to log to Eclipse error log (and Error Log view) then you should call one of StatusManager.handle() methods directly. 如果您只想登录Eclipse错误日志(和错误日志视图),那么您应该直接调用其中一个StatusManager.handle()方法。

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

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