This commit is contained in:
张威33321
2026-09-08 20:36:25 +08:00
parent 6296202eb0
commit 1a6ba86f04
13 changed files with 314 additions and 104 deletions

View File

@@ -0,0 +1,27 @@
// Package logging 负责 aio-mcp 的全局日志初始化。
package logging
import (
"log/slog"
"os"
)
// Setup 初始化全局 slog 默认 logger。
//
// 日志固定输出到 stderrstdio 模式下 stdout 是 MCP 协议通道,
// 任何日志混入都会破坏 JSON-RPC 报文。业务代码同样禁止打印到 stdout。
func Setup(level string) {
var lvl slog.Level
switch level {
case "debug":
lvl = slog.LevelDebug
case "warn":
lvl = slog.LevelWarn
case "error":
lvl = slog.LevelError
default:
lvl = slog.LevelInfo
}
slog.SetDefault(slog.New(slog.NewTextHandler(os.Stderr, &slog.HandlerOptions{Level: lvl})))
}