def __call__(self, method):
from functools import wraps
@wraps(method)
def timed(*args, **kw):
if self.logger.level <= logging.DEBUG:
ts = time.time()
result = method(*args, **kw)
te = time.time()
print_args = False
if print_args:
self.logger.debug('Ran %r (%s, %r) in %2.2fs' %
(method.__name__,
", ".join(["%s" % (a,) for a in args]),
kw,
te - ts))
else:
self.logger.debug('Ran %r in %2.2fs' %
(method.__name__,
te - ts))
return result
else:
return method(*args, **kw)
return timed
评论列表
文章目录