ADR-0010: Go stdlib log/slog over Third-Party Structured Loggers for Application Logging
Context and Problem Statement
Spotter requires structured logging throughout the application: request logging in HTTP middleware, service-level operation tracking in sync and enrichment pipelines, AI API call diagnostics, and error reporting. The logger must support key-value attributes (structured fields), multiple log levels, and be injectable into services via dependency injection. Should the project use a third-party structured logging library or Go's standard library log/slog package introduced in Go 1.21?
Decision Drivers
- Spotter targets Go 1.24+ (as declared in
go.mod) —log/slogis fully available and stable - The logger is passed as a
*slog.Loggerparameter to every service constructor — the interface must be widely understood - Minimizing external dependencies is a project goal (self-hosted, personal application)
- Log output goes to stdout for container-friendly log collection — no need for complex log routing
- Multiple services need contextual logging with varying attribute sets (request IDs, user IDs, artist names, API response codes)
- Some services need the ability to suppress logging entirely (e.g., test contexts, optional enrichers)
Considered Options
- Go stdlib
log/slog— standard library structured logger withTextHandlerwriting to stdout - Uber Zap — high-performance structured logger with zero-allocation logging
- logrus — widely-used structured logger with field-based API
- zerolog — zero-allocation JSON-first structured logger
Decision Outcome
Chosen option: Go stdlib log/slog, because it provides structured logging with key-value attributes, multiple log levels, handler-based output formatting, and the slog.Logger type as a standard interface — all without adding any external dependency. The logger is initialized once in cmd/server/main.go with a TextHandler writing to os.Stdout at Debug level, then passed via dependency injection to every service. This adds zero entries to go.mod for logging.
Consequences
- Good, because zero external dependencies for logging —
log/slogis part of the Go standard library since Go 1.21 - Good, because
*slog.Loggeris the standard interface — any Go developer recognizes it without learning a third-party API - Good, because the
slog.Handlerinterface allows swapping output format (text, JSON) without changing any call sites - Good, because structured attributes (
slog.String(),slog.Int(),slog.Duration()) provide type-safe key-value logging - Good, because the no-op handler pattern (
nopHandler) enables silent loggers for optional services and tests - Bad, because
slog.TextHandleroutput is less structured than JSON for log aggregation tools — switching toslog.JSONHandlerwould fix this but is not yet configured - Bad, because no built-in log rotation or file output — relies on container runtime or external tools for log management
Confirmation
Compliance is confirmed by verifying that go.mod contains no logging library imports (no go.uber.org/zap, github.com/sirupsen/logrus, or github.com/rs/zerolog). All services should accept *slog.Logger as a constructor parameter. The logger should be initialized in cmd/server/main.go using slog.New() with a slog.TextHandler.