ZLMediaKit/python/mk_logger.py
夏楚 6d520ea6a3
Some checks failed
Android / build (push) Has been cancelled
CodeQL / Analyze (cpp) (push) Has been cancelled
CodeQL / Analyze (javascript) (push) Has been cancelled
Docker / build (push) Has been cancelled
Linux / build (push) Has been cancelled
Linux_Python / build (push) Has been cancelled
macOS / build (push) Has been cancelled
macOS_Python / build (push) Has been cancelled
Windows / build (push) Has been cancelled
Windows_Python / build (push) Has been cancelled
新增支持Python混合编程模式 (#4579)
2026-02-10 13:28:42 +08:00

28 lines
751 B
Python

import inspect
try:
import mk_loader
USE_PLUGIN_LOGGER = True
except ImportError:
USE_PLUGIN_LOGGER = False
def _do_log(level: int, *args):
frame_info = inspect.stack()[2]
filename = frame_info.filename
lineno = frame_info.lineno
funcname = frame_info.function
# 把所有参数转成字符串后用空格拼接
msg = " ".join(str(arg) for arg in args)
if USE_PLUGIN_LOGGER:
mk_loader.log(level, filename, lineno, funcname, msg)
else:
print(f"[{filename}:{lineno}] {funcname} | {msg}")
def log_trace(*args): _do_log(0, *args)
def log_debug(*args): _do_log(1, *args)
def log_info(*args): _do_log(2, *args)
def log_warn(*args): _do_log(3, *args)
def log_error(*args): _do_log(4, *args)