添加auto_log装饰器
This commit is contained in:
parent
74f6b737cb
commit
bad884ce26
|
@ -0,0 +1,19 @@
|
|||
import logging
|
||||
from functools import wraps
|
||||
|
||||
myLogger = logging.getLogger('log')
|
||||
|
||||
|
||||
def auto_log(name='', raise_exception=False):
|
||||
def decorate(func):
|
||||
@wraps(func)
|
||||
def wrapper(*args, **kwargs):
|
||||
try:
|
||||
real_func = func(*args, **kwargs)
|
||||
return real_func
|
||||
except Exception as e:
|
||||
myLogger.error(name, exc_info=True)
|
||||
if raise_exception:
|
||||
raise
|
||||
return wrapper
|
||||
return decorate
|
Loading…
Reference in New Issue