Typed attrs with slog.Any / slog.Int / slog.String
Prefer typed attrs in hot paths: no reflection, no allocations for many common cases.
slog.LogAttrs(ctx, slog.LevelInfo, "order placed",
slog.String("id", orderID),
slog.Int("items", n),
slog.Duration("took", d),
)
With — derive a logger with pinned fields
reqLogger := slog.Default().With("req_id", id, "user", u)
reqLogger.Info("auth ok")
reqLogger.Info("db read", "table", "users")
Group — nested attributes
logger.Info("user signed up",
slog.Group("user",
slog.String("email", email),
slog.String("plan", "pro"),
),
)