Files
membank/aio-mcp/internal/logging/logging.go
张威33321 1a6ba86f04 0908
2026-09-08 20:36:25 +08:00

28 lines
646 B
Go
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
// 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})))
}