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!
[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.
Use the force, read the source (excerpt from the
Priority
andLevel
class compiled, TRACE level was introduced in version 1.2.12):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 theLogEvent
's level (depends on which method was used in the code – trace/debug/.../fatal). IfLogEvent
's level is greater or equal to theLogger
's level, theLogEvent
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.Hierarchy of log4j logging levels are as follows in Highest to Lowest order :
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
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.
Hierarchy order