Eclipse RCP - Simple Logging mechanism

Eclipse RCP – Simple Logging mechanism

This is a short snippet to solve you logging needs in Eclipse RCP application by using build in logging functionality.
I have created 3 simple static utility methods but you can create your LogUtil utility class as you wish based on this example:

import org.eclipse.core.runtime.IStatus;
import org.eclipse.core.runtime.Status;

public class LogUtil {

    public static void logError(String msg){
        IStatus st = new Status(IStatus.ERROR,Activator.PLUGIN_ID, msg);
        Activator.getDefault().getLog().log(st);
    }
    public static void logInfo(String msg){
        IStatus st = new Status(IStatus.INFO,Activator.PLUGIN_ID, msg);
        Activator.getDefault().getLog().log(st);
    }
    public static void logWarning(String msg){
        IStatus st = new Status(IStatus.WARNING,Activator.PLUGIN_ID, msg);
        Activator.getDefault().getLog().log(st);
    }
}

Hope that helps someone who was forced to use System.out.println to debug simple RCP plugin applications.

Leave a Reply