Permalink
Browse files

addded exception partial support

  • Loading branch information...
1 parent 5106974 commit dd7e558612ee76c98f0d7e3349520d4342be1136 @Nassty committed Mar 26, 2011
Showing with 19 additions and 7 deletions.
  1. +19 −7 fusqlogger.py
View
@@ -1,4 +1,6 @@
from functools import wraps
+import StringIO
+import traceback
class colors:
HEADER = '\033[95m'
@@ -19,6 +21,10 @@ def dump(self, message):
return "%s%s%s" %( colors.HEADER, str(message),
colors.ENDC )
+ def fail(self, message):
+ return "%s%s%s" %( colors.FAIL, str(message),
+ colors.ENDC )
+
def log(skip=False, showReturn=False):
def _log(f):
@wraps(f)
@@ -37,15 +43,24 @@ def handler(*args, **kw):
fun_args += colorize.warn(" {" + ", ".join(["%s => %s"% (x,y) for x,y in
kw.items() ] ) + "}")
- retValue = f(*args, **kw)
+ try:
+ e = False
+ retValue = f(*args, **kw)
+ except Exception, e:
+ lines = traceback.format_exc().splitlines()
+ rep = ['# %s #' % colorize.fail(x.ljust(50, " ")) for x in lines]
+ print "#" * (len(lines[0]) + 24)
+ print "\n".join(rep)
+ print "#" * (len(lines[0]) + 24)
retstr = ""
if showReturn:
retstr = " returned " + colorize.ok(str(retValue))
if not skip:
print "%s%s(%s)%s" % (header, fun_name, fun_args, str(retstr))
-
+ if e:
+ raise e
return retValue
return handler
@@ -54,12 +69,9 @@ def handler(*args, **kw):
def dump(msg):
colorize = colors()
print "[SQL] dumped : %s" % colorize.dump(msg)
+
if __name__ == "__main__":
@log()
def asd(*args, **kw):
- if args:
- dump(" ".join(map(str, args)))
-
- asd(1,2,3,4,5,6,7, asd=1, bsd=2, csd=3)
- asd(asd=1, bsd=2, csd=3)
+ (1,)[1]
asd()

0 comments on commit dd7e558

Please sign in to comment.