DevOps

Structured logs you will actually search

Lime, cyan and amber waves streaming across a dark panel

Free-form log lines are written for the person who wrote them. Structured logs are written for the person who has to find them later, usually under pressure.

logger := slog.New(slog.NewJSONHandler(os.Stdout, nil))
logger.Info("payment captured",
    "order_id", order.ID,
    "amount_cents", order.Total,
    "duration_ms", time.Since(start).Milliseconds(),
)

A small field vocabulary

Agree on a handful of keys across services and stick to them. Consistency is what turns logs into something you can query.

  • request_id on every line of a request
  • user_id or account_id, never an email address
  • duration_ms as a number, not a string
  • error holding the error text only
Lime, cyan and amber waves streaming across a dark panel

If you cannot filter by it, it is decoration.

Start with the request ID. It is the single field that turns a pile of lines into a story you can follow.