External Publication
Visit Post

Type-safe slogging

x-log [Unofficial] May 9, 2026
Source

Well written article by Redowan Delowar, explaining how to achieve type-safe logging with Go's log/slog library.

  • Take the logger as a constructor argument. Never reach for slog.Default() or any package-level slog function.
  • Always use logger.LogAttrs(ctx, level, msg, attrs...). Not logger.Info, logger.Warn, or any of the kv-flavored helpers.
  • Every attribute comes from a helper in internal/log/attrs.go. Write applog.OrderID(o.ID), never slog.String("order_id", o.ID) inline.
  • sloglint enforces all three on every commit so the workflow doesn’t erode.

Thanks for reading this post via RSS. You're awesome ♥️

Discussion in the ATmosphere

Loading comments...