I recently had a moment to think about how I use log levels. I've used logging in various frameworks and standard libraries across many languages. While some levels are standard, not all tools expose the same levels and not all tools have all of the levels I've come to want.
Level | Meaning | Alert | Enabled in Production |
---|---|---|---|
trace | Emit practically every variable in scope or "got here" type messages | Never | Only in madness |
debug | Emit critical variables or function entry/return | Never | When unable to reproduce behavior in lower environments |
info | Critical section entry/exit, expensive section input parameter or return inspection | No | Yes for you code, No for dependencies |
warning | Recoverable, accounted-for problems that could be expensive en masse | Yes, when exceeding a frequency threshold, a human should intervene at their convenience | Yes, except to silence an alert when it's been triaged and cannot be immediately fixed |
error | Unaccounted-for problems or critical dependency failures, but not grave enough to halt | Yes, a human should intervene ASAP | Of course |
fatal OR critical | Unaccounted-for, unexpected failures that must stop the process emitted moments before exit | Absolutely, a human must intervene before the process can restart | Absolutely |
I've generally colored them with ANSI colors in log output like this:
- fatal/critical: ⚫🟥 black text on red background
- error: 🔴⬛ red text on black background
- warning: 🟡 yellow or gold text on a transparent background
- info: 🔵 blue text on a transparent background
- debug: 🟢 green text on a transparent background
- trace: 🟠orange text on a transparent background
These colors work for my non-colorblind eyes. There are color schemes that are probably better to account for those for whom my colors aren't differentiable, so think of them and comment if you have one you like.
I'm doing mostly data pipelines for the last few years but even in my web service days, these were the levels we wanted and rules we followed. One team even looked into aspect-oriented programming in order to get the level of granularity we wanted for trace logging once.
An earlier version was originally posted here.
Top comments (0)