logging

package
v0.0.0-...-f2e3cbe Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: May 1, 2026 License: MIT Imports: 5 Imported by: 0

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

View Source
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).

View Source
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

func InstallMCP(parent *slog.Logger, ss *mcp.ServerSession) *slog.Logger

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

func NewLogger(serviceName, serviceVersion string) *slog.Logger

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

func ParseLevel(raw string) slog.Level

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) Enabled

func (f *FanoutHandler) Enabled(ctx context.Context, level slog.Level) bool

Enabled reports whether any underlying handler is enabled at level.

func (*FanoutHandler) Handle

func (f *FanoutHandler) Handle(ctx context.Context, r slog.Record) error

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.

func (*FanoutHandler) WithAttrs

func (f *FanoutHandler) WithAttrs(attrs []slog.Attr) slog.Handler

WithAttrs implements slog.Handler.

func (*FanoutHandler) WithGroup

func (f *FanoutHandler) WithGroup(name string) slog.Handler

WithGroup implements slog.Handler.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL