java16.util.logging
Class LogManager

java.lang.Object
  extended by java16.util.logging.LogManager

public class LogManager
extends java.lang.Object


Field Summary
static java.lang.String LOGGING_MXBEAN_NAME
          String representation of the javax.management.ObjectName for LoggingMXBean.
 
Method Summary
 boolean addLogger(Logger logger)
          Add a named logger.
 void addPropertyChangeListener(java.beans.PropertyChangeListener l)
          Adds 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.
 Logger getLogger(java.lang.String name)
          Method to find a named logger.
 java.util.Enumeration<java.lang.String> getLoggerNames()
          Get an enumeration of known logger names.
static java.util.logging.LoggingMXBean getLoggingMXBean()
          Returns LoggingMXBean for managing loggers.
static LogManager getLogManager()
          Return the global LogManager object.
 java.lang.String getProperty(java.lang.String name)
          Get the value of a logging property.
 void readConfiguration()
          Reinitialize the logging properties and reread the logging configuration.
 void readConfiguration(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(java.beans.PropertyChangeListener l)
          Removes an event listener for property change events.
 void reset()
          Reset the logging configuration.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

LOGGING_MXBEAN_NAME

public static final java.lang.String LOGGING_MXBEAN_NAME
String representation of the javax.management.ObjectName for LoggingMXBean.

Since:
1.5
See Also:
Constant Field Values
Method Detail

getLogManager

public static LogManager getLogManager()
Return the global LogManager object.


addPropertyChangeListener

public void addPropertyChangeListener(java.beans.PropertyChangeListener l)
                               throws 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:
java.lang.SecurityException - if a security manager exists and if the caller does not have LoggingPermission("control").
java.lang.NullPointerException - if the PropertyChangeListener is null.

removePropertyChangeListener

public void removePropertyChangeListener(java.beans.PropertyChangeListener l)
                                  throws 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:
java.lang.SecurityException - if a security manager exists and if the caller does not have LoggingPermission("control").

addLogger

public boolean addLogger(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:
java.lang.NullPointerException - if the logger name is null.

getLogger

public Logger getLogger(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

public java.util.Enumeration<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

public void readConfiguration()
                       throws java.io.IOException,
                              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:
java.lang.SecurityException - if a security manager exists and if the caller does not have LoggingPermission("control").
java.io.IOException - if there are IO problems reading the configuration.

reset

public void reset()
           throws 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:
java.lang.SecurityException - if a security manager exists and if the caller does not have LoggingPermission("control").

readConfiguration

public void readConfiguration(java.io.InputStream ins)
                       throws java.io.IOException,
                              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:
java.lang.SecurityException - if a security manager exists and if the caller does not have LoggingPermission("control").
java.io.IOException - if there are problems reading from the stream.

getProperty

public java.lang.String getProperty(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

public void checkAccess()
                 throws 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:
java.lang.SecurityException - if a security manager exists and if the caller does not have LoggingPermission("control").

getLoggingMXBean

public static java.util.logging.LoggingMXBean getLoggingMXBean()
Returns LoggingMXBean for managing loggers. The LoggingMXBean can also obtained from the platform MBeanServer method.

Returns:
a LoggingMXBean object.
Since:
1.5
See Also:
java.lang.management.ManagementFactory