What are the Log4j Levels?

Published on Author bloggeroneLeave a comment

Log4J Levels

Loggers may be assigned levels. The set of possible levels, that is DEBUG, INFO, WARN, ERROR and FATAL are defined in the org.apache.log4j.Level class.

If a given logger is not assigned a level, then it inherits one from its closest ancestor with an assigned level. The root logger resides at the top of the logger hierarchy. It always exists and always has an assigned level.

The logger is the core component of the logging process. In log4j, there are 5 normal levels Levels of logger available (not including custom Levels):

static Level DEBUG – The DEBUG Level designates fine-grained informational events that are most useful to debug an application.
static Level INFO – The INFO level designates informational messages that highlight the progress of the application at coarse-grained level.
static Level WARN – The WARN level designates potentially harmful situations.
static Level ERROR – The ERROR level designates error events that might still allow the application to continue running.
static Level FATAL – The FATAL level designates very severe error events that will presumably lead the application to abort.

Custom logj4 levels

Log4j’s levels are mostly sufficient for all common applications. Rarely you may need a new Level apart from the levels provided by log4j. In that case you can extend org.apache.log4j.Level class and have your own custom level implementation.

In addition, there are two special levels of logging available:

static Level ALL -The ALL Level has the lowest possible rank and is intended to turn on all logging.
static Level OFF – The OFF Level has the highest possible rank and is intended to turn off logging.

Also, Log4j provides you configuration file based level setting which makes change the logging level without modifying the source code. The configuration can be setup using .xml or .properties file



Leave a Reply

Your email address will not be published. Required fields are marked *