Structured logging

Structured logging emits log lines as key-value records, usually in JSON format. This allows logs to be filtered and aggregated by individual fields instead of requiring tools to parse information embedded in prose.

Minimal example

go
logger := slog.New(slog.NewJSONHandler(os.Stdout, nil))
logger.Info("order created", "order_id", 1042)

Learn this concept

Lesson 6.5 · Request-scoped logging and timeouts

Used in exercises

Exercise 6.6 · Request context and timeout layer