java.util.logging
Class LogManager

java.lang.Object sample code for java.lang.Object definition code for java.lang.Object 
  extended by java.util.logging.LogManager

public class LogManager
extends Object sample code for java.lang.Object definition code for java.lang.Object

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:

These two properties may be set via the Preferences API, or as command line property definitions to the "java" command, or as system property definitions passed to JNI_CreateJavaVM.

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 are first searched on the system class path before any user 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.

Since:
1.4

Field Summary
static String sample code for java.lang.String definition code for java.lang.String LOGGING_MXBEAN_NAME sample code for java.util.logging.LogManager.LOGGING_MXBEAN_NAME definition code for java.util.logging.LogManager.LOGGING_MXBEAN_NAME
          String representation of the ObjectName sample code for javax.management.ObjectName definition code for javax.management.ObjectName for LoggingMXBean sample code for java.util.logging.LoggingMXBean definition code for java.util.logging.LoggingMXBean .
 
Constructor Summary
protected LogManager sample code for java.util.logging.LogManager.LogManager() definition code for java.util.logging.LogManager.LogManager() ()
          Protected constructor.
 
Method Summary
 boolean addLogger sample code for java.util.logging.LogManager.addLogger(java.util.logging.Logger) definition code for java.util.logging.LogManager.addLogger(java.util.logging.Logger) (Logger sample code for java.util.logging.Logger definition code for java.util.logging.Logger  logger)
          Add a named logger.
 void addPropertyChangeListener sample code for java.util.logging.LogManager.addPropertyChangeListener(java.beans.PropertyChangeListener) definition code for java.util.logging.LogManager.addPropertyChangeListener(java.beans.PropertyChangeListener) (PropertyChangeListener sample code for java.beans.PropertyChangeListener definition code for java.beans.PropertyChangeListener  l)
          Adds an event listener to be invoked when the logging properties are re-read.
 void checkAccess sample code for java.util.logging.LogManager.checkAccess() definition code for java.util.logging.LogManager.checkAccess() ()
          Check that the current context is trusted to modify the logging configuration.
 Logger sample code for java.util.logging.Logger definition code for java.util.logging.Logger getLogger sample code for java.util.logging.LogManager.getLogger(java.lang.String) definition code for java.util.logging.LogManager.getLogger(java.lang.String) (String sample code for java.lang.String definition code for java.lang.String  name)
          Method to find a named logger.
 Enumeration sample code for java.util.Enumeration definition code for java.util.Enumeration <String sample code for java.lang.String definition code for java.lang.String > getLoggerNames sample code for java.util.logging.LogManager.getLoggerNames() definition code for java.util.logging.LogManager.getLoggerNames() ()
          Get an enumeration of known logger names.
static LoggingMXBean sample code for java.util.logging.LoggingMXBean definition code for java.util.logging.LoggingMXBean getLoggingMXBean sample code for java.util.logging.LogManager.getLoggingMXBean() definition code for java.util.logging.LogManager.getLoggingMXBean() ()
          Returns LoggingMXBean for managing loggers.
static LogManager sample code for java.util.logging.LogManager definition code for java.util.logging.LogManager getLogManager sample code for java.util.logging.LogManager.getLogManager() definition code for java.util.logging.LogManager.getLogManager() ()
          Return the global LogManager object.
 String sample code for java.lang.String definition code for java.lang.String getProperty sample code for java.util.logging.LogManager.getProperty(java.lang.String) definition code for java.util.logging.LogManager.getProperty(java.lang.String) (String sample code for java.lang.String definition code for java.lang.String  name)
          Get the value of a logging property.
 void readConfiguration sample code for java.util.logging.LogManager.readConfiguration() definition code for java.util.logging.LogManager.readConfiguration() ()
          Reinitialize the logging properties and reread the logging configuration.
 void readConfiguration sample code for java.util.logging.LogManager.readConfiguration(java.io.InputStream) definition code for java.util.logging.LogManager.readConfiguration(java.io.InputStream) (InputStream sample code for java.io.InputStream definition code for java.io.InputStream  ins)
          Reinitialize the logging properties and reread the logging configuration from the given stream, which should be in java.util.Properties format.
 void removePropertyChangeListener sample code for java.util.logging.LogManager.removePropertyChangeListener(java.beans.PropertyChangeListener) definition code for java.util.logging.LogManager.removePropertyChangeListener(java.beans.PropertyChangeListener) (PropertyChangeListener sample code for java.beans.PropertyChangeListener definition code for java.beans.PropertyChangeListener  l)
          Removes an event listener for property change events.
 void reset sample code for java.util.logging.LogManager.reset() definition code for java.util.logging.LogManager.reset() ()
          Reset the logging configuration.
 
Methods inherited from class java.lang.Object sample code for java.lang.Object definition code for java.lang.Object
clone sample code for java.lang.Object.clone() definition code for java.lang.Object.clone() , equals sample code for java.lang.Object.equals(java.lang.Object) definition code for java.lang.Object.equals(java.lang.Object) , finalize sample code for java.lang.Object.finalize() definition code for java.lang.Object.finalize() , getClass sample code for java.lang.Object.getClass() definition code for java.lang.Object.getClass() , hashCode sample code for java.lang.Object.hashCode() definition code for java.lang.Object.hashCode() , notify sample code for java.lang.Object.notify() definition code for java.lang.Object.notify() , notifyAll sample code for java.lang.Object.notifyAll() definition code for java.lang.Object.notifyAll() , toString sample code for java.lang.Object.toString() definition code for java.lang.Object.toString() , wait sample code for java.lang.Object.wait() definition code for java.lang.Object.wait() , wait sample code for java.lang.Object.wait(long) definition code for java.lang.Object.wait(long) , wait sample code for java.lang.Object.wait(long, int) definition code for java.lang.Object.wait(long, int)
 

Field Detail

LOGGING_MXBEAN_NAME sample code for java.util.logging.LogManager.LOGGING_MXBEAN_NAME

public static final String sample code for java.lang.String definition code for java.lang.String  LOGGING_MXBEAN_NAME
String representation of the ObjectName sample code for javax.management.ObjectName definition code for javax.management.ObjectName for LoggingMXBean sample code for java.util.logging.LoggingMXBean definition code for java.util.logging.LoggingMXBean .

See Also:
Constant Field Values
Constructor Detail

LogManager sample code for java.util.logging.LogManager() definition code for java.util.logging.LogManager()

protected LogManager()
Protected constructor. This is protected so that container applications (such as J2EE containers) can subclass the object. It is non-public as it is intended that there only be one LogManager object, whose value is retrieved by calling Logmanager.getLogManager.

Method Detail

getLogManager sample code for java.util.logging.LogManager.getLogManager() definition code for java.util.logging.LogManager.getLogManager()

public static LogManager sample code for java.util.logging.LogManager definition code for java.util.logging.LogManager  getLogManager()
Return the global LogManager object.


addPropertyChangeListener sample code for java.util.logging.LogManager.addPropertyChangeListener(java.beans.PropertyChangeListener) definition code for java.util.logging.LogManager.addPropertyChangeListener(java.beans.PropertyChangeListener)

public void addPropertyChangeListener(PropertyChangeListener sample code for java.beans.PropertyChangeListener definition code for java.beans.PropertyChangeListener  l)
                               throws SecurityException sample code for java.lang.SecurityException definition code for java.lang.SecurityException 
Adds an event listener to be invoked when the logging properties are re-read. Adding multiple instances of the same event Listener results in multiple entries in the property event listener table.

Parameters:
l - event listener
Throws:
SecurityException sample code for java.lang.SecurityException definition code for java.lang.SecurityException - if a security manager exists and if the caller does not have LoggingPermission("control").
NullPointerException sample code for java.lang.NullPointerException definition code for java.lang.NullPointerException - if the PropertyChangeListener is null.

removePropertyChangeListener sample code for java.util.logging.LogManager.removePropertyChangeListener(java.beans.PropertyChangeListener) definition code for java.util.logging.LogManager.removePropertyChangeListener(java.beans.PropertyChangeListener)

public void removePropertyChangeListener(PropertyChangeListener sample code for java.beans.PropertyChangeListener definition code for java.beans.PropertyChangeListener  l)
                                  throws SecurityException sample code for java.lang.SecurityException definition code for java.lang.SecurityException 
Removes an event listener for property change events. If the same listener instance has been added to the listener table through multiple invocations of addPropertyChangeListener, then an equivalent number of removePropertyChangeListener invocations are required to remove all instances of that listener from the listener table.

Returns silently if the given listener is not found.

Parameters:
l - event listener (can be null)
Throws:
SecurityException sample code for java.lang.SecurityException definition code for java.lang.SecurityException - if a security manager exists and if the caller does not have LoggingPermission("control").

addLogger sample code for java.util.logging.LogManager.addLogger(java.util.logging.Logger) definition code for java.util.logging.LogManager.addLogger(java.util.logging.Logger)

public boolean addLogger(Logger sample code for java.util.logging.Logger definition code for java.util.logging.Logger  logger)
Add a named logger. This does nothing and returns false if a logger with the same name is already registered.

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.

Parameters:
logger - the new logger.
Returns:
true if the argument logger was registered successfully, false if a logger of that name already exists.
Throws:
NullPointerException sample code for java.lang.NullPointerException definition code for java.lang.NullPointerException - if the logger name is null.

getLogger sample code for java.util.logging.LogManager.getLogger(java.lang.String) definition code for java.util.logging.LogManager.getLogger(java.lang.String)

public Logger sample code for java.util.logging.Logger definition code for java.util.logging.Logger  getLogger(String sample code for java.lang.String definition code for java.lang.String  name)
Method to find a named logger.

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.

Parameters:
name - name of the logger
Returns:
matching logger or null if none is found

getLoggerNames sample code for java.util.logging.LogManager.getLoggerNames() definition code for java.util.logging.LogManager.getLoggerNames()

public Enumeration sample code for java.util.Enumeration definition code for java.util.Enumeration <String sample code for java.lang.String definition code for java.lang.String > getLoggerNames()
Get an enumeration of known logger names.

Note: Loggers may be added dynamically as new classes are loaded. This method only reports on the loggers that are currently registered.

Returns:
enumeration of logger name strings

readConfiguration sample code for java.util.logging.LogManager.readConfiguration() definition code for java.util.logging.LogManager.readConfiguration()

public void readConfiguration()
                       throws IOException sample code for java.io.IOException definition code for java.io.IOException ,
                              SecurityException sample code for java.lang.SecurityException definition code for java.lang.SecurityException 
Reinitialize the logging properties and reread the logging configuration.

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.

Throws:
SecurityException sample code for java.lang.SecurityException definition code for java.lang.SecurityException - if a security manager exists and if the caller does not have LoggingPermission("control").
IOException sample code for java.io.IOException definition code for java.io.IOException - if there are IO problems reading the configuration.

reset sample code for java.util.logging.LogManager.reset() definition code for java.util.logging.LogManager.reset()

public void reset()
           throws SecurityException sample code for java.lang.SecurityException definition code for java.lang.SecurityException 
Reset the logging configuration.

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.

Throws:
SecurityException sample code for java.lang.SecurityException definition code for java.lang.SecurityException - if a security manager exists and if the caller does not have LoggingPermission("control").

readConfiguration sample code for java.util.logging.LogManager.readConfiguration(java.io.InputStream) definition code for java.util.logging.LogManager.readConfiguration(java.io.InputStream)

public void readConfiguration(InputStream sample code for java.io.InputStream definition code for java.io.InputStream  ins)
                       throws IOException sample code for java.io.IOException definition code for java.io.IOException ,
                              SecurityException sample code for java.lang.SecurityException definition code for java.lang.SecurityException 
Reinitialize the logging properties and reread the logging configuration from the given stream, which should be in java.util.Properties format. A PropertyChangeEvent will be fired after the properties are read.

Any log level definitions in the new configuration file will be applied using Logger.setLevel(), if the target Logger exists.

Parameters:
ins - stream to read properties from
Throws:
SecurityException sample code for java.lang.SecurityException definition code for java.lang.SecurityException - if a security manager exists and if the caller does not have LoggingPermission("control").
IOException sample code for java.io.IOException definition code for java.io.IOException - if there are problems reading from the stream.

getProperty sample code for java.util.logging.LogManager.getProperty(java.lang.String) definition code for java.util.logging.LogManager.getProperty(java.lang.String)

public String sample code for java.lang.String definition code for java.lang.String  getProperty(String sample code for java.lang.String definition code for java.lang.String  name)
Get the value of a logging property. The method returns null if the property is not found.

Parameters:
name - property name
Returns:
property value

checkAccess sample code for java.util.logging.LogManager.checkAccess() definition code for java.util.logging.LogManager.checkAccess()

public void checkAccess()
                 throws SecurityException sample code for java.lang.SecurityException definition code for java.lang.SecurityException 
Check that the current context is trusted to modify the logging configuration. This requires LoggingPermission("control").

If the check fails we throw a SecurityException, otherwise we return normally.

Throws:
SecurityException sample code for java.lang.SecurityException definition code for java.lang.SecurityException - if a security manager exists and if the caller does not have LoggingPermission("control").

getLoggingMXBean sample code for java.util.logging.LogManager.getLoggingMXBean() definition code for java.util.logging.LogManager.getLoggingMXBean()

public static LoggingMXBean sample code for java.util.logging.LoggingMXBean definition code for java.util.logging.LoggingMXBean  getLoggingMXBean()
Returns LoggingMXBean for managing loggers. The LoggingMXBean can also obtained from the platform MBeanServer sample code for java.lang.management.ManagementFactory.getPlatformMBeanServer() definition code for java.lang.management.ManagementFactory.getPlatformMBeanServer() method.

Returns:
a LoggingMXBean sample code for java.util.logging.LoggingMXBean definition code for java.util.logging.LoggingMXBean object.
See Also:
ManagementFactory sample code for java.lang.management.ManagementFactory definition code for java.lang.management.ManagementFactory