← All articles
· 2 min read

Structured logs you can actually grep later

If a human has to regex your logs during an incident, the log line failed. Pick one format, put the request id on every line, and move on.

The test of a log line is simple: during an incident, at 3am, can you find what you need with one grep and without a parser in your head? If the answer is no, the line failed, no matter how much it printed.

Free-form prose logs fail this test. They read fine to a human reading top to bottom and are miserable to search across millions of lines:

2026-05-30 14:02:11 Processing order for user, took a while, might retry

Which user? Which order? How long is "a while"? Structured logs put the answers in stable keys. Pick one format and never mix. Key-value is grep-friendly; JSON is machine-friendly. Whichever you pick, carry a request_id on every line so you can reconstruct one request out of the interleaved noise of fifty.

level=info ts=2026-05-30T14:02:11Z request_id=7f3a9c msg="order processed" user_id=4821 order_id=99013 duration_ms=812 retried=false

In Go with log/slog that line is cheap and consistent:

handler.go
logger := slog.With("request_id", reqID)
start := time.Now()

// ... do the work ...

logger.Info("order processed",
    "user_id", userID,
    "order_id", orderID,
    "duration_ms", time.Since(start).Milliseconds(),
    "retried", retried,
)

Now the incident query is trivial: grep 'request_id=7f3a9c' to follow one request, or filter duration_ms>1000 to find the slow ones. Two habits make this pay off: log the identifiers you will search by (ids, not names), and log durations as numbers in a fixed unit so comparisons are honest. Everything else is noise you will scroll past.