]> code.delx.au - pymsnt/commitdiff
Major changes. Moved everything away from twistd and .tac files. Its nicer this way...
authorjamesbunton <jamesbunton@55fbd22a-6204-0410-b2f0-b6c764c7e90a>
Tue, 24 Jan 2006 05:53:38 +0000 (05:53 +0000)
committerjamesbunton <jamesbunton@55fbd22a-6204-0410-b2f0-b6c764c7e90a>
Tue, 24 Jan 2006 05:53:38 +0000 (05:53 +0000)
git-svn-id: http://delx.cjb.net/svn/pymsnt/trunk@101 55fbd22a-6204-0410-b2f0-b6c764c7e90a

committer: jamesbunton <jamesbunton@55fbd22a-6204-0410-b2f0-b6c764c7e90a>

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():