vs_log_macros.py 746 B

1234567891011121314151617181920212223
  1. import logging
  2. # 内部持有一个 logger 实例,默认是 Root Logger(防止在没初始化前报错)
  3. _active_logger = logging.getLogger()
  4. def set_active_logger(logger: logging.Logger):
  5. """供外部日志配置工具调用,用于重定向所有宏的输出"""
  6. global _active_logger
  7. _active_logger = logger
  8. # --- 宏定义 (调用签名完全保持原样) ---
  9. def VSC_INFO(tag, message, *args):
  10. _active_logger.info(f"[{tag}] {message}", *args)
  11. def VSC_DEBUG(tag, message, *args):
  12. _active_logger.debug(f"[{tag}] {message}", *args)
  13. def VSC_WARN(tag, message, *args):
  14. _active_logger.warning(f"[{tag}] {message}", *args)
  15. def VSC_ERROR(tag, message, *args):
  16. _active_logger.error(f"[{tag}] {message}", *args)