Logging Best Practices

Structured JSON over text, log levels, sampling, correlation IDs, and the cost reality.

Overview

The most expensive pillar

Logging is the most expensive of the three pillars at scale and the most often abused. Two engineers logging 'everything at INFO' can quintuple a service's log spend without proportional debug value.

A healthy log line goes through a short pipeline before anyone reads it. The service emits the event as structured JSON with a trace_id, secrets and PII are redacted, the event is sampled at the source while every error is kept, and what remains sits in hot retention for 7-30 days before moving to a cold archive in S3 or GCS. The six rules below cover each of those stages.

Key concepts

  • Structured logging
  • Log levels
  • Sampling at source
  • Correlation ID (trace_id)
  • Log retention tiering

Interview questions

  • What's a good logging policy for a new service?
  • How do correlation IDs work in distributed systems?
  • How do you reduce log costs without losing visibility?

Sign up free to read the full topic

More SRE topics

Start free on Cariara · Coding problems · System design studio