vs_log_macros.py 632 B

123456789101112131415161718192021
  1. # vs_log_macros.py
  2. import logging
  3. import os
  4. # 配置日志
  5. # 默认INFO级别,格式包含线程名
  6. logging.basicConfig(level=os.environ.get("VSC_LOG_LEVEL", "INFO").upper(),
  7. format='[%(levelname)s] [%(threadName)s] %(message)s')
  8. # 定义快捷日志函数,模仿C++的宏
  9. def VSC_INFO(tag, message, *args):
  10. logging.info(f"[{tag}] {message}", *args)
  11. def VSC_DEBUG(tag, message, *args):
  12. logging.debug(f"[{tag}] {message}", *args)
  13. def VSC_WARN(tag, message, *args):
  14. logging.warning(f"[{tag}] {message}", *args)
  15. def VSC_ERROR(tag, message, *args):
  16. logging.error(f"[{tag}] {message}", *args)