Documentation
¶
Overview ¶
Package logging provides the structured logging primitives shared by the Taskfile MCP server: a multi-handler fanout, the MCP "logging" arm wiring, and the stderr logger constructor.
Index ¶
- Constants
- func InstallMCP(parent *slog.Logger, ss *mcp.ServerSession) *slog.Logger
- func NewLogger(serviceName, serviceVersion string) *slog.Logger
- func ParseLevel(raw string) slog.Level
- type FanoutHandler
- func (f *FanoutHandler) Enabled(ctx context.Context, level slog.Level) bool
- func (f *FanoutHandler) Handle(ctx context.Context, r slog.Record) error
- func (f *FanoutHandler) Handlers() []slog.Handler
- func (f *FanoutHandler) WithAttrs(attrs []slog.Attr) slog.Handler
- func (f *FanoutHandler) WithGroup(name string) slog.Handler
Constants ¶
const LevelEnv = "MCP_TASKFILE_LOG_LEVEL"
LevelEnv names the environment variable used to configure the log level. Recognised values: debug, info, warn, error (case-insensitive).
const LoggerName = "mcp-taskfile-server"
LoggerName is the logger name reported on logging/message notifications sent to the connected MCP client.
Variables ¶
This section is empty.
Functions ¶
func InstallMCP ¶
InstallMCP returns a logger derived from parent that fans every record out to both parent's existing handler and an MCP arm bound to ss. Subsequent records reach the connected client via logging/message in addition to whatever sink was previously installed (typically a JSON handler on stderr).
The SDK's LoggingHandler enforces the client-set threshold internally via logging/setLevel; the parent arm keeps its own threshold from MCP_TASKFILE_LOG_LEVEL. Failures forwarding to the client are dropped inside the SDK to avoid recursion through this handler.
func NewLogger ¶
NewLogger builds the structured logger used by the server. It writes JSON to stderr (the only safe channel under stdio MCP transport) and honours MCP_TASKFILE_LOG_LEVEL.
MCP-side mirroring is wired in by the Server itself once the client handshake completes, by extending this logger with the SDK's LoggingHandler bound to the active session via InstallMCP. The client controls what reaches it via logging/setLevel, independently of stderr.
func ParseLevel ¶
ParseLevel resolves the configured log level. Unrecognised or empty values fall back to info.
Types ¶
type FanoutHandler ¶
type FanoutHandler struct {
// contains filtered or unexported fields
}
FanoutHandler dispatches every record to multiple slog.Handlers, allowing the server to emit a single log line to both the stderr JSON sink and the SDK's MCP LoggingHandler without coupling their lifecycles. Per-handler errors are dropped so a failure in one branch does not suppress the others.
slog has no built-in multi-handler; this is the minimum needed.
func NewFanout ¶
func NewFanout(handlers ...slog.Handler) *FanoutHandler
NewFanout returns a handler that forwards every record to each of handlers in order.
func (*FanoutHandler) Handle ¶
Handle dispatches r to each underlying handler that is enabled. Each handler receives a clone of the record because slog.Record's attributes are encoded lazily.
func (*FanoutHandler) Handlers ¶
func (f *FanoutHandler) Handlers() []slog.Handler
Handlers returns the underlying handlers in their original order. The returned slice is shared with the receiver and must not be mutated.