]> code.delx.au - pymsnt/blobdiff - src/debug.py
Turned off MSN protocol debugging by default.
[pymsnt] / src / debug.py
index fdabb20f4439ab882c6dd5f9c8eb65c61ececf28..74c52cbe10b281c443ebb166ea6a3496771304a1 100644 (file)
@@ -2,6 +2,7 @@
 # Licensed for distribution under the GPL version 2, check COPYING for details
 
 from twisted.python import log
+
 import sys, time
 
 import config
@@ -17,20 +18,20 @@ def observer(eventDict):
 def observer2(eventDict):
        edm = eventDict['message']
        if isinstance(edm, LogEvent):
-               if edm.category == INFO and config.debugLevel < 3:
+               if edm.category == INFO and config._debugLevel < 3:
                        return
-               if (edm.category == WARN or edm.category == ERROR) and config.debugLevel < 2:
+               if (edm.category == WARN or edm.category == ERROR) and config._debugLevel < 2:
                        return
                text = str(edm)
        elif edm:
-               if config.debugLevel < 3: return
+               if config._debugLevel < 3: return
                text = ' '.join(map(str, edm))
        else:
                if eventDict['isError'] and eventDict.has_key('failure'):
-                       if config.debugLevel < 1: return
+                       if config._debugLevel < 1: return
                        text = eventDict['failure'].getTraceback()
                elif eventDict.has_key('format'):
-                       if config.debugLevel < 3: return
+                       if config._debugLevel < 3: return
                        text = eventDict['format'] % eventDict
                else:
                        return
@@ -46,6 +47,7 @@ def printf(text):
        sys.__stdout__.write(text + "\n")
        sys.__stdout__.flush()
 
+
 debugFile = None
 def reloadConfig():
        global debugFile
@@ -53,15 +55,16 @@ def reloadConfig():
                debugFile.close()
        
        try:
-               config.debugLevel = int(config.debugLevel)
+               config._debugLevel = int(config.debugLevel.strip())
        except ValueError:
-               config.debugLevel = 0
+               config._debugLevel = 0
+               config.debugLevel = "0"
 
-       if config.debugLevel > 0:
+       if config._debugLevel > 0:
                if len(config.debugFile) > 0:
                        try:
-                               debugFile = open(config.debugFile, "w")
-                               log.msg("Rewrote log file.")
+                               debugFile = open(config.debugFile, "a")
+                               log.msg("Reopened log file.")
                        except IOError:
                                log.discardLogs() # Give up
                                debugFile = sys.__stdout__
@@ -69,6 +72,10 @@ def reloadConfig():
                else:
                        debugFile = sys.__stdout__
 
+               try:
+                       log.removeObserver(observer)
+               except ValueError:
+                       pass
                log.startLoggingWithObserver(observer)
        else:
                log.discardLogs()