添加auto_log装饰器

This commit is contained in:
caoqianming 2023-02-14 11:02:29 +08:00
parent 74f6b737cb
commit bad884ce26
1 changed files with 19 additions and 0 deletions

19
apps/utils/my_log.py Normal file
View File

@ -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