Log levels
A log level is a routing decision: this line heads toward the pager, that one
heads to the archive. Teams miss in both directions, stamping routine events
error until alerts mean nothing, or hiding real failures at debug where no one
looks. The level is a contract about urgency, and a broken contract trains
people to stop reading the logs at all.
Method
- Reserve error for act now. An error line means the request failed and a
person is needed: a charge could not be captured, a required dependency is
down. If the code recovered on its own, it is not an error. Error volume
should track incidents, not background weather.
- Use warn for a trend short of failure. A retry that eventually
succeeded, a deprecated endpoint still called, a climbing cache-miss rate.
Warn is the watch-this channel: nobody wakes for one, but a flood of them is
the tremor before the error storm.
- Use info for a request's milestones. Order placed, user logged in, job
finished, each with the ids to trace it. Info is what you read to
reconstruct normal behavior, so keep it to state changes, not every function
entry, and one request stays a readable handful of lines.
- Use debug for mechanics you want only when hunting. Variable values, the
branch taken, payload shapes. Debug ships off in production and turns on for
one service or one request mid-investigation. It earns its verbosity by
being silent the rest of the time.
- Never log a caught-and-handled exception at error. If you retried and
recovered, that is warn or info. Logging every swallowed exception at error
is the fastest way to make the error stream worthless and the pager numb.
- Make the level adjustable at runtime. Wire a flag or endpoint to lift one
logger to debug with no redeploy. During an incident you want more detail
from one component in seconds, not after a build, then drop it back to info
so cost and noise fall.
Signals
- Filtered to error only, is every line something a human should act on?
- Could you enable debug for one service mid-incident without shipping code?
- Does one healthy request at info produce a few lines, not hundreds?
Boundaries
Levels decide urgency, not shape: how each line is structured is
structured-logging's concern. Whether an error-level line should page is
alerting-design. Some stacks add trace or fatal rungs; follow the project's
existing ladder rather than bolting on a parallel one.
1---2name: log-levels3description: Assign log levels deliberately so error wakes a human, warn flags a trend, and info and debug explain later without burying the signal. Use when logs are either silent during real failures or so noisy that nobody trusts them.4---56# Log levels78A log level is a routing decision: this line heads toward the pager, that one9heads to the archive. Teams miss in both directions, stamping routine events10error until alerts mean nothing, or hiding real failures at debug where no one11looks. The level is a contract about urgency, and a broken contract trains12people to stop reading the logs at all.1314## Method15161. **Reserve error for act now.** An error line means the request failed and a17 person is needed: a charge could not be captured, a required dependency is18 down. If the code recovered on its own, it is not an error. Error volume19 should track incidents, not background weather.202. **Use warn for a trend short of failure.** A retry that eventually21 succeeded, a deprecated endpoint still called, a climbing cache-miss rate.22 Warn is the watch-this channel: nobody wakes for one, but a flood of them is23 the tremor before the error storm.243. **Use info for a request's milestones.** Order placed, user logged in, job25 finished, each with the ids to trace it. Info is what you read to26 reconstruct normal behavior, so keep it to state changes, not every function27 entry, and one request stays a readable handful of lines.284. **Use debug for mechanics you want only when hunting.** Variable values, the29 branch taken, payload shapes. Debug ships off in production and turns on for30 one service or one request mid-investigation. It earns its verbosity by31 being silent the rest of the time.325. **Never log a caught-and-handled exception at error.** If you retried and33 recovered, that is warn or info. Logging every swallowed exception at error34 is the fastest way to make the error stream worthless and the pager numb.356. **Make the level adjustable at runtime.** Wire a flag or endpoint to lift one36 logger to debug with no redeploy. During an incident you want more detail37 from one component in seconds, not after a build, then drop it back to info38 so cost and noise fall.3940## Signals4142- Filtered to error only, is every line something a human should act on?43- Could you enable debug for one service mid-incident without shipping code?44- Does one healthy request at info produce a few lines, not hundreds?4546## Boundaries4748Levels decide urgency, not shape: how each line is structured is49structured-logging's concern. Whether an error-level line should page is50alerting-design. Some stacks add trace or fatal rungs; follow the project's51existing ladder rather than bolting on a parallel one.