]>
code.delx.au - pymsnt/blob - src/debug.py
d284ee9da0ef81090d9da1bf334a8e14c2f7e15d
1 # Copyright 2004 James Bunton <james@delx.cjb.net>
2 # Licensed for distribution under the GPL version 2, check COPYING for details
10 """ A simple logging module. Use as follows.
13 > debug.log("text string")
15 If debugging is enabled then the data will be dumped to a file
16 or the screen (whichever the user chose)
22 if(config
.debugSmart
):
23 rollingStack
= utils
.RollingStack(100)
26 def reopenFile(first
=False):
29 if(file): file.close()
32 file = open(utils
.doPath(config
.debugLog
), 'a')
34 print "Error opening debug log file. Exiting..."
38 def flushDebugSmart():
40 if(config
.debugSmart
):
41 file.write(rollingStack
.grabAll())
47 if(len(config
.debugLog
) > 0):
49 def log(data
, wtime
=True):
52 text
+= time
.strftime("%D - %H:%M:%S - ")
53 text
+= utils
.latin1(data
) + "\n"
54 if(config
.debugSmart
):
55 rollingStack
.push(text
)
60 def log(data
, wtime
=True):
62 print time
.strftime("%D - %H:%M:%S - "),
63 print utils
.latin1(data
)
65 log("Debug logging enabled.")
72 # So that I can pass this module to twisted.python.failure.Failure.printDetailedTraceback() as a file