Documentation
¶
Overview ¶
Package slogdiag is an outbound adapter implementing port.Diagnostics over the standard library's log/slog. It is the production sink for the harness's general-purpose operational logging: composition decisions, degraded-mode warnings, lifecycle notes. The composition layer (cmd mains, internal/app) constructs one and injects it; the port keeps the agent loop and domain free of any slog dependency.
The adapter owns the port.Level → slog.Level mapping and the text-vs-JSON handler choice, so callers pick a destination/format/min-level and otherwise speak only the neutral port.Diagnostics contract.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Diagnostics ¶
type Diagnostics struct {
// contains filtered or unexported fields
}
Diagnostics is a port.Diagnostics backed by a *slog.Logger.
func New ¶
New constructs a Diagnostics writing to w. When jsonFormat is true it uses a slog JSON handler, otherwise a text handler. Records below minLevel are dropped by the handler. The composition layer decides these knobs.
func NewFromLogger ¶
func NewFromLogger(l *slog.Logger) *Diagnostics
NewFromLogger wraps an already-constructed *slog.Logger. It lets a caller that already owns a slog.Logger (e.g. one shared with another subsystem) expose it through the Diagnostics port without re-deriving a handler. A nil logger falls back to a DISCARD logger (never slog.Default): the result is always usable, but the fallback can no longer reach the global default sink — keeping this adapter off the banned global-default path (mirrors mcpperf.go's nil-Logger fallback).
func NewText ¶
func NewText(w io.Writer) *Diagnostics
NewText is the convenience constructor for the common case: human-readable text to w at the Info threshold (mecated's default operator posture).
func (*Diagnostics) Log ¶
Log emits one record at level. The ctx is forwarded to slog's context-aware path (LogAttrs-style) so a handler may read trace context from it; the adapter never derives cancellation from ctx.
func (*Diagnostics) With ¶
func (d *Diagnostics) With(args ...any) port.Diagnostics
With returns a child Diagnostics carrying args bound onto every record, leaving the receiver unchanged (slog.Logger.With returns a new logger).