Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 0 additions & 8 deletions backend/middleware/access_middleware.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,12 +32,4 @@ async def dispatch(self, request: Request, call_next: RequestResponseEndpoint) -

response = await call_next(request)

if request.method != 'OPTIONS':
log.debug('<-- 请求结束')

log.info(
f'{request.client.host: <15} | {request.method: <8} | {response.status_code: <6} | '
f'{path} | {(time.perf_counter() - perf_time) * 1000:.3f}ms',
)

return response
10 changes: 8 additions & 2 deletions backend/middleware/opera_log_middleware.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ async def dispatch(self, request: Request, call_next: Any) -> Response:
error = None
try:
response = await call_next(request)
elapsed = (time.perf_counter() - ctx.perf_time) * 1000
elapsed = round((time.perf_counter() - ctx.perf_time) * 1000, 3)
for e in [
'__request_http_exception__',
'__request_validation_exception__',
Expand All @@ -65,7 +65,7 @@ async def dispatch(self, request: Request, call_next: Any) -> Response:
log.error(f'请求异常: {msg}')
break
except Exception as e:
elapsed = (time.perf_counter() - ctx.perf_time) * 1000
elapsed = round((time.perf_counter() - ctx.perf_time) * 1000, 3)
code = getattr(e, 'code', StandardResponseCode.HTTP_500) # 兼容 SQLAlchemy 异常用法
msg = getattr(e, 'msg', str(e)) # 不建议使用 traceback 模块获取错误信息,会暴漏代码信息
status = StatusType.disable
Expand All @@ -86,6 +86,12 @@ async def dispatch(self, request: Request, call_next: Any) -> Response:
log.debug(f'接口摘要:[{summary}]')
log.debug(f'请求地址:[{ctx.ip}]')
log.debug(f'请求参数:{args}')
log.info(
f'{request.client.host: <15} | {request.method: <8} | {response.status_code: <6} | '
f'{path} | {elapsed:.3f}ms',
)
if request.method != 'OPTIONS':
log.debug('<-- 请求结束')

# 日志创建
opera_log_in = CreateOperaLogParam(
Expand Down