From 0700a378ec3376adfdcbc75175cdb57de679af62 Mon Sep 17 00:00:00 2001 From: Codex Date: Thu, 21 May 2026 11:52:28 +0800 Subject: [PATCH] =?UTF-8?q?stage=20+=20reservation:=20=E5=AD=A4=E7=AB=8B?= =?UTF-8?q?=20print=20=E2=86=92=20logger?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 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 --- douyin/reservation/douyin_reservation.py | 10 +++++++++- douyin/stage/douyin_stage.py | 7 ++++++- 2 files changed, 15 insertions(+), 2 deletions(-) diff --git a/douyin/reservation/douyin_reservation.py b/douyin/reservation/douyin_reservation.py index a551d5d..88f30c9 100644 --- a/douyin/reservation/douyin_reservation.py +++ b/douyin/reservation/douyin_reservation.py @@ -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 diff --git a/douyin/stage/douyin_stage.py b/douyin/stage/douyin_stage.py index bffad2c..36bfb05 100644 --- a/douyin/stage/douyin_stage.py +++ b/douyin/stage/douyin_stage.py @@ -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: