I want to send my plugin exceptions to the error log, but I do not want them to be displayed in the Eclipse console. This is what I do.
Firstly, I implemented ILogListener.
public class MyILogListener implements ILogListener { @Override public void logging(IStatus status, String plugin) { System.out.println("logging: " + plugin); } }
I have this example Action to run a test.
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 to the error log in the Eclipse application and this is displayed on the console.
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
You can see that MyILogListener prints "org.eclipse.core.runtime", I thought it would print my plugin id, which is "Test". In addition, in my implementation, I do not write anything to the log, but an exception appears in the error log. I want to write an exception in the error log, and not show it in the console.
What am I doing wrong? I try this with Eclipse 3.7.0 and 3.7.1.
source share