-import config
-import utils
-import time
-
-""" A simple logging module. Use as follows.
-
-> import debug
-> debug.log("text string")
-
-If debugging is enabled then the data will be dumped to a file
-or the screen (whichever the user chose)
-"""
-
-
-file = None
-rollingStack = None
-if(config.debugSmart):
- rollingStack = utils.RollingStack(100)
-
-
-def reopenFile(first=False):
- global file
- if(file or first):
- if(file): file.close()
-
- try:
- file = open(utils.doPath(config.debugLog), 'a')
- except:
- print "Error opening debug log file. Exiting..."
- os.abort()
-
-
-def flushDebugSmart():
- global rollingStack
- if(config.debugSmart):
- file.write(rollingStack.grabAll())
- rollingStack.flush()
- file.flush()
-
-
-if(config.debugOn):
- if(len(config.debugLog) > 0):
- reopenFile(True)
- def log(data, wtime=True):
- text = ""
- if(wtime):
- text += time.strftime("%D - %H:%M:%S - ")
- text += utils.latin1(data) + "\n"
- if(config.debugSmart):
- rollingStack.push(text)
- else:
- file.write(text)
- file.flush()
- else:
- def log(data, wtime=True):
- if(wtime):
- print time.strftime("%D - %H:%M:%S - "),
- print utils.latin1(data)
- sys.stdout.flush()
- log("Debug logging enabled.")
-else:
- def log(data):
- pass
-
-
-def write(data):
- # So that I can pass this module to twisted.python.failure.Failure.printDetailedTraceback() as a file
- data = data.rstrip()
- log(data)