Logging #4: Log Levels

Most logging libraries provide a possibility to set the level from which the logs are emitted. Moreover, the log level is usually an out-of-the-box field in logs. Below I describe my rules that I use when choosing a log level.

  1. Fatal (or Critical)
    Serious error. The application is going to close.
  2. Error
    Application error. However the application can be still running.
  3. Warn (or Warning)
    Volatile error which does not break anything.
  4. Info (or Information)
    Notable events showing the progress of some process. Everything that alters the state any system.
  5. Debug
    Only for ad-hoc debugging or verifying something in production.
  6. Trace (or Verbose)
    Internal system events that are not necessarily observable from the outside, but useful when determining how something happened.

The biggest difference from usual log level usage guidelines is that I avoid to use Debug level as much as possible. I do not have any Debug logging merged to master branch. However, the default logger log level is set to Debug. Normally, I do not see any Debug nor Trace in logs from production. The only rare cases I get these logs are when:

  1. I need to get some data for analyzing some case. Then I add some ad-hoc Debug level logs.
  2. I have totally no idea what is going on. Then I switch the logging level to Trace.

However, even using log levels is also questionable.

Logging series

Leave a comment