tooluniverse.logging_config 模块¶
ToolUniverse 的全局日志配置
该模块基于 Python 标准日志模块,提供了一个集中式日志系统。它允许在整个 ToolUniverse 项目中通过不同的详细级别控制调试输出。
- 用法:
# 通过环境变量设置日志级别 export TOOLUNIVERSE_LOG_LEVEL=DEBUG
# 或通过编程方式设置 from tooluniverse.logging_config import setup_logging, get_logger setup_logging(‘DEBUG’)
# 在代码中使用 logger = get_logger(__name__) logger.info(“这是一个信息消息”) logger.debug(“这是一个调试消息”)
- class tooluniverse.logging_config.ToolUniverseFormatter[源代码]¶
基类:
Formatter带有彩色输出和表情符号前缀的自定义格式化器
- COLORS = {'CRITICAL': '\x1b[35m', 'DEBUG': '\x1b[36m', 'ERROR': '\x1b[31m', 'INFO': '\x1b[32m', 'PROGRESS': '\x1b[34m', 'RESET': '\x1b[0m', 'WARNING': '\x1b[33m'}¶
- EMOJI_PREFIX = {'CRITICAL': '🚨 ', 'DEBUG': '🔧 ', 'ERROR': '❌ ', 'INFO': 'ℹ️ ', 'PROGRESS': '⏳ ', 'WARNING': '⚠️ '}¶
- tooluniverse.logging_config.reconfigure_for_quiet()[源代码]¶
Reconfigure logging to suppress INFO-level messages (quiet mode).
This function should be called after TOOLUNIVERSE_QUIET is set to ensure that ℹ️ info lines are suppressed even if the logger singleton was already initialized before the env var was exported.
- tooluniverse.logging_config.reconfigure_for_stdio()[源代码]¶
将日志重新配置为在标准输入输出模式下输出到标准错误(stderr)。
此函数应在进入标准输入输出模式的最开始调用,以确保所有日志输出到标准错误而不是标准输出。
- tooluniverse.logging_config.setup_logging(level=None)[源代码]¶
设置全局日志配置
- 参数:
level (
str) – 日志级别(’DEBUG’、’INFO’、’WARNING’、’ERROR’、’CRITICAL’)
- tooluniverse.logging_config.get_logger(name=None)[源代码]¶
获取日志记录器实例
- 参数:
name (
str, optional) – 记录器名称(通常为 __name__)
- 退货
logging.Logger: Logger instance
- tooluniverse.logging_config.minimal(msg, *args, **kwargs)¶
日志信息消息
- tooluniverse.logging_config.verbose(msg, *args, **kwargs)¶
记录调试消息
- tooluniverse.logging_config.progress(msg, *args, **kwargs)¶
记录进度消息