Search in sources :

Example 1 with SharedCorePlugin

use of org.python.pydev.shared_core.SharedCorePlugin in project Pydev by fabioz.

the class Log method log.

/**
 * @param errorLevel IStatus.[OK|INFO|WARNING|ERROR]
 * @return CoreException that can be thrown for the given log event
 */
public static CoreException log(int errorLevel, String message, Throwable e) {
    final String id;
    if (SharedCorePlugin.inTestMode()) {
        id = "SharedCorePlugin";
    } else {
        SharedCorePlugin plugin = SharedCorePlugin.getDefault();
        id = plugin.getBundle().getSymbolicName();
    }
    Status s = new Status(errorLevel, id, errorLevel, message, e);
    CoreException coreException = new CoreException(s);
    Tuple<Integer, String> key = new Tuple<Integer, String>(errorLevel, message);
    synchronized (lastLoggedTime) {
        Long lastLoggedMillis = lastLoggedTime.get(key);
        long currentTimeMillis = System.currentTimeMillis();
        if (lastLoggedMillis != null) {
            if (currentTimeMillis < lastLoggedMillis + (20 * 1000)) {
                // Logged in the last 20 seconds, so, just skip it for now
                return coreException;
            }
        }
        lastLoggedTime.put(key, currentTimeMillis);
    }
    try {
        if (SharedCorePlugin.inTestMode()) {
            if (DEBUG_LEVEL <= errorLevel) {
                System.err.println(message);
                if (e != null) {
                    e.printStackTrace();
                }
            }
        } else {
            SharedCorePlugin plugin = SharedCorePlugin.getDefault();
            plugin.getLog().log(s);
        }
    } catch (Exception e1) {
    // logging should not fail!
    }
    return coreException;
}
Also used : IStatus(org.eclipse.core.runtime.IStatus) Status(org.eclipse.core.runtime.Status) CoreException(org.eclipse.core.runtime.CoreException) Tuple(org.python.pydev.shared_core.structure.Tuple) CoreException(org.eclipse.core.runtime.CoreException) SharedCorePlugin(org.python.pydev.shared_core.SharedCorePlugin)

Aggregations

CoreException (org.eclipse.core.runtime.CoreException)1 IStatus (org.eclipse.core.runtime.IStatus)1 Status (org.eclipse.core.runtime.Status)1 SharedCorePlugin (org.python.pydev.shared_core.SharedCorePlugin)1 Tuple (org.python.pydev.shared_core.structure.Tuple)1