Canonical guidance

Use when

Avoid

Preferred pattern

logger := slog.New(slog.NewJSONHandler(os.Stdout, nil)).With(
	slog.String("service", "api"),
)

logger.Info("request complete", slog.Int("status", http.StatusOK))

Anti-pattern

Explanation: This anti-pattern is tempting because printf is fast to type, but it throws away the structured context operators depend on.

Why

Related pages

Sources