Java Reference
In-Depth Information
he logging APIs are structured so that there are several logging levels and calls on the logger
APIs can be appropriately enabled or disabled and at diferent levels. his is done with an idea
to optimize the cost associated with the logging activity. If logging is disabled for a given log
level, then the logger can make a cheap comparison test and return. On the other hand, if log-
ging is enabled for a given log level, the logger is still careful to minimize costs before passing the
LogRecord into the handlers. he localization and formatting aspects of logging activity also
come at a cost. hey are considered as the expensive part of the logging activity. he localization
and formatting could be deferred until the handler requests them.
9.4.2 The Core Classes and Interfaces
here is just one interface called ilter and the remaining of the logging activities in the Java
development are managed through classes. he most important classes that manage logging activi-
ties are LogManager , Logger , Level , Handler , Formatter , and LogRecord . We will
delve into some important details of these classes and interfaces in the following subsections.
9.4.2.1 The Logger Class
Loggers are normally named entities, using dot-separated names. Developers appropriately use the
namespace for associating diferent namespaces with diferent type of loggers and log levels. he
namespace for loggers is hierarchical in nature and are managed by the LogManager . In addi-
tion to named loggers, it is possible to create anonymous loggers (anonymous loggers don't appear
in the shared namespace). Loggers keep track of their parent loggers through the use of the logging
namespace. Loggers may inherit various attributes from their parents in the logger namespace. In
particular, a logger may inherit the following—logging level, handlers, and resource bundle names.
he logging methods are grouped in ive main categories:
Set of “log” methods that take a log level, a message string, and optionally some parameters
to the message string.
Set of “logp” methods (
p for “precise”) that are like the “log” methods but also take an
explicit source class name and method name.
Set of “logrb” method (
rb for “resource bundle”) that are like the “logp” method, but these
methods also take an explicit resource bundle name for use in localizing the log message.
here are some utility methods for tracing method entries (the “entering” methods), method
returns (the “exiting” methods), and throwing exceptions (the “throwing” methods).
Set of convenience methods for use in the very simplest of cases, when a developer simply wants
to log a simple string at a given log level. hese methods are named after the standard level
names (for example, “severe,” “warning,” “info,” etc.) and take a single argument—a message.
9.4.2.2 The Level Class
Any log message needs to be associated with a log level. he level class deines seven standard log
levels with the help of ields, ranging from severe (the highest priority, with the highest value) to
inest (the lowest priority, with the lowest value). he level serves as a rough guide to the impor-
tance and urgency of a log message, and the application developer can appropriately choose the
level to log a particular activity. Log level objects essentially encapsulate an integer value, with
Search WWH ::




Custom Search