feat: 更新日志记录功能,添加自检脚本以检查 action_logger 初始化与绑定状态
This commit is contained in:
1 parent
57177ef7a2
commit
1105ed618f
7 files changed
+218
-38
No files matched your search
+42
-17
@@ -7,11 +7,28 @@ import sys
|
||||
# ==== 首先配置日志系统,确保日志文件能正常写入 ==============================
|
||||
try:
|
||||
from douyin.logging import douyin_logging
|
||||
|
||||
douyin_logging.configure_logging()
|
||||
except Exception:
|
||||
# 日志配置失败不影响主流程,但会缺少文件日志
|
||||
pass
|
||||
|
||||
# 尝试确保行为日志的异步 listener 在进程启动时就被启动,
|
||||
# 以避免某些运行环境中模块未完整初始化导致日志未落盘的问题。
|
||||
try:
|
||||
# 直接以模块方式导入,避免 package 的 `__init__` 导出遮蔽(`from douyin.logging import action_logger`
|
||||
# 会失败因为 package 只导出了 `ActionLogger` 等名字)。
|
||||
import importlib
|
||||
|
||||
action_logger_mod = importlib.import_module("douyin.logging.action_logger")
|
||||
try:
|
||||
action_logger_mod._start_queue_listener_if_needed()
|
||||
except Exception:
|
||||
# 启动失败时不影响主流程,action_logger 有回退到同步 file handler 的逻辑
|
||||
pass
|
||||
except Exception:
|
||||
pass
|
||||
|
||||
# ==== 兼容导入完整逻辑模块 douyin_fudai 及其依赖 ==============================
|
||||
# 当前 WebGUI 目录中没有完整版 douyin_fudai.py,而是在 Cursor 的工作树中存在完整实现。
|
||||
# 同时,我们在本目录下放置了一些 shim 模块(如 douyin_text_utils、douyin_swipe_ops 等),
|
||||
@@ -22,12 +39,8 @@ _BASE_DIR = os.path.dirname(__file__)
|
||||
_EXTERNAL_DOUYIN_FUDAI_DIR = os.environ.get(
|
||||
"EXTERNAL_DOUYIN_FUDAI_DIR",
|
||||
os.path.join(
|
||||
os.path.expanduser("~"),
|
||||
".cursor",
|
||||
"worktrees",
|
||||
"douyin_guaji-main",
|
||||
"axf"
|
||||
)
|
||||
os.path.expanduser("~"), ".cursor", "worktrees", "douyin_guaji-main", "axf"
|
||||
),
|
||||
)
|
||||
|
||||
|
||||
@@ -53,7 +66,9 @@ def _load_local_shim(mod_name: str, rel_path: str) -> None:
|
||||
# 1) 先加载本地 shim 模块,确保后续 import 优先使用这些实现
|
||||
_load_local_shim("douyin_text_utils", "douyin/utils/douyin_text_utils.py")
|
||||
_load_local_shim("douyin_swipe_ops", "douyin/handlers/douyin_swipe_ops.py")
|
||||
_load_local_shim("douyin_reservation_ops", "douyin/reservation/douyin_reservation_ops.py")
|
||||
_load_local_shim(
|
||||
"douyin_reservation_ops", "douyin/reservation/douyin_reservation_ops.py"
|
||||
)
|
||||
|
||||
# 2) 再把完整逻辑所在目录追加到 sys.path,供 `douyin_fudai` 等模块导入
|
||||
try:
|
||||
@@ -295,13 +310,15 @@ def main(argv: list[str]) -> int:
|
||||
|
||||
try:
|
||||
_scaled_click(
|
||||
getattr(analyser, "yanghao_comment_btn_x", 540), getattr(analyser, "yanghao_comment_btn_y", 2000)
|
||||
getattr(analyser, "yanghao_comment_btn_x", 540),
|
||||
getattr(analyser, "yanghao_comment_btn_y", 2000),
|
||||
)
|
||||
analyser.operation.delay(1)
|
||||
analyser._save_step_screenshot("test_comment_after_open")
|
||||
|
||||
_scaled_click(
|
||||
getattr(analyser, "yanghao_comment_input_x", 540), getattr(analyser, "yanghao_comment_input_y", 1900)
|
||||
getattr(analyser, "yanghao_comment_input_x", 540),
|
||||
getattr(analyser, "yanghao_comment_input_y", 1900),
|
||||
)
|
||||
analyser.operation.delay(1)
|
||||
analyser._save_step_screenshot("test_comment_after_focus")
|
||||
@@ -321,7 +338,8 @@ def main(argv: list[str]) -> int:
|
||||
analyser._save_step_screenshot("test_comment_after_send")
|
||||
|
||||
_scaled_click(
|
||||
getattr(analyser, "yanghao_comment_close_x", 900), getattr(analyser, "yanghao_comment_close_y", 300)
|
||||
getattr(analyser, "yanghao_comment_close_x", 900),
|
||||
getattr(analyser, "yanghao_comment_close_y", 300),
|
||||
)
|
||||
analyser.operation.delay(1)
|
||||
analyser._save_step_screenshot("test_comment_after_close")
|
||||
@@ -368,10 +386,15 @@ def main(argv: list[str]) -> int:
|
||||
analyser.skip_if_countdown_gt_seconds = int(
|
||||
args.skip_if_countdown_gt_seconds or 900
|
||||
)
|
||||
if hasattr(args, 'skip_if_countdown_lt_seconds') and args.skip_if_countdown_lt_seconds is not None:
|
||||
setattr(analyser, "skip_if_countdown_lt_seconds", int(
|
||||
args.skip_if_countdown_lt_seconds or 10
|
||||
))
|
||||
if (
|
||||
hasattr(args, "skip_if_countdown_lt_seconds")
|
||||
and args.skip_if_countdown_lt_seconds is not None
|
||||
):
|
||||
setattr(
|
||||
analyser,
|
||||
"skip_if_countdown_lt_seconds",
|
||||
int(args.skip_if_countdown_lt_seconds or 10),
|
||||
)
|
||||
if args.reset_after_swipes is not None:
|
||||
analyser.reset_after_swipes = max(1, int(args.reset_after_swipes or 0))
|
||||
analyser.reset_after_swipes_enabled = True
|
||||
@@ -398,9 +421,11 @@ def main(argv: list[str]) -> int:
|
||||
# 运行时覆盖:回退后滑动等待(快速值,仅在未启用回退校验时使用)
|
||||
if getattr(args, "reservation_back_swipe_delay", None) is not None:
|
||||
try:
|
||||
setattr(analyser, "reservation_back_swipe_delay_fast_seconds", float(
|
||||
args.reservation_back_swipe_delay
|
||||
))
|
||||
setattr(
|
||||
analyser,
|
||||
"reservation_back_swipe_delay_fast_seconds",
|
||||
float(args.reservation_back_swipe_delay),
|
||||
)
|
||||
except Exception:
|
||||
pass
|
||||
if getattr(args, "reservation_preempt_min_value", None) is not None:
|
||||
|
||||
Reference in new issue
Block a user