

0 / 2 embers
0 / 3000 xp
click for more info
Complete a lesson to start your streak
click for more info
Difficulty: 5
click for more info
Not enough gems
Cost: 6 gems
1: Structured Logging
incomplete
2: Slog Package
incomplete
3: Log Levels
incomplete
4: More Log Levels
incomplete
5: Key-Value Pairs
incomplete
6: Output Formats
incomplete
Back
ctrl+,
Next
ctrl+.
This lesson's interactive features are locked, please to keep using them
I previously mentioned the conventional 4 log levels:
Many projects use even more levels like TRACE, FATAL, or PANIC, but as I already mentioned... I'd avoid them. Let's go a bit deeper on each level.
Use Debug for detailed information that's useful for debugging, but not necessary for normal operation. Storing Debug logs can be expensive and noisy, so it's common to disable them in production and keep them enabled locally.
You can almost think of Debug logs as permanent "print debugging" statements.
Sometimes I even throw them in during local development, and delete them before committing if they're super ad-hoc.
Info level logs are used to record important events that are not errors. For example:
They're useful for understanding normal system behavior, and can help identify trends over time. In many cases, Info logs can be replaced with aggregated metrics – more on that later.
Whoops. Did I go out of order? Yes.. but intentionally!
Warn is the level between Info and Error, so when should you use it?
To be blunt: I think you shouldn't!
It's a weird gray area between Info and Error, and in my experience, if it's not an actual error, it should usually be demoted to Info. Here's how I think about it:
Error.400 and use Info.Error level logs record... errors. Obviously.
They should include enough information to diagnose the problem. Things like:
System errors and user errors are not the same. A request for a non-existent resource should return a 404 Not Found – but the system didn't fail.
System errors (in general, that corresponds to 5XX codes in web-speak) should be logged as Error level logs. User errors (4XX codes) should be logged as Debug or Info level logs or not logged at all.