Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there a near-consensus guideline for log levels?

Tags:

java

c#

logging

I've been influenced by the log levels that I and my teams have used at my last two companies. I'll share ours here but keep in mind this bit is subjective:

  • Fatal - Your app is going down.
  • Error - This operation or thread is crashing and burning. The app may be able to continue.
  • Warn - The current operation may be able to continue but an engineer needs to investigate something.
  • Info - Explain what your operation is doing.
  • Debug - Explanation of operations that may get pretty spammy (inner loops, etc).

Now, my objective question is whether there is a highly-agreed upon style defined in this regard. The answer may be no. But if there is such a standard, can you point a URL to it?

Also note that I don't really care what threshold is actually configured to log somewhere useful in a deployed / production environment. Rather, my question is restricted to guidelines that those of us who write code should use.

I'm putting a C# tag and Java tag on my question. It's possible we'd have different guidelines in these two camps but there are probably only cultural reasons that we'd differ, not conceptual reasons.

like image 660
Matthew Lund Avatar asked May 15 '11 22:05

Matthew Lund


People also ask

What should I expect from the trace logging level?

You can expect the TRACE logging level to be very verbose. You can use it for example to annotate each step in the algorithm or each individual query with parameters in your code.

Why do you need a logging framework?

When combined with a logging framework you can easily limit the information that is written to the log destination of your choice. When setting the log level that you are interested in your logging framework you effectively limit all less important log levels to be ignored.

What are log levels and logs?

Log files contain a wealth of information about all of the events that take place within a system and log levels allow users to categorize those events by type and severity so they can be treated accordingly.

What are the benefits of the log levels?

The log levels can help in reducing the information noise and reduce alert fatigue. Before continuing with the description of the log levels themselves it would be good to know where the log levels come from.


2 Answers

I'm not even sure that whether something is "highly-agreed" upon can be answered objectively.

The Log4j and Log4Net libraries certainly employ the level definitions that you've described. See this link.

Somebody might yet produce a counter-example of a library that uses a differently defined set of logging levels.

like image 139
Andrew Shepherd Avatar answered Oct 22 '22 20:10

Andrew Shepherd


from SSCLI (.NET sources):

namespace System {
    ...
    [Serializable]
    internal enum LogLevel {
        Trace  = 0,
        Status = 20,
        Warning= 40,
        Error  = 50,
        Panic  = 100,
    }
    ...
}

note the [warning] values) I rely on this variant of distribution. anyway it's Microsoft)

like image 42
Mikant Avatar answered Oct 22 '22 20:10

Mikant