假设我在文件log.py中有两个装饰器函数
def timeit(logger, level = 'DEBUG'):
def timeit_decorator(method):
def timeit_wrapper(*args, **kw):
ts = time.time()
result = method(*args, **kw)
te = time.time()
logger.log(logging.getLevelName(level), '%2.4f sec' % (te - ts), extra = dict(filename = method.__code__.co_filename, funcName = method.__code__.co_name))
return result
return timeit_wrapper
return timeit_decorator
我有一个文件test.py有一个函数,它使用像这样的装饰器,
@timeit(logger = LOGGER)
@logargs(logger = LOGGER)
def test(arg1 = 'something'):
pass
当我运行test.py其中一个装饰器打印模块时,func& lineno as [test.py:7 - test()] 和其他一个打印像[log.py:6 - timeit_wrapper()]
如何使装饰器同时打印实际方法,模块和& lineno是[test.py:7 - test()]