38 lines
1.0 KiB
Python
38 lines
1.0 KiB
Python
"""只记录可关联的技术外壳;正文、模型输入和凭据不进入应用日志。"""
|
|
|
|
import json
|
|
import logging
|
|
|
|
日志 = logging.getLogger("muse")
|
|
|
|
|
|
def 记录运行(
|
|
事件: str,
|
|
*,
|
|
请求ID: str | None = None,
|
|
任务ID: str | None = None,
|
|
步骤ID: str | None = None,
|
|
尝试ID: str | None = None,
|
|
状态: str | int | None = None,
|
|
错误码: str | None = None,
|
|
耗时秒: float | None = None,
|
|
) -> None:
|
|
"""字段白名单避免把请求字典或异常正文顺手传入日志。"""
|
|
内容 = {
|
|
"event": 事件,
|
|
"request_id": 请求ID,
|
|
"task_id": 任务ID,
|
|
"step_id": 步骤ID,
|
|
"attempt_id": 尝试ID,
|
|
"status": 状态,
|
|
"code": 错误码,
|
|
"duration_seconds": 耗时秒,
|
|
}
|
|
日志.info(json.dumps({k: v for k, v in 内容.items() if v is not None}, ensure_ascii=False))
|
|
|
|
|
|
def 配置日志() -> None:
|
|
日志.setLevel(logging.INFO)
|
|
if not 日志.handlers:
|
|
日志.addHandler(logging.StreamHandler())
|