log4j logging hierarchy order
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!
This table might be helpful for you:
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.
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.