The log levels WARN, ERROR and FATAL are pretty clear. But when is something DEBUG, and when INFO?
I've seen some projects that are annoyingly verbose on the INFO level, but I've also seen code that favors the DEBUG level too much. In both cases, useful information is hidden in the noise.
What are the criteria for determining log levels?
There's no need for a DEBUG2 level. That's what 'TRACE' is for. TRACE is intended to be the absolute lowest level of logging outputting every possible piece of information you might want to see.
To avoid a deluge of information, it is generally not recommended that you enable trace-level logging across an entire project. Instead use 'DEBUG' to find out general information about the bug and where it occurs (hence the name), and then enable TRACE only for that component if you still can't figure it out.
Think about who needs to use each level. In my code I keep DEBUG reserved for a developer output, e.g. output that would only help a developer. VERBOSE is used for a normal user when alot of info is needed. INFO I use to normally show major events (e.g. sending a webpage, checking something important).
And FAIL and WARN are pretty self explanatory.
Informally I use this sort of hierarchy,
I'll generally release with INFO being logged, but only if I know that log files are actually reviewed (and size isn't an issue), otherwise it's WARN.
The convention in my team is to use
debug
if something is calculated in the message, whereasinfo
is used for plain text. So in effectinfo
will show you what's happening anddebug
will show the values of the things that are happening.I don't think there are any hard-and-fast rules; using the log4j-type levels, my 'rules of thumb' are something like:
Not set in stone, but a rough idea of how I think of it.
I tend to target INFO towards the user to give them messages that aren't even warnings. DEBUG tends to be for developer use where I output messages to help trace the flow through the code (with values of variables as well).
I also like another level of DEBUG (DEBUG2?) which gives absolute bucketloads of debug information such as hex dumps of all buffers and so on.