Datasheet
Logger Methods
The Logger is the main class used in code that utilizes the logging system. Methods are provided to
obtain a named or anonymous logger, configure and get information about the logger, and log messages.
Obtaining a Logger
The following methods allow you to retrieve a handle to a Logger. These are static methods and provide
an easy way to obtain a
Logger without going through a LogManager.
Method Description
static Logger getAnonymousLogger() Creates an anonymous logger that is exempt
static Logger getAnonymousLogger(String from standard security checks, for use in
resourceBundleName) applets. The anonymous logger is not regis-
tered in the
LogManager namespace, but has
the root logger (“”) as a parent, inheriting level
and handlers from the root logger. A resource
bundle can also be specified for localization of
log messages.
static Logger getLogger(String name) Returns a named logger from the LogManager
static Logger getLogger(String name,
namespace, or if one is not found, creates and
String resourceBundleName) returns a new named logger. A resource bun-
dle can also be specified for localization of log
messages.
Configuring a Logger Object
The following methods allow you to configure a Logger object. You can add and remove handlers, set
the logging level on this
Logger object, set its parent, and choose whether or not log messages should be
passed up the logger hierarchy.
Method Description
void addHandler(Handler handler) Adds a Handler to the logger. Multiple han-
dlers can be added. Also note that the root log-
ger is configured with a set of default
Handlers.
void removeHandler(Handler handler) Removes a specified handler from the list of
handlers on this logger. If the handler is not
found, this method returns silently.
void setLevel(Level newLevel) Sets the log level that this logger will use. Mes-
sage levels lower than the logger’s value will
be automatically discarded. If null is passed
in, the level will be inherited from this log-
ger’s parent.
Table continued on following page
39
Chapter 1: Key Java Language Features and Libraries
05_777106 ch01.qxp 11/28/06 10:43 PM Page 39