[Pydev-cvs] org.python.pydev.core/src/org/python/pydev/core/log Log.java, 1.10, 1.11
Brought to you by:
fabioz
From: Fabio Z. <fa...@us...> - 2008-10-03 00:43:43
|
Update of /cvsroot/pydev/org.python.pydev.core/src/org/python/pydev/core/log In directory ddv4jf1.ch3.sourceforge.com:/tmp/cvs-serv10014/src/org/python/pydev/core/log Modified Files: Log.java Log Message: Synching with aptana svn repo for release 1.3.22 (see http://pydev.sourceforge.net/developers.html) Index: Log.java =================================================================== RCS file: /cvsroot/pydev/org.python.pydev.core/src/org/python/pydev/core/log/Log.java,v retrieving revision 1.10 retrieving revision 1.11 diff -C2 -d -r1.10 -r1.11 *** Log.java 27 Sep 2008 19:57:34 -0000 1.10 --- Log.java 3 Oct 2008 00:43:38 -0000 1.11 *************** *** 7,16 **** import java.io.PrintStream; - import org.eclipse.core.runtime.IPath; import org.eclipse.core.runtime.IStatus; import org.eclipse.core.runtime.Status; import org.python.pydev.core.CorePlugin; import org.python.pydev.core.FullRepIterable; - import org.python.pydev.core.REF; --- 7,19 ---- import java.io.PrintStream; import org.eclipse.core.runtime.IStatus; import org.eclipse.core.runtime.Status; + import org.eclipse.jface.text.IDocument; + import org.eclipse.swt.widgets.Display; + import org.eclipse.ui.console.ConsolePlugin; + import org.eclipse.ui.console.IConsole; + import org.eclipse.ui.console.MessageConsole; import org.python.pydev.core.CorePlugin; import org.python.pydev.core.FullRepIterable; *************** *** 20,24 **** public class Log { ! /** * @param errorLevel IStatus.[OK|INFO|WARNING|ERROR] --- 23,31 ---- public class Log { ! /** ! * Console used to log contents ! */ ! private static MessageConsole fConsole; ! /** * @param errorLevel IStatus.[OK|INFO|WARNING|ERROR] *************** *** 47,51 **** ! //------------ Log that writes to .metadata/.plugins/org.python.pydev.core/PydevLog.log private final static Object lock = new Object(); --- 54,58 ---- ! //------------ Log that writes to a new console private final static Object lock = new Object(); *************** *** 69,90 **** } ! private synchronized static void toLogFile(String buffer) { ! synchronized(lock){ ! try{ ! CorePlugin default1 = CorePlugin.getDefault(); ! if(default1 == null){ ! //in tests ! System.out.println(buffer); ! return; } ! IPath stateLocation = default1.getStateLocation().append("PydevLog.log"); ! String file = stateLocation.toOSString(); ! REF.appendStrToFile(buffer+"\r\n", file); ! }catch(Throwable e){ ! log(e); //default logging facility } } } public static void toLogFile(Exception e) { String msg = getExceptionStr(e); --- 76,130 ---- } ! private synchronized static void toLogFile(final String buffer) { ! final Runnable r = new Runnable(){ ! ! public void run() { ! synchronized(lock){ ! try{ ! CorePlugin default1 = CorePlugin.getDefault(); ! if(default1 == null){ ! //in tests ! System.out.println(buffer); ! return; ! } ! ! //also print to console ! System.out.println(buffer); ! MessageConsole c = getConsole(); ! IDocument doc = c.getDocument(); ! doc.replace(doc.getLength(), 0, buffer.toString()+"\r\n"); ! ! // IPath stateLocation = default1.getStateLocation().append("PydevLog.log"); ! // String file = stateLocation.toOSString(); ! // REF.appendStrToFile(buffer+"\r\n", file); ! }catch(Throwable e){ ! log(e); //default logging facility ! } } ! ! } ! }; ! ! Display current = Display.getCurrent(); ! if(current != null && current.getThread() == Thread.currentThread ()){ ! //ok, just run it ! r.run(); ! }else{ ! if(current == null){ ! current = Display.getDefault(); ! current.asyncExec(r); } } } + + private static MessageConsole getConsole(){ + if (fConsole == null){ + fConsole = new MessageConsole("Pydev Logging", null); + ConsolePlugin.getDefault().getConsoleManager().addConsoles(new IConsole[]{fConsole}); + } + return fConsole; + } + public static void toLogFile(Exception e) { String msg = getExceptionStr(e); |