log4j logging hierarchy order
Asked Answered
L

11

230

What is the hierarchy of log4j logging?

DEBUG
INFO
WARN
ERROR
FATAL

Which one provides the highest logging which would be helpful to troubleshoot issues? Can any one provide the order or hierarchy in which logging take place from highest to lowest? Thanks!

L answered 12/10, 2011 at 20:6 Comment(0)
D
419

This table might be helpful for you:

Log Level

Going down the first column, you will see how the log works in each level. i.e for WARN, (FATAL, ERROR and WARN) will be visible. For OFF, nothing will be visible.

Demagogue answered 11/5, 2016 at 15:28 Comment(5)
The terms visibility and item are not self explanatory. I see that the official documentation is also vague on this. The output method such as error, info, debug, etc. of the logger assigns a priority/severity level to the logging message. If the logging really takes effect (the message will be visible) depends on the effective logging level of the logger being used.Fretwork
link broken. please fix or removeEcosystem
Although this answers the question (that's just asking for the "hierarchy order"), I finally downvoted for your poor terminology: going down, "visibility" works, item. Didn't you wish to explain how logger configuration affects the actual logging (passing log events)? Please consider another update. BTW: the table in the official documentation (at the end of the section) differs in treating OFF and ALL, well, after reading some of the source (not finding special cases) I doubt that their table is correct.Fretwork
Thank you Wolf, I have updated the answer according to your comments.Demagogue
I think this is an excellent visualization of the log levels and the expected log message types that would be output for a specific logger level setting. My only suggestion might be to have alternating row colors to guide the viewer that the chart should be interpreted by row rather than column. (i.e. the rows represent logger levels and the columns represent log message types that would be present)Congruity
T
166

Use the force, read the source (excerpt from the Priority and Level class compiled, TRACE level was introduced in version 1.2.12):

public final static int OFF_INT = Integer.MAX_VALUE;
public final static int FATAL_INT = 50000;
public final static int ERROR_INT = 40000;
public final static int WARN_INT  = 30000;
public final static int INFO_INT  = 20000;
public final static int DEBUG_INT = 10000;
public static final int TRACE_INT = 5000; 
public final static int ALL_INT = Integer.MIN_VALUE; 

or the log4j API for the Level class, which makes it quite clear.

When the library decides whether to print a certain statement or not, it computes the effective level of the responsible Logger object (based on configuration) and compares it with the LogEvent's level (depends on which method was used in the code – trace/debug/.../fatal). If LogEvent's level is greater or equal to the Logger's level, the LogEvent is sent to appender(s) – "printed". At the core, it all boils down to an integer comparison and this is where these constants come to action.

Tippet answered 13/10, 2011 at 8:21 Comment(0)
U
63
OFF
FATAL
ERROR
WARN
INFO
DEBUG
TRACE
ALL
Ukrainian answered 12/10, 2011 at 20:8 Comment(4)
check the code where are integer variables for proof docjar.com/html/api/org/apache/log4j/Level.java.htmlUkrainian
at your link it said that "ALL < DEBUG < INFO < WARN < ERROR < FATAL < OFF" and it perfectly the same as I saidUkrainian
Venn diagram OFF() ALL(TRACE(DEBUG(INFO(WARN(ERROR(FATAL))))))Volsung
@L on log4j Logging Levels they use alphabetic order in the first table. Except for the missing trace, they later correctly state that ALL < DEBUG < INFO < WARN < ERROR < FATAL < OFF (wherein < means less important)Fretwork
N
28

Hierarchy of log4j logging levels are as follows in Highest to Lowest order :

  • TRACE
  • DEBUG
  • INFO
  • WARN
  • ERROR
  • FATAL
  • OFF

TRACE log level provides highest logging which would be helpful to troubleshoot issues. DEBUG log level is also very useful to trouble shoot the issues.

You can also refer this link for more information about log levels : https://logging.apache.org/log4j/2.0/manual/architecture.html

Nonmetal answered 13/9, 2015 at 10:56 Comment(0)
J
12

[Taken from http://javarevisited.blogspot.com/2011/05/top-10-tips-on-logging-in-java.html]

DEBUG is the lowest restricted java logging level and we should write everything we need to debug an application, this java logging mode should only be used on Development and Testing environment and must not be used in production environment.

INFO is more restricted than DEBUG java logging level and we should log messages which are informative purpose like Server has been started, Incoming messages, outgoing messages etc in INFO level logging in java.

WARN is more restricted than INFO java logging level and used to log warning sort of messages e.g. Connection lost between client and server. Database connection lost, Socket reaching to its limit. These messages and java logging level are almost important because you can setup alert on these logging messages in java and let your support team monitor health of your java application and react on this warning messages. In Summary WARN level is used to log warning message for logging in Java.

ERROR is the more restricted java logging level than WARN and used to log Errors and Exception, you can also setup alert on this java logging level and alert monitoring team to react on this messages. ERROR is serious for logging in Java and you should always print it.

FATAL java logging level designates very severe error events that will presumably lead the application to abort. After this mostly your application crashes and stopped.

OFF java logging level has the highest possible rank and is intended to turn off logging in Java.

Jehol answered 28/5, 2014 at 17:33 Comment(0)
N
5

I find the term "logging level" to be a bit confusing, so I prefer to think of it like this:

  • Events have a SEVERITY (a level). In log4j this is modelled as an integer.
  • Loggers have a THRESHOLD (aka a LoggerConfig level, used to filter Events)

By convention, log4j defines some Standard Log Levels. In v2.x these are (in order of decending severity): OFF, FATAL, ERROR, WARN, INFO, DEBUG, TRACE, ALL. Note that OFF and ALL are only intended as Logger threshold values, not Event severity levels). You can also add your own custom levels, and assign them a numerical value.

A Logger will ignore any events less severe than its threshold:

  • A threshold of OFF means no logging.
  • A threshold of FATAL means only FATAL events (or worse) are logged.
  • A threshold of ERROR means only ERROR, FATAL (or worse) are logged.
  • A threshold of WARN means only WARN, ERROR, FATAL (or worse) are logged.
  • etc...
  • A threshold of ALL means all events are logged (the most verbose option)

As a diagram (based on the table shown in the log4j v2.x docs) it looks like this:

logging levels cheat sheet

Norrie answered 28/1, 2022 at 14:5 Comment(0)
T
4

Hierarchy order

  1. ALL
  2. TRACE
  3. DEBUG
  4. INFO
  5. WARN
  6. ERROR
  7. FATAL
  8. OFF
Turkoman answered 26/4, 2018 at 11:4 Comment(0)
C
4

To make it clear, there is no defined term like 'hierarchy' in log4j. Yes there are different levels. For troubleshooting you have to select which level you want the logs.

enter image description here

Clynes answered 20/5, 2021 at 20:5 Comment(0)
C
2

Adding .NET log levels for reference

https://learn.microsoft.com/en-us/aspnet/core/fundamentals/logging/?view=aspnetcore-7.0

dotnet core log level

Cascade answered 6/4, 2023 at 18:5 Comment(0)
N
1

The table below illustrates how Level filtering works.

In the table, the vertical header shows the level of the LogEvent you want to configure in your app settings, while the horizontal header shows the Level visibility in associated with the appropriate config.

The intersection identifies whether the LogEvent would be allowed to display logs for further processing (Yes) or discarded (No).

enter image description here

Nainsook answered 2/1 at 10:15 Comment(0)
S
-1

TRACE --> DEBUG--> INFO -->WARN --> ERROR --> FATAL

If Log level is set for WARN. it will log all the WARN and all levels below it.(ERROR and FATAL). If Log level is set for TRACE. it will log all the TRACE and all levels below it.(DEBUG,INFO,WARN,ERROR,FATAL).

Sheenasheeny answered 21/12, 2021 at 20:17 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.