feat: 日志统一加 [VolcSync] 前缀便于筛选
模块级重绑定 print(一处覆盖全部 52 处调用, 含 log()/dprint/裸print), traceback.print_exc 改走带前缀通道, 去除 log() 内嵌标识避免双前缀。 筛选: docker logs litellm 2>&1 | grep VolcSync
This commit is contained in:
+23
-2
@@ -41,6 +41,27 @@ except ImportError:
|
|||||||
pass
|
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
|
# 🛠️ Configuration & Constants
|
||||||
# ==========================================
|
# ==========================================
|
||||||
@@ -157,7 +178,7 @@ def log(msg, level="INFO"):
|
|||||||
icon = {"DEBUG": "🔍", "INFO": "ℹ️", "WARNING": "⚠️", "ERROR": "❌"}.get(
|
icon = {"DEBUG": "🔍", "INFO": "ℹ️", "WARNING": "⚠️", "ERROR": "❌"}.get(
|
||||||
level, "📝"
|
level, "📝"
|
||||||
)
|
)
|
||||||
print(f"{icon} [VolcSync] {msg}", flush=True)
|
print(f"{icon} {msg}", flush=True)
|
||||||
|
|
||||||
|
|
||||||
def dprint(msg):
|
def dprint(msg):
|
||||||
@@ -1492,7 +1513,7 @@ def active_monitor_loop():
|
|||||||
|
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
print(f"Error in monitor loop / 监控循环出错: {e}", flush=True)
|
print(f"Error in monitor loop / 监控循环出错: {e}", flush=True)
|
||||||
traceback.print_exc()
|
print(traceback.format_exc(), end="")
|
||||||
time.sleep(5)
|
time.sleep(5)
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user