Cut a log excerpt to what the reader needs

AI-assisted article. Reviewed by Codebuff automated editorial review on 2026-11-13. Examples are illustrative, not real user data.
Logs are the opposite of most evidence: there is always more of them, and pasting more rarely makes the question clearer. A reader who receives ten thousand lines scrolls to the end, finds the last stack trace and answers that one. A short excerpt built around the first failure, with the surrounding context and the request id, gets an answer about the thing that actually broke.
Which failure belongs at the top of an excerpt?
Later errors are often consequences: a connection pool exhausted after the first timeout, a cascade of retries, a client that gave up. Keeping the earliest failure and a handful of lines before it preserves the cause; keeping the last two thousand lines preserves the noise it produced.
If you cannot tell which failure came first, say so and include the boundaries. Two excerpts from the start and the end of the window are usually enough for a reader to see the transition.
Cut with context, not with truncation
Truncating the middle of a file removes the correlation between lines without removing their volume. Selecting a window around a match keeps them together and tells the reader exactly what was kept.
Keep the line numbers if your tool prints them, and keep the timestamp on every line. The timestamps are how a reader matches the excerpt against another system, and a line without one cannot be matched at all.
# Keep the first timeout and six lines after it, with a two-line lead-in
$ grep -n -B2 -A6 "ETIMEDOUT" app.log | head -20
1182: 09:14:02.331Z req=7f3a pool: 9/10 in use
1183: 09:14:02.402Z req=7f3a GET /api/pastes/9c1 -> pending
1184: 09:14:06.418Z req=7f3a upstream ETIMEDOUT after 4000ms
1185: 09:14:06.419Z req=7f3a retry 1/2 scheduled in 200ms
1186: 09:14:06.621Z req=7f3a upstream ETIMEDOUT after 4000ms
1187: 09:14:06.622Z req=7f3a retry 2/2 scheduled in 400ms
1188: 09:14:07.024Z req=7f3a GET /api/pastes/9c1 -> 504
Keep the request id and the window
One identifier ties the excerpt to everything else: the access log, the trace, the dashboard. Include it even when it looks unremarkable, and give the time window you searched, so a reader can look at a different system over the same interval.
If the log is structured, keep the structure instead of flattening it to prose. A JSON line that a reader can parse beats a sentence that describes what the line said.
Say what you removed
A reader has to know whether the excerpt is complete for its window. Say which lines you dropped, especially when they contained user data, tokens or payloads. That way a missing line is an explained gap rather than a suspicious one.
If the full log is needed for a longer investigation, share it as an expiring link with a password rather than as an attachment, and send the excerpt in the question so the first reply does not have to wait for a download.
Sources and editorial review
Prepared with AI assistance and checked against the log and encrypted-paste pages at the reviewed revision: first-failure selection, windowed context versus truncation, identifier and time-window notes, and the removal statement. The log lines are fabricated and use a synthetic request id.