stage + reservation: 孤立 print → logger
- douyin/stage/douyin_stage.py:阶段诊断起始处的 [DEBUG] print 改为 _LOGGER.debug,原本是诊断日志,走 logging 更合适 - douyin/reservation/douyin_reservation.py:当 _RESERVATION_ERROR_UTILS 不可用时的 print 兜底改为 _LOGGER.error,避免日志静默丢失 - 两处都新增模块级 logger 回归:140 .py 编译通过;test_filter_logging / check_web_gui_config_sync 通过。 Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
This commit is contained in:
1 parent
d5c9936c88
commit
0700a378ec
2 files changed
+15
-2
No files matched your search
@@ -1,12 +1,17 @@
|
||||
from __future__ import annotations
|
||||
|
||||
import json
|
||||
import logging
|
||||
import os
|
||||
import time
|
||||
import threading
|
||||
from datetime import datetime
|
||||
from typing import Any, Optional
|
||||
|
||||
# 模块级 logger:原代码 _RESERVATION_ERROR_UTILS 不可用时用 print 兜底,
|
||||
# 改走 logging,避免日志静默丢失。
|
||||
_LOGGER = logging.getLogger("douyin.reservation.douyin_reservation")
|
||||
|
||||
# 文件级锁字典,用于保护 JSON 文件的并发读写
|
||||
_json_file_locks: dict[str, threading.Lock] = {}
|
||||
_json_locks_lock = threading.Lock()
|
||||
@@ -200,7 +205,10 @@ def write_reservations_state(
|
||||
)
|
||||
else:
|
||||
try:
|
||||
print(f"[预约队列] 写入状态文件失败: {type(e).__name__}: {e}")
|
||||
_LOGGER.error(
|
||||
"[预约队列] 写入状态文件失败: %s: %s",
|
||||
type(e).__name__, e,
|
||||
)
|
||||
except Exception:
|
||||
pass
|
||||
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
from __future__ import annotations
|
||||
|
||||
import logging
|
||||
|
||||
from douyin.detection import douyin_pixel
|
||||
from douyin.fudai.core.coords import (
|
||||
RECOMMEND_TAB,
|
||||
@@ -13,6 +15,9 @@ from douyin.fudai.core.coords import (
|
||||
COUPON_PARTICIPATE_BUTTON_ALT,
|
||||
)
|
||||
|
||||
# 模块级 logger:原代码用 print 输出阶段诊断起始信息,统一走 logging。
|
||||
_LOGGER = logging.getLogger("douyin.stage.douyin_stage")
|
||||
|
||||
|
||||
def diagnose_stage_from_current_screen(analyser, trigger_reason="unknown"): # type: ignore[misc] # noqa: C901
|
||||
"""完整抽離自 `douyin_fudai.fudai_analyse._diagnose_stage_from_current_screen`。
|
||||
@@ -81,7 +86,7 @@ def diagnose_stage_from_current_screen(analyser, trigger_reason="unknown"): # t
|
||||
from douyin.utils.ocr_preprocess import preprocess_for_ocr # type: ignore
|
||||
|
||||
# 输出开始分隔符与起始信息
|
||||
print(f"[DEBUG] 阶段诊断开始: trigger_reason={trigger_reason}")
|
||||
_LOGGER.debug("[阶段诊断] 开始: trigger_reason=%s", trigger_reason)
|
||||
_log_separator("开始阶段诊断")
|
||||
# 结构化日志:确保将触发原因、以及可能来自此前阶段诊断的缓存信息写入统一日志
|
||||
try:
|
||||
|
||||
Reference in new issue
Block a user