Understanding Log Levels Using A Practical Example
2 min readJun 3, 2020
Example: Say you have an authentication API, that receives a JSON request to register a new user.
How would you log events that occur in the end-to-end new user registration process? Here’s how I would do it:
- The arrows represent the setting on your logger instance
- For example, if you set the level to DEBUG, you will see all the logs in your logs.
- If you set it to warn, you will only see warning, error and fatal logs. Assuming you are using a single logging instance(i.e. All logs go to a single log file)
Using multiple loggers
- If you use multiple logging instances, you can set each logger to have different levels.
- That is, you can group all the fatal errors in one file, and set alerts according to your specific needs.
Using Logging Levels Effectively
- FATAL — “Logs that describe an unrecoverable application or system crash, or a catastrophic failure that requires immediate attention” — LogLevel Enum
- ERROR — “Logs that highlight when the current flow of execution is stopped due to a failure. These should indicate a failure in the current activity, not an application-wide failure.” — LogLevel Enum
- WARN — “Logs that highlight an abnormal or unexpected event in the application flow, but do not otherwise cause the application execution to stop.” — LogLevel Enum
- INFO — Logs that track the general flow of the application.
- DEBUG —”Logs that are used for interactive investigation during development. These logs should primarily contain information useful for debugging and have no long-term value.” — LogLevel Enum
Reference
- Happy to know what you think in the comments. Thanks for reading.