Structured logging in Go with log/slog
June 2026
Since log/slog landed in the standard library I have stopped pulling in third-party logging packages for new services. It covers what I need: levels, key/value attributes and a JSON handler.
logger := slog.New(slog.NewJSONHandler(os.Stdout, &slog.HandlerOptions{Level: slog.LevelInfo}))
logger.Info("order created", "order_id", id, "amount", amount)
Request-scoped attributes
Create a child logger per request with logger.With("request_id", rid) and pass it through the context. Every line from that request can then be filtered with a single query.
What not to log
Tokens, full card numbers and raw request bodies. Implement slog.LogValuer on sensitive types so they redact themselves.