Files
douyin_guaji-main/douyin/logging/douyin_logging_pkg/__init__.py
T
CodexandClaude Opus 4.7 9d1b0c1e36 拆分 douyin_logging (1412 → 5 个子模块 + 46 行 shim)
把 douyin/logging/douyin_logging.py 按职责拆成
douyin/logging/douyin_logging_pkg/ 子包:

- _common (21)     共享全局状态:_logging_configured / _logger_cache / _log_monitor
- handlers (206)   自定义 handler:RotatingDatedFileHandler / DatedFileHandler
- cleanup (282)    日志压缩与清理:compress_log_file / cleanup_old_logs / _load_*_policy
- monitor (337)    轮转监控:LogRotationMonitor / start/stop_log_monitor / get_log_stats
- config (652)     主配置入口:get_logger / configure_logging / log_function_call /
                   LogContext / get_caller_info / format_exception_info

原文件改为 46 行 re-export shim,15 个公共符号全部保留。
全局变量统一搬到 _common,子模块通过 ``from . import _common as _state``
访问 _state.X 形式(global 不能跨模块)。

子包名 douyin_logging_pkg 是为了避免与同目录下的 shim 文件
douyin_logging.py 冲突(同名包 vs 模块在 Python 中不能并存)。

回归:
- 6 个新文件 + shim compileall 通过
- pytest 353 passed / 1 skipped(含 unified_logger MDC 13 个用例)
- 旧 import 路径与新子包路径返回同一函数对象
- get_logger 缓存机制(第二次调用返回同一对象)正常工作

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
2026-05-21 17:13:34 +08:00

57 lines
1.5 KiB
Python
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
"""douyin_logging_pkg - 日志系统子包。
原 douyin/logging/douyin_logging.py 拆成 5 个子模块:
- _common 共享全局状态:_logging_configured / _logger_cache / _log_monitor
- handlers 自定义 handler:RotatingDatedFileHandler / DatedFileHandler
- cleanup 压缩与清理:compress_log_file / cleanup_old_logs
- monitor 监控线程:LogRotationMonitor / start_log_monitor / stop_log_monitor / get_log_stats
- config 主配置入口:get_logger / configure_logging / log_function_call / LogContext
外部 import 路径不变:
``from douyin.logging.douyin_logging import configure_logging`` 仍可用
(原文件改成 re-export shim)。
"""
from .handlers import (
DatedFileHandler,
RotatingDatedFileHandler,
)
from .cleanup import (
_load_logging_cleanup_policy_from_config,
cleanup_old_logs,
compress_log_file,
)
from .monitor import (
LogRotationMonitor,
get_log_stats,
start_log_monitor,
stop_log_monitor,
)
from .config import (
LogContext,
configure_logging,
format_exception_info,
get_caller_info,
get_logger,
log_function_call,
)
__all__ = [
"RotatingDatedFileHandler",
"DatedFileHandler",
"compress_log_file",
"cleanup_old_logs",
"_load_logging_cleanup_policy_from_config",
"get_logger",
"configure_logging",
"log_function_call",
"LogContext",
"get_caller_info",
"format_exception_info",
"LogRotationMonitor",
"start_log_monitor",
"stop_log_monitor",
"get_log_stats",
]