LogManager is used to manage named Logger s and
any shared logging properties.
There is one global LogManager instance in the application,
which can be obtained by calling the static method
LogManager.getLogManager() .
All methods on this type can be taken as being thread safe.
The LogManager class can be specified by the
"java.util.logging.manager" system property. If the property is unavailable
or invalid java.util.logging.LogManager will be used by
default.
On initialization, LogManager reads its configuration data
from a properties file, which by default is the "lib/logging.properties" file
in the JRE directory.
However, two system properties can be used instead to customize the
initialization of the LogManager :
- "java.util.logging.config.class"
- "java.util.logging.config.file"
These properties can be set either by using the Preferences API, as a command
line option or by passing the appropriate system property definitions to
JNI_CreateJavaVM.
The "java.util.logging.config.class" property should specify a class name. If
it is set, this class will be loaded and instantiated during
LogManager 's initialization, so that this object's default
constructor can read the initial configuration and define properties for the
LogManager .
The "java.util.logging.config.file" system property can be used to specify a
properties file if the "java.util.logging.config.class" property has not been
used. This file will be read instead of the default properties file.
Some global logging properties are as follows:
- "handlers" - a list of handler classes, separated by whitespace. These
classes must be subclasses of
Handler and must have a public
no-argument constructor. They will be registered with the root
Logger .
- "config" - a list of configuration classes, separated by whitespace.
These classes should also have a public no-argument default constructor,
which should contain all the code for applying that configuration to the
logging system.
Besides global properties, properties for individual Loggers
and Handlers can be specified in the property files. The names
of these properties will start with the fully qualified name of the handler
or logger.
The LogManager organizes Loggers based on their
fully qualified names. For example, "x.y.z" is child of "x.y".
Levels for Loggers can be defined by properties whose name end
with ".level". For example, "alogger.level = 4" sets the level for the logger
"alogger" to 4, Any children of "alogger" will also be given the level 4
unless specified lower down in the properties file. The property ".level"
will set the log level for the root logger.
|