commit-gnue
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

gnue/gnue-common/gnue/common GDebug.py


From: Jason Cater
Subject: gnue/gnue-common/gnue/common GDebug.py
Date: Fri, 11 May 2001 11:56:37 -0700

CVSROOT:        /home/cvs
Module name:    gnue
Changes by:     Jason Cater <address@hidden>    01/05/11 11:56:35

Modified files:
        gnue-common/gnue/common: GDebug.py 

Log message:
        Completed GDebug.py so that it handles traces, exceptions, and writing 
to log files. Will be used transparently by new GClientApp class. Note that 
this file is not exactly the same as GFDebug, although this file supercedes 
GFDebug.  The printMesg works the same. However, to set the log file and 
debugging level, run GDebug.setDebug(level, file).  If file==None then stderr 
is used.

CVSWeb URLs:
http://savannah.gnu.org/cgi-bin/viewcvs/gnue/gnue-common/gnue/common/GDebug.py.diff?cvsroot=OldCVS&tr1=1.1&tr2=1.2&r1=text&r2=text

Patches:
Index: gnue/gnue-common/gnue/common/GDebug.py
diff -u gnue/gnue-common/gnue/common/GDebug.py:1.1 
gnue/gnue-common/gnue/common/GDebug.py:1.2
--- gnue/gnue-common/gnue/common/GDebug.py:1.1  Tue Apr 24 19:12:52 2001
+++ gnue/gnue-common/gnue/common/GDebug.py      Fri May 11 11:56:35 2001
@@ -22,18 +22,81 @@
 # GDebug.py
 #
 # DESCRIPTION:
-# Class used for debugging
+# Intelligently handles traces and exception handling for Client Apps
 #
 # NOTES:
 #
 # HISTORY:
 #
 
-# This needs to be modified to do all that GFDebug does. 
-# This was a kwik hack!
+import string
+import sys
+from traceback import format_exception
 
-LEVEL = 0
+_fh = sys.__stderr__
+_conttest = 0
+_DEBUG_LEVEL = 0
 
-def printMesg(level, message): 
-  if level >= LEVEL: 
-     print "DB%3d: %s" % (level, message)
+class _stderrcatcher:
+    def write(self, str):
+        global _fh, _conttest
+        for ch in str:
+            if (_conttest == 0):
+                _fh.write("DB000: ")
+                _conttest = 1
+            if ( ch != '\n'):
+                _fh.write(ch)
+            else:
+                _fh.write('\n')
+                _conttest = 0
+
+    def writelines(self, list):
+        for line in list:
+            self.write(str)
+
+
+def setDebug (level, file=None): 
+  global _DEBUG_LEVEL
+  _DEBUG_LEVEL = level
+  if (file): 
+    fh = open( file, 'w' )
+    catchStderr( fh )
+  else:
+    catchStderr( sys.__stderr__ )
+     
+
+def catchStderr(fh):
+    global _fh
+    _fh = fh
+    sys.stderr = _stderrcatcher()
+
+
+def handleException(exc_info):
+    #
+    # Not used at present
+    #
+    type, exception, traceback = exc_info
+    if (isinstance(exception, GETrace) ):
+        printMesg( exception.level, exception.message)
+    elif (not isinstance(exception, SystemExit)):
+        strings = format_exception(type, exception, traceback)
+        text = string.join(strings, '')
+        printMesg(0, text)
+
+def printMesg(level, message):
+    global _fh
+    if ( int(level) <= int(_DEBUG_LEVEL) ):
+        lines = string.split(message, '\n')
+        for line in lines:
+            _fh.write("DB%03d: %s\n"%(level, line))
+
+class GETrace(Exception):
+    #
+    #Exception class representing a debug message
+    #not yet used for anything and probably won't be :)
+    #
+    def __init__(self, level=0, message="Trace Message"):
+        Exception.__init__(self)
+        self.level = level
+        self.message = message
+



reply via email to

[Prev in Thread] Current Thread [Next in Thread]