]> code.delx.au - pymsnt/blob - src/debug.py
Reverted a change that broke challenges.
[pymsnt] / src / debug.py
1 # Copyright 2004-2005 James Bunton <james@delx.cjb.net>
2 # Licensed for distribution under the GPL version 2, check COPYING for details
3
4 from twisted.python import log
5 import sys
6
7 class INFO : pass
8 class WARN : pass
9 class ERROR: pass
10
11 class LogEvent:
12 def __init__(self, category=INFO, ident="", msg="", log=True):
13 self.category, self.ident, self.msg = category, ident, msg
14 frame = sys._getframe(1)
15 self.klass = frame.f_locals.get("self", frame.f_code.co_filename)
16 self.method = frame.f_code.co_name
17 self.args = frame.f_locals
18 if log:
19 self.log()
20
21 def __str__(self):
22 args = {}
23 for key in self.args.keys():
24 val = self.args[key]
25 args[key] = val
26 try:
27 if len(val) > 128:
28 args[key] = "Oversize arg"
29 except:
30 # If its not an object with length, assume that it can't be too big. Hope that's a good assumption.
31 pass
32 category = str(self.category).split(".")[1]
33 return "%s :: %s :: %s :: %s :: %s :: %s" % (category, str(self.ident), self.msg, self.method, str(self.klass), str(args))
34
35 def log(self):
36 log.msg(self)
37