The java.util.logging package defines a sophisticated and
highly-configurable logging facility that Java applications can use
to emit, filter, format, and output warning, diagnostic, tracing and
debugging messages. An application generates log messages by calling
various methods of a Logger object. The content of
a log message (with other pertinant details such as the time and
sequence number) is encapsulated in a LogRecord
object generated by the Logger. A
Handler object represents a destination for
LogRecord objects. Concrete subclasses of
Handler support destinations such as files and
sockets. Most Handler objects have an associated
Formatter that converts a
LogRecord object into the actual text that is
logged. The subclasses SimpleFormatter and
XMLFormatter produce simple plain-text log
messages and detailed XML logs respectively.
Each log message has an associated severity level. The
Level class defines a type-safe enumeration of
defined levels. Logger and
Handler objects both have an associated
Level, and discard any log messages whose severity
is less than that specified level. In addition to this level-based
filtering, Logger and Handler
objects may also have an associated Filter object
which may be implemented to filter log messages based on any desired
criteria.
Applications that desire complete control over the logs they generate
can create a Logger object, along with
Handler, Formatter and
Filter objects that control the destination,
content, and appearance of the log. Simpler applications need only to
create a Logger for themselves, and can leave the rest to the
LogManager class. LogManager
reads a system-wide configuration file (or a configuration class) and
automatically directs log messages to a standard destination (or
destinations) for the system. In Java 5.0,
LoggingMXBean defines an interface for monitoring
and management of the logging facility through the
javax.management packages (which are beyond the
scope of this book).