Files
douyi_guaji_main/tools/diagnostics/check_action_logger.py
T
CodexandClaude Opus 4.5 a19fa35a0f chore: 整理 tools/ 47 个脚本按功能分组
- diagnostics/ 11 个:环境/配置/依赖诊断
- logs/ 7 个:日志分析与查看
- coords/ 6 个:坐标拾取与区域选择
- cleanup/ 3 个:代码清理工具
- adb/ 2 个:ADB / 输入法相关
- windows/ 4 个:Windows 系统修复(备份)
- dev/ 9 个:开发辅助 / 运行时探测

并更新 tools/README.md 描述新结构。
删除 3 个明显的临时调试脚本 (_dump_lines.py / tmp_*.py)。

tools/ 不被业务代码 import,分组仅为人工浏览方便。

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-05-20 23:25:28 +08:00

87 lines
2.7 KiB
Python

#!/usr/bin/env python3
"""项目自检脚本:检查 action_logger 初始化与 analyser._log_kv 绑定。
用法: 在与项目相同的 Python 环境中运行:
python tools/check_action_logger.py
"""
import logging
import time
import traceback
from pathlib import Path
import sys
PROJECT_ROOT = Path(__file__).resolve().parents[1]
sys.path.insert(0, str(PROJECT_ROOT))
from douyin.logging import action_logger, douyin_logging_wrapper
from douyin.core.douyin_fudai import fudai_analyse
import path_config
def safe_repr(obj):
try:
return repr(obj)
except Exception:
return "<unreprable>"
def main():
print("=== action_logger / handler 状态 ===")
try:
al = logging.getLogger("action_logger")
handlers = al.handlers
print(
"logger 'action_logger' handlers:",
[(type(h).__name__, getattr(h, "baseFilename", None)) for h in handlers],
)
except Exception:
print("获取 action_logger 失败:")
traceback.print_exc()
print("\n=== action_logger 模块队列/监听器 ===")
try:
q = getattr(action_logger, "_log_queue", None)
l = getattr(action_logger, "_queue_listener", None)
print("_log_queue:", type(q).__name__ if q is not None else None)
print("_queue_listener:", type(l).__name__ if l is not None else None)
if l is not None:
# QueueListener has method 'is_alive' if it's a Thread subclass; otherwise skip
alive = getattr(l, "is_alive", lambda: False)()
print("listener is_alive:", alive)
except Exception:
traceback.print_exc()
print("\n=== actions.log 路径与权限 ===")
try:
path = path_config.get_actions_log_path()
print("actions.log path:", path)
try:
with open(path, "a", encoding="utf-8") as f:
f.write(f"#check {time.time()}\n")
print("已向 actions.log 追加一行(权限与磁盘检查通过)")
except Exception as e:
print("写入 actions.log 失败:", e)
except Exception:
traceback.print_exc()
print("\n=== analyser._log_kv 绑定检查与试写 ===")
try:
a = fudai_analyse()
print("analyser._log_kv repr:", safe_repr(a._log_kv))
try:
a._log_kv("check_point", "self_check", detail="test_write")
print(
"已调用 analyser._log_kv(...). 请查看 actions.log 是否包含该条目(或等待几秒队列刷新)"
)
except Exception as e:
print("调用 analyser._log_kv 失败:", e)
except Exception:
traceback.print_exc()
print("\n检查完成。")
if __name__ == "__main__":
main()