In this tutorial, we will
discuss different logging levels and methods. As logging levels and
methods are correlated, we will discuss them with some examples.
Logging Levels
The logging levels can be set to
the logger. The standard levels are ordered as ALL, TRACE, DEBUG, INFO,
WARN, ERROR, FATAL, and OFF. There is a provision to set custom levels
by inheriting the org.apache.log4j.Level class. The description of the
logging levels is shown in the following table.
Level Description
ALL It is used to log all
the events.
TRACE It is used for
fine-grained informational events.
DEBUG This level is
mainly used at the time of debugging the application.
INFO This level is used
to log the informational messages to represent the progress of the
application.
WARN It is used to log
harmful situations, which are to be avoided.
ERROR This one is used
where error events are generated but the error does not terminate the
application.
FATAL It designates the
error events which cause the abort of the application.
OFF This is the highest
level and is used to turn off logging.
There are different ways to set
the logging level. One is setting the log level within Java source code
and in another approach, the log level can be set using the properties
file.
First, we will discuss how to
set up the log level in the Java source code. Later we will discuss how
to set up the log level using log4j.properties file.
Logging Methods
For the above-mentioned log
levels, the associated methods of the Logger class are as follows:
1. public void trace(Object msg)
2. public void debug(Object msg)
3. public void info(Object msg)
4. public void warn(Object msg)
5. public void error(Object msg)
6. public void fatal(Object msg)

No comments:
Post a Comment
Note: Only a member of this blog may post a comment.