|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object java.util.logging.LogManager
There is a single global LogManager object that is used to maintain a set of shared state about Loggers and log services.
This LogManager object:
The global LogManager object can be retrieved using LogManager.getLogManager(). The LogManager object is created during class initialization and cannot subsequently be changed.
At startup the LogManager class is located using the java.util.logging.manager system property.
By default, the LogManager reads its initial configuration from a properties file "lib/logging.properties" in the JRE directory. If you edit that property file you can change the default logging configuration for all uses of that JRE.
In addition, the LogManager uses two optional system properties that allow more control over reading the initial configuration:
If the "java.util.logging.config.class" property is set, then the property value is treated as a class name. The given class will be loaded, an object will be instantiated, and that object's constructor is responsible for reading in the initial configuration. (That object may use other system properties to control its configuration.) The alternate configuration class can use readConfiguration(InputStream) to define properties in the LogManager.
If "java.util.logging.config.class" property is not set, then the "java.util.logging.config.file" system property can be used to specify a properties file (in java.util.Properties format). The initial logging configuration will be read from this file.
If neither of these properties is defined then, as described above, the LogManager will read its initial configuration from a properties file "lib/logging.properties" in the JRE directory.
The properties for loggers and Handlers will have names starting with the dot-separated name for the handler or logger.
The global logging properties may include:
Note that all classes loaded during LogManager configuration must be on the system class path. That includes the LogManager class, any config classes, and any handler classes.
Loggers are organized into a naming hierarchy based on their dot separated names. Thus "a.b.c" is a child of "a.b", but "a.b1" and a.b2" are peers.
All properties whose names end with ".level" are assumed to define log levels for Loggers. Thus "foo.level" defines a log level for the logger called "foo" and (recursively) for any of its children in the naming hierarchy. Log Levels are applied in the order they are defined in the properties file. Thus level settings for child nodes in the tree should come after settings for their parents. The property name ".level" can be used to set the level for the root of the tree.
All methods on the LogManager object are multi-thread safe.
Nested Class Summary | |
private class |
LogManager.Cleaner
|
private static class |
LogManager.LogNode
|
private class |
LogManager.RootLogger
|
Field Summary | |
private java.beans.PropertyChangeSupport |
changes
|
private boolean |
deathImminent
|
private static Level |
defaultLevel
|
private static Handler[] |
emptyHandlers
|
private boolean |
initializedGlobalHandlers
|
private Hashtable |
loggers
|
private static LogManager |
manager
|
private java.security.Permission |
ourPermission
|
private Properties |
props
|
private boolean |
readPrimordialConfiguration
|
private LogManager.LogNode |
root
|
private Logger |
rootLogger
|
Constructor Summary | |
protected |
LogManager()
Protected constructor. |
Method Summary | |
boolean |
addLogger(Logger logger)
Add a named logger. |
void |
addPropertyChangeListener(java.beans.PropertyChangeListener l)
Add an event listener to be invoked when the logging properties are re-read. |
void |
checkAccess()
Check that the current context is trusted to modify the logging configuration. |
private static void |
doSetLevel(Logger logger,
Level level)
|
private static void |
doSetParent(Logger logger,
Logger parent)
|
private LogManager.LogNode |
findNode(String name)
|
(package private) boolean |
getBooleanProperty(String name,
boolean defaultValue)
|
(package private) Filter |
getFilterProperty(String name,
Filter defaultValue)
|
(package private) Formatter |
getFormatterProperty(String name,
Formatter defaultValue)
|
(package private) int |
getIntProperty(String name,
int defaultValue)
|
(package private) Level |
getLevelProperty(String name,
Level defaultValue)
|
Logger |
getLogger(String name)
Method to find a named logger. |
Enumeration |
getLoggerNames()
Get an enumeration of known logger names. |
static LogManager |
getLogManager()
Return the global LogManager object. |
String |
getProperty(String name)
Get the value of a logging property. |
(package private) String |
getStringProperty(String name,
String defaultValue)
|
private void |
initializeGlobalHandlers()
|
private String[] |
parseClassNames(String propertyName)
|
void |
readConfiguration()
Reinitialize the logging properties and reread the logging configuration. |
void |
readConfiguration(InputStream ins)
Reinitialize the logging properties and reread the logging configuration from the given stream, which should be in java.util.Properties format. |
private void |
readPrimordialConfiguration()
|
void |
removePropertyChangeListener(java.beans.PropertyChangeListener l)
Remove an event listener for property change events. |
void |
reset()
Reset the logging configuration. |
private void |
resetLogger(String name)
|
private void |
setLevelsOnExistingLoggers()
|
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
private static LogManager manager
private static final Handler[] emptyHandlers
private Properties props
private java.beans.PropertyChangeSupport changes
private static final Level defaultLevel
private Hashtable loggers
private LogManager.LogNode root
private Logger rootLogger
private volatile boolean readPrimordialConfiguration
private boolean initializedGlobalHandlers
private boolean deathImminent
private java.security.Permission ourPermission
Constructor Detail |
protected LogManager()
Method Detail |
public static LogManager getLogManager()
private void readPrimordialConfiguration()
public void addPropertyChangeListener(java.beans.PropertyChangeListener l) throws SecurityException
l
- event listener
SecurityException
- if a security manager exists and if
the caller does not have LoggingPermission("control").public void removePropertyChangeListener(java.beans.PropertyChangeListener l) throws SecurityException
Returns silently if the given listener is not found.
l
- event listener
SecurityException
- if a security manager exists and if
the caller does not have LoggingPermission("control").public boolean addLogger(Logger logger)
The Logger factory methods call this method to register each newly created Logger.
The application should retain its own reference to the Logger object to avoid it being garbage collected. The LogManager may only retain a weak reference.
logger
- the new logger.
NullPointerException
- if the logger name is null.private static void doSetLevel(Logger logger, Level level)
private static void doSetParent(Logger logger, Logger parent)
private LogManager.LogNode findNode(String name)
public Logger getLogger(String name)
Note that since untrusted code may create loggers with arbitrary names this method should not be relied on to find Loggers for security sensitive logging.
name
- name of the logger
public Enumeration getLoggerNames()
Note: Loggers may be added dynamically as new classes are loaded. This method only reports on the loggers that are currently registered.
public void readConfiguration() throws IOException, SecurityException
The same rules are used for locating the configuration properties as are used at startup. So normally the logging properties will be re-read from the same file that was used at startup.
Any log level definitions in the new configuration file will be applied using Logger.setLevel(), if the target Logger exists.
A PropertyChangeEvent will be fired after the properties are read.
SecurityException
- if a security manager exists and if
the caller does not have LoggingPermission("control").
IOException
- if there are IO problems reading the configuration.public void reset() throws SecurityException
For all named loggers, the reset operation removes and closes all Handlers and (except for the root logger) sets the level to null. The root logger's level is set to Level.INFO.
SecurityException
- if a security manager exists and if
the caller does not have LoggingPermission("control").private void resetLogger(String name)
private String[] parseClassNames(String propertyName)
public void readConfiguration(InputStream ins) throws IOException, SecurityException
Any log level definitions in the new configuration file will be applied using Logger.setLevel(), if the target Logger exists.
ins
- stream to read properties from
SecurityException
- if a security manager exists and if
the caller does not have LoggingPermission("control").
IOException
- if there are problems reading from the stream.public String getProperty(String name)
name
- property name
String getStringProperty(String name, String defaultValue)
int getIntProperty(String name, int defaultValue)
boolean getBooleanProperty(String name, boolean defaultValue)
Level getLevelProperty(String name, Level defaultValue)
Filter getFilterProperty(String name, Filter defaultValue)
Formatter getFormatterProperty(String name, Formatter defaultValue)
private void initializeGlobalHandlers()
public void checkAccess() throws SecurityException
If the check fails we throw a SecurityException, otherwise we return normally.
SecurityException
- if a security manager exists and if
the caller does not have LoggingPermission("control").private void setLevelsOnExistingLoggers()
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |