Showing posts with label log listener. Show all posts
Showing posts with label log listener. Show all posts

Thursday, November 19, 2015

How to listen to Eclipse Log errors

Register a listener in your Core Plugin startup:

Platform.addLogListener(new MyLogListener());

Listen to the log:

import org.eclipse.core.runtime.ILogListener;
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.core.runtime.IStatus;
import org.eclipse.core.runtime.Status;
import org.eclipse.core.runtime.jobs.Job;

public class MyLogListener implements ILogListener
{

@Override
public void logging(IStatus status, String plugin)
{
if (status.getCode() == IStatus.ERROR)
{
startJob(status);
}
}

private void startJob(final IStatus status)
{
Job job = new Job("Reporting error...")
{
@Override
protected IStatus run(IProgressMonitor monitor)
{
System.out.println("===============Studio error reporting starts==============");
String ticketMessage = status.getMessage();
System.out.println(ticketMessage);
Throwable exception = status.getException();
exception.printStackTrace();
 System.out.println("===============Studio error reporting ends==============");
return null;
}
};
job.schedule();
}

}