把 douyin/logging/douyin_logging_wrapper.py 的 LoggingWrapper 类(8 个
@staticmethod)按职责拆成 douyin/logging/douyin_logging_wrapper_pkg/ 子包:
- _common (76) 共享:colorama / 占位类 / 模块实例
- enhanced (380) enhanced_log_kv 主入口
- simple (216) _enhanced_log_kv_simple 简化版
- detailed (356) _enhanced_log_kv_detailed 详细版(最大头)
- misc (151) 5 个小型辅助方法(log_step_time / log_error_with_context /
log_performance_step / log_debug_info / get_performance_stats)
- wrapper (55) LoggingWrapper 类(薄壳,每个方法 1 行 forwarding)
策略:8 个方法全是 @staticmethod 第一参数 analyser,搬到 module-level 后
类方法变成 1 行 forwarding。类内部互调(enhanced_log_kv → simple/detailed,
log_error_with_context → enhanced_log_kv)改为直接 import module-level 函数。
外部 import 路径不变:
``from douyin.logging.douyin_logging_wrapper import LoggingWrapper`` 仍可用
(原文件改成 59 行 re-export shim,含 18 个共享符号 / 4 个占位类)。
回归:
- 7 个新文件 + shim compileall 通过
- pytest 353 passed / 1 skipped
- LoggingWrapper.get_performance_stats / module-level 函数 / Fore/Style 占位
全部能正常调用
Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
77 lines
2.0 KiB
Python
77 lines
2.0 KiB
Python
from __future__ import annotations
|
|
|
|
"""douyin_logging_wrapper_pkg._common - 共享:colorama / 占位类 / 模块实例。
|
|
|
|
被本子包的所有方法子模块共用。
|
|
"""
|
|
|
|
import sys
|
|
|
|
# 导入 colorama 用于颜色支持
|
|
try:
|
|
from colorama import Fore, Style, init
|
|
|
|
init(autoreset=True)
|
|
COLORAMA_AVAILABLE = True
|
|
except ImportError:
|
|
# 如果没有 colorama,使用 ANSI 转义序列
|
|
class Fore:
|
|
RED = "\033[31m"
|
|
GREEN = "\033[32m"
|
|
YELLOW = "\033[33m"
|
|
BLUE = "\033[34m"
|
|
MAGENTA = "\033[35m"
|
|
CYAN = "\033[36m"
|
|
WHITE = "\033[37m"
|
|
LIGHTRED_EX = "\033[91m"
|
|
LIGHTGREEN_EX = "\033[92m"
|
|
LIGHTYELLOW_EX = "\033[93m"
|
|
LIGHTBLUE_EX = "\033[94m"
|
|
LIGHTMAGENTA_EX = "\033[95m"
|
|
LIGHTCYAN_EX = "\033[96m"
|
|
LIGHTWHITE_EX = "\033[97m"
|
|
|
|
class Style:
|
|
RESET_ALL = "\033[0m"
|
|
BRIGHT = "\033[1m"
|
|
|
|
COLORAMA_AVAILABLE = False
|
|
|
|
|
|
# 导入所有日志模块
|
|
try:
|
|
from douyin.logging.internal_loggers import ErrorLogger, DebugLogger # type: ignore[assignment]
|
|
from douyin.logging.action_logger import ActionLogger # type: ignore[assignment]
|
|
from douyin.logging.performance_tracker import PerformanceTracker # type: ignore[assignment]
|
|
|
|
LOGGING_MODULES_AVAILABLE = True
|
|
except ImportError:
|
|
# 如果导入失败,提供占位符类
|
|
class ErrorLogger:
|
|
def log_exception(self, *args, **kwargs):
|
|
pass
|
|
|
|
class DebugLogger:
|
|
def log_variable(self, *args, **kwargs):
|
|
pass
|
|
|
|
class ActionLogger:
|
|
def log_step(self, *args, **kwargs):
|
|
pass
|
|
|
|
class PerformanceTracker:
|
|
def end_timer(self, *args, **kwargs):
|
|
pass
|
|
|
|
def get_statistics(self, *args, **kwargs):
|
|
return {}
|
|
|
|
LOGGING_MODULES_AVAILABLE = False
|
|
|
|
|
|
# 初始化日志模块实例
|
|
_error_logger = ErrorLogger()
|
|
_debug_logger = DebugLogger()
|
|
_action_logger = ActionLogger()
|
|
_performance_tracker = PerformanceTracker()
|