Observabilitystructured logsJSON logslog levelslog level

Structured logging

Definition

Structured logging emits each log event as a set of named fields (timestamp, level, message, service, trace id and context fields) in a machine-readable format.

In practice

Free-text logs need fragile regexes to answer "show all errors for order 42". With fields, a log store such as Loki or Elasticsearch can filter by order_id, count by error_type and jump to the trace by trace_id. Log levels (DEBUG, INFO, WARN, ERROR) control volume: production usually runs at INFO with errors always kept.

Logs are the most expensive signal per event, so avoid logging every success at high volume; sample them and count with metrics instead. Never log secrets, tokens or full personal data, and keep field names consistent across services. Message templates with parameters keep messages groupable instead of unique strings.

Example

{"ts":"2026-11-24T09:12:03Z","level":"error","service":"checkout","msg":"payment declined","order_id":"o-4821","trace_id":"4bf92f35...","duration_ms":812}