Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to formalize a proper strategy for choosing logging levels?

Selecting logging levels for messages has always bugged me. Although I do try to make sensible decisions there isn't any true standard I conform to. Are there any standards?

What strategy do you employ when deciding upon logging levels in your web-application?

The logging library that I use has the following levels:

  • debug
  • info
  • warning
  • error
  • critical
  • alert

Thanks in advance!

like image 389
Marijn Huizendveld Avatar asked Oct 11 '22 06:10

Marijn Huizendveld


1 Answers

Usage of log levels are quite different and not carved in stone. In my company we mainly use Log4j with the levels fatal, error, warn, info and debug. Our guidelines are:

  • FATAL is a very severe error that will lead the application to abort. You should explain here why your application died. This error can not be caused by wrong user actions.
  • ERROR is for error that your application is doing something it should not, but it might allow it to continue running. This error can also not be caused by wrong user actions.
  • WARN is for potentially harmful situations in application usage. Your application is running and will not crash because of this issue. Maybe there is a server timeout or another rare but not unexpected situation. This might also be caused by dumb user actions. ;)
  • INFO is for informational messages, which tell something about the progress of the appliation. Think about it as: "what is the app doing?" or "where did that data come from?".
  • DEBUG is for very fine-grained informational events that are most useful to debug an application. Logging for this level is turned off by default. You can use it for logging method parameters or specific variables in an error-prone part of your application.

You can adopt these error levels to almost any logging libraries. For example you could use my description of FATAL for your CRITICAL level.

like image 200
Chris Avatar answered Oct 12 '22 23:10

Chris