Files
douyi_guaji_main/tools/diagnostics/check_action_logger.py
T
CodexandClaude Opus 4.5 8fe7ff0585 refactor: 根目录核心模块迁移到 douyin/core/ 和 douyin/logging/
将 4 个根目录核心模块迁移到合理位置:
- path_config.py    -> douyin/core/path_config.py
- version.py        -> douyin/core/version.py
- Underlying_Operations.py -> douyin/core/underlying_operations.py
- unified_logger.py -> douyin/logging/unified_logger.py

配套更新所有 import:
- path_config: 41 处 import 改为 douyin.core.path_config
- version: 4 处改为 douyin.core.version
- unified_logger: 5 处改为 douyin.logging.unified_logger
- Underlying_Operations: 14 处改为 douyin.core.underlying_operations

修复 path_config.PROJECT_ROOT 计算(向上 2 级而非当前目录)。

验证:python -m compileall 全项目通过。

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-05-21 00:23:14 +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
from douyin.core 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()