]> code.delx.au - pymsnt/blobdiff - src/debug.py
Major changes. Moved everything away from twistd and .tac files. Its nicer this way...
[pymsnt] / src / debug.py
index 284c85ca0abd1617f71d993c098046ebfb78f577..fdabb20f4439ab882c6dd5f9c8eb65c61ececf28 100644 (file)
@@ -2,12 +2,19 @@
 # Licensed for distribution under the GPL version 2, check COPYING for details
 
 from twisted.python import log
-import sys
+import sys, time
 
 import config
 
 
 def observer(eventDict):
+       try:
+               observer2(eventDict)
+       except Exception, e:
+               printf("CRITICAL: Traceback in debug.observer2 - " + str(e))
+
+
+def observer2(eventDict):
        edm = eventDict['message']
        if isinstance(edm, LogEvent):
                if edm.category == INFO and config.debugLevel < 3:
@@ -29,11 +36,15 @@ def observer(eventDict):
                        return
        
        # Now log it!
-       timeStr = time.strftime(self.timeFormat, time.localtime(eventDict['time']))
+       timeStr = time.strftime("[%Y-%m-%d %H:%M:%S]", time.localtime(eventDict['time']))
        text = text.replace("\n", "\n\t")
        global debugFile
-       debugFile.write(timeStr + msgStr)
+       debugFile.write("%s %s\n" % (timeStr, text))
+       debugFile.flush()
        
+def printf(text):
+       sys.__stdout__.write(text + "\n")
+       sys.__stdout__.flush()
 
 debugFile = None
 def reloadConfig():