Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

When to use the different log levels

There are different ways to log messages, in order of fatality:

  1. FATAL

  2. ERROR

  3. WARN

  4. INFO

  5. DEBUG

  6. TRACE

How do I decide when to use which?

What's a good heuristic to use?

like image 309
raoulsson Avatar asked Jan 08 '10 22:01

raoulsson


People also ask

What are the five levels of logging?

The possible values are: QUIET, FATAL, ERROR, INFO, VERBOSE, DEBUG, DEBUG1, DEBUG2, and DEBUG3. The default is INFO.

What should I log at information level?

You use the INFO logging level to record messages about routine application operation. Those are entries you usually don't care that much about, to be honest. If things go bad during development, you'll be looking at DEBUG entries. When things go bad in production, ERROR entries are what you're looking for.


2 Answers

I generally subscribe to the following convention:

  • Trace - Only when I would be "tracing" the code and trying to find one part of a function specifically.
  • Debug - Information that is diagnostically helpful to people more than just developers (IT, sysadmins, etc.).
  • Info - Generally useful information to log (service start/stop, configuration assumptions, etc). Info I want to always have available but usually don't care about under normal circumstances. This is my out-of-the-box config level.
  • Warn - Anything that can potentially cause application oddities, but for which I am automatically recovering. (Such as switching from a primary to backup server, retrying an operation, missing secondary data, etc.)
  • Error - Any error which is fatal to the operation, but not the service or application (can't open a required file, missing data, etc.). These errors will force user (administrator, or direct user) intervention. These are usually reserved (in my apps) for incorrect connection strings, missing services, etc.
  • Fatal - Any error that is forcing a shutdown of the service or application to prevent data loss (or further data loss). I reserve these only for the most heinous errors and situations where there is guaranteed to have been data corruption or loss.
like image 82
GrayWizardx Avatar answered Oct 19 '22 13:10

GrayWizardx


Would you want the message to get a system administrator out of bed in the middle of the night?

  • yes -> error
  • no -> warn
like image 27
pm100 Avatar answered Oct 19 '22 12:10

pm100