Skip to content

Engineering habits · Part 6 of 10

Reading logs effectively when something is on fire

Start from the symptom and the time, follow one request id, find the first error rather than the loudest one and compare with a healthy case.

· 2 min read

engineeringlogging

When production misbehaves you may face millions of lines. Reading them well is a skill, and it starts with narrowing the search before reading anything.

Anchor on time and symptom

Decide when the problem started and what exactly is wrong: errors for one endpoint, slowness for one customer, a job that did not run. Restrict the logs to that window and that component. Compare with the period just before, since the difference is where the answer lives.

Follow one request

If logs carry a request or correlation id, take one failing request and follow it through every service. That single thread shows the sequence of events far better than skimming the whole stream.

shell
# Find all lines for one request across files.
grep "request_id=abc123" app.log worker.log | sort

# JSON logs: show errors for one user with jq.
jq -c 'select(.level == "error" and .user_id == 42) | {time, msg}' app.json.log

Find the first error, not the loudest

A failure often causes a cascade: one database timeout, then thousands of retries and secondary errors. The most frequent message is usually a symptom. Sort by time and look for the earliest unusual line.

Look at the shape

  • Count messages per minute to see when it started and whether it is growing.
  • Group errors by type, endpoint, version or host. If one host or one release stands out, you have a lead.
  • Look for gaps. Missing logs can mean a crashed process or a dead log shipper.

Read the whole message. Stack traces and error texts usually say what is wrong. Read from the first line, note the exception class and the deepest frame in your own code, and search for the exact message.

Write logs for the person debugging

  1. Include identifiers: request id, user id, order id.
  2. Log decisions and inputs at boundaries, not every line of a loop.
  3. Use levels honestly, so errors mean something.
  4. Never log secrets or personal data you do not need.

Takeaway

Narrow by time and component, follow one request, find the earliest error, compare with a healthy period and invest in logs that make the next investigation easier.

A knowledge article, drafted with AI assistance and checked with automated tests. It is general background, not a description of my own experience or of any client's work.

Comments

Leave a comment

No account or email needed. Comments appear after review. A one-way hash of your IP address is kept for 30 days to fight spam, then erased.