Skip to content

Commit ae9584a

Browse files
committed
perf: 日志装饰器异常处理增加logger打印日志
1 parent 379316b commit ae9584a

File tree

1 file changed

+9
-6
lines changed

1 file changed

+9
-6
lines changed

ruoyi-fastapi-backend/module_admin/annotation/log_annotation.py

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
from config.enums import BusinessType
1717
from config.env import AppConfig
1818
from exceptions.exception import LoginException, ServiceException, ServiceWarning
19+
from utils.log_util import logger
1920
from utils.response_util import ResponseUtil
2021

2122

@@ -116,13 +117,14 @@ async def wrapper(*args, **kwargs):
116117
try:
117118
# 调用原始函数
118119
result = await func(*args, **kwargs)
119-
except LoginException as e:
120+
except (LoginException, ServiceWarning) as e:
121+
logger.warning(e.message)
120122
result = ResponseUtil.failure(data=e.data, msg=e.message)
121123
except ServiceException as e:
124+
logger.error(e.message)
122125
result = ResponseUtil.error(data=e.data, msg=e.message)
123-
except ServiceWarning as e:
124-
result = ResponseUtil.failure(data=e.data, msg=e.message)
125126
except Exception as e:
127+
logger.exception(e)
126128
result = ResponseUtil.error(msg=str(e))
127129
# 获取请求耗时
128130
cost_time = float(time.time() - start_time) * 100
@@ -295,13 +297,14 @@ async def wrapper(*args, **kwargs):
295297
try:
296298
# 调用原始函数
297299
result = await func(*args, **kwargs)
298-
except LoginException as e:
300+
except (LoginException, ServiceWarning) as e:
301+
logger.warning(e.message)
299302
result = ResponseUtil.failure(data=e.data, msg=e.message)
300303
except ServiceException as e:
304+
logger.error(e.message)
301305
result = ResponseUtil.error(data=e.data, msg=e.message)
302-
except ServiceWarning as e:
303-
result = ResponseUtil.failure(data=e.data, msg=e.message)
304306
except Exception as e:
307+
logger.exception(e)
305308
result = ResponseUtil.error(msg=str(e))
306309
# 获取请求耗时
307310
cost_time = float(time.time() - start_time) * 100

0 commit comments

Comments
 (0)