def debug(fn):
"""
Function/method decorator to trace calls via debug logging.
Is a pass-thru if we're not at LOG_LEVEL=DEBUG. Normally this
would have a lot of perf impact but this application doesn't
have significant throughput.
"""
@wraps(fn)
def wrapper(*args, **kwargs):
try:
# because we have concurrent processes running we want
# to tag each stack with an identifier for that process
arg = "[{}]".format(sys.argv[1])
except IndexError:
arg = "[pre_start]"
name = '{}{}{}'.format(arg, (len(inspect.stack()) * " "), fn.__name__)
log.debug('%s' % name)
out = apply(fn, args, kwargs)
log.debug('%s: %s', name, out)
return out
return wrapper
评论列表
文章目录