diff --git a/volc_limit_sync.py b/volc_limit_sync.py index d984ec7..6171e15 100644 --- a/volc_limit_sync.py +++ b/volc_limit_sync.py @@ -41,6 +41,27 @@ except ImportError: pass +# ========================================== +# 🏷️ Unified Log Tag (统一日志标识,便于过滤) +# ========================================== +# 本脚本所有输出统一带 [VolcSync] 前缀,方便日志筛选: +# docker logs litellm 2>&1 | grep VolcSync +# 实现方式:模块级重绑定 print(`print` 在模块命名空间中按调用时查找), +# 一处覆盖 log()/dprint 与全部裸 print 调用;对模块外部无任何影响。 +LOG_TAG = "[VolcSync]" + +_original_print = print + + +def _tagged_print(*args, **kwargs): + if args and isinstance(args[0], str): + args = (args[0].lstrip("\n"), *args[1:]) + _original_print(LOG_TAG, *args, **kwargs) + + +print = _tagged_print + + # ========================================== # 🛠️ Configuration & Constants # ========================================== @@ -157,7 +178,7 @@ def log(msg, level="INFO"): icon = {"DEBUG": "🔍", "INFO": "ℹ️", "WARNING": "⚠️", "ERROR": "❌"}.get( level, "📝" ) - print(f"{icon} [VolcSync] {msg}", flush=True) + print(f"{icon} {msg}", flush=True) def dprint(msg): @@ -1492,7 +1513,7 @@ def active_monitor_loop(): except Exception as e: print(f"Error in monitor loop / 监控循环出错: {e}", flush=True) - traceback.print_exc() + print(traceback.format_exc(), end="") time.sleep(5)