def logging_scope(name, *wargs, **wkwargs):
'''
A decorator to add the decorated function as a new logging scope, with name `name`.
All additional arguments are passed to `StatusLogger._scope_enter`. Current
supported keyword arguments are "timed", in which case when the scope closes,
the duration of the call is shown.
'''
def logging_scope(func, *args, **kwargs):
logger._scope_enter(name, *wargs, **wkwargs)
success = True
try:
f = func(*args, **kwargs)
return f
except Exception as e:
success = False
raise_with_traceback(e)
finally:
logger._scope_exit(success)
return lambda func: decorate(func, logging_scope)
评论列表
文章目录