X-Git-Url: http://git.maemo.org/git/?a=blobdiff_plain;f=src%2Futil%2Fmisc.py;h=69a5b0986e5c53c4bd9f67131b31749c2c296ef4;hb=96110c9e22eb2fd87963853d7045256dcacae19b;hp=ba5f5062583b3dbfff5082eba5bfc9d68e09e8b5;hpb=d5e83934d71da982e8a0b671254dd0be4ee87838;p=theonering diff --git a/src/util/misc.py b/src/util/misc.py index ba5f506..69a5b09 100644 --- a/src/util/misc.py +++ b/src/util/misc.py @@ -16,6 +16,45 @@ import warnings import string +_indentationLevel = [0] + + +def log_call(logger): + + def log_call_decorator(func): + + @functools.wraps(func) + def wrapper(*args, **kwds): + logger.debug("%s> %s" % (" " * _indentationLevel[0], func.__name__, )) + _indentationLevel[0] += 1 + try: + return func(*args, **kwds) + finally: + _indentationLevel[0] -= 1 + logger.debug("%s< %s" % (" " * _indentationLevel[0], func.__name__, )) + + return wrapper + + return log_call_decorator + + +def log_exception(logger): + + def log_exception_decorator(func): + + @functools.wraps(func) + def wrapper(*args, **kwds): + try: + return func(*args, **kwds) + except Exception: + logger.exception(func.__name__) + raise + + return wrapper + + return log_exception_decorator + + def printfmt(template): """ This hides having to create the Template object and call substitute/safe_substitute on it. For example: