File tree Expand file tree Collapse file tree 2 files changed +5
-8
lines changed Expand file tree Collapse file tree 2 files changed +5
-8
lines changed Original file line number Diff line number Diff line change 66
77from loguru import logger
88
9- from backend .common .context import ctx
109from backend .core .conf import settings
1110from backend .core .path_conf import LOG_DIR
1211from backend .utils .timezone import timezone
@@ -78,12 +77,8 @@ def setup_logging() -> None:
7877
7978 # request_id 过滤器
8079 def request_id_filter (record : logging .LogRecord ) -> logging .LogRecord :
81- if ctx .exists ():
82- rid = get_request_trace_id ()
83- record ['request_id' ] = rid [: settings .TRACE_ID_LOG_LENGTH ]
84- else :
85- record ['request_id' ] = settings .TRACE_ID_LOG_DEFAULT_VALUE
86-
80+ rid = get_request_trace_id ()
81+ record ['request_id' ] = rid [: settings .TRACE_ID_LOG_LENGTH ]
8782 return record
8883
8984 # 配置 loguru 处理器
Original file line number Diff line number Diff line change 44
55def get_request_trace_id () -> str :
66 """从请求头中获取追踪 ID"""
7- return ctx .get (settings .TRACE_ID_REQUEST_HEADER_KEY , settings .TRACE_ID_LOG_DEFAULT_VALUE )
7+ if ctx .exists ():
8+ return ctx .get (settings .TRACE_ID_REQUEST_HEADER_KEY , settings .TRACE_ID_LOG_DEFAULT_VALUE )
9+ return settings .TRACE_ID_LOG_DEFAULT_VALUE
You can’t perform that action at this time.
0 commit comments