|
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), the following is borrowed
from the log4j API
(http://jakarta.apache.org/log4j/docs/api/index.html):
-
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.
In addition, there are two special levels of logging available: (descriptions
borrowed from the log4j API
http://jakarta.apache.org/log4j/docs/api/index.html):
The behaviour of loggers is hierarchical. The following table illustrates
this:
A logger will only output messages that are of a level greater than or
equal to it. If the level of a logger is not set it will inherit the level of
the closest ancestor. So if a logger is created in the package
com.foo.bar and no level is set for it, it will
inherit the level of the logger created in com.foo.
If no logger was created in com.foo, the logger
created in com.foo.bar will inherit the level of the
root logger, the root logger is always instantiated
and available, the root logger is assigned the level
DEBUG.
There are a number of ways to create a logger, one can retrieve the root
logger:
Logger logger = Logger.getRootLogger();
|
One can create a new logger:
Logger logger = Logger.getLogger("MyLogger");
|
More usually, one instantiates a static logger globally, based on the name
of the class:
static Logger logger = Logger.getLogger(test.class);
|
All these create a logger called "logger", one can set the level with:
logger.setLevel((Level)Level.WARN);
|
You can use any of 7 levels; Level.DEBUG, Level.INFO, Level.WARN,
Level.ERROR, Level.FATAL, Level.ALL and Level.OFF.
|