← Lessons

quiz vs the machine

Silver1050

System Design

Structured Logging

Logging as key value records instead of free form prose for machine querying.

4 min read · intro · beat Silver to climb

Structured logging

A traditional log line is a human sentence such as a message about a failed payment. It reads fine to a person but is painful for a machine to parse at scale. Structured logging records each event as a set of named fields, usually serialized as JSON, so tools can filter and aggregate without fragile text matching.

What a structured event holds

  • A timestamp and a severity level such as info or error
  • A short message describing what happened
  • Context fields like user id, request id, region, and latency

Because the fields are named, you can ask precise questions such as all error events for one user in one region, and get an answer in seconds.

Consistency matters

The value comes from consistent field names across services. If one service writes user id and another writes uid, your queries break. Teams often share a logging library that stamps standard fields automatically.

A caution

Structured logs cost more bytes than plain text, and high volume logging can dominate spend. Log at the right level and avoid recording secrets.

Key idea

Structured logs turn events into queryable key value records, so consistent field naming unlocks fast precise searches.

Check yourself

Answer to earn rating on the learn ladder.

1. What is the main advantage of structured logging over plain text lines?

2. Why does consistent field naming matter across services?