Index (Frames) | Index (No Frames) | Package | Package Tree | Tree
java.util.logging

Class LogManager

java.lang.Object
|
+--java.util.logging.LogManager


public class LogManager

extends Object

The LogManager maintains a hierarchical namespace of Logger objects and manages properties for configuring the logging framework. There exists only one single LogManager per virtual machine. This instance can be retrieved using the static method #getLogManager().

Configuration Process: The global LogManager object is created and configured when the class java.util.logging.LogManager is initialized. The configuration process includes the subsequent steps:

  1. If the system property java.util.logging.manager is set to the name of a subclass of java.util.logging.LogManager, an instance of that subclass is created and becomes the global LogManager. Otherwise, a new instance of LogManager is created.
  2. The LogManager constructor tries to create a new instance of the class specified by the system property java.util.logging.config.class. Typically, the constructor of this class will call LogManager.getLogManager().readConfiguration(java.io.InputStream) for configuring the logging framework. The configuration process stops at this point if the system property java.util.logging.config.class is set (irrespective of whether the class constructor could be called or an exception was thrown).
  3. If the system property java.util.logging.config.class is not set, the configuration parameters are read in from a file and passed to #readConfiguration(java.io.InputStream). The name and location of this file are specified by the system property java.util.logging.config.file.
  4. If the system property java.util.logging.config.file is not set, however, the contents of the URL "{gnu.classpath.home.url}/logging.properties" are passed to #readConfiguration(java.io.InputStream). Here, "{gnu.classpath.home.url}" stands for the value of the system property gnu.classpath.home.url.

Author:

Constructor Summary

LogManager()

Method Summary

synchronized booleanaddLogger(java.util.logging.Logger logger)

Adds a named logger.
synchronized voidaddPropertyChangeListener(java.beans.PropertyChangeListener listener)

Registers a listener which will be notified when the logging properties are re-read.
voidcheckAccess()

Checks whether the current security context allows changing the configuration of the logging framework.
static java.util.logging.LogManagergetLogManager()

Returns the globally shared LogManager instance.
synchronized java.util.logging.LoggergetLogger(java.lang.String name)

Returns a Logger given its name.
synchronized java.util.EnumerationgetLoggerNames()

Returns an Enumeration of currently registered Logger names.
synchronized java.lang.StringgetProperty(java.lang.String name)

Returns the value of a configuration property as a String.
synchronized voidreadConfiguration()

Configures the logging framework by reading a configuration file.
synchronized voidreadConfiguration(java.io.InputStream inputStream)

synchronized voidremovePropertyChangeListener(java.beans.PropertyChangeListener listener)

Unregisters a listener.
synchronized voidreset()

Resets the logging configuration by removing all handlers for registered named loggers and setting their level to null.

Constructor Details

LogManager

protected LogManager()


Method Details

addLogger

public synchronized boolean addLogger(java.util.logging.Logger logger)

Adds a named logger. If a logger with the same name has already been registered, the method returns false without adding the logger.

The LogManager only keeps weak references to registered loggers. Therefore, names can become available after automatic garbage collection.

Parameters:

Returns:

Throws:


addPropertyChangeListener

public synchronized void addPropertyChangeListener(java.beans.PropertyChangeListener listener)

Registers a listener which will be notified when the logging properties are re-read.

Parameters:

  • listener -

checkAccess

public void checkAccess()

Checks whether the current security context allows changing the configuration of the logging framework. For the security context to be trusted, it has to be granted a LoggingPermission("control").

Throws:

  • SecurityException - if a security manager exists and the caller is not granted the permission to control the logging infrastructure.

getLogManager

public static LogManager getLogManager()

Returns the globally shared LogManager instance.


getLogger

public synchronized Logger getLogger(java.lang.String name)

Returns a Logger given its name.

Parameters:

  • name - the name of the logger.
Returns:

  • a named Logger, or null if there is no logger with that name.

getLoggerNames

public synchronized Enumeration getLoggerNames()

Returns an Enumeration of currently registered Logger names. Since other threads can register loggers at any time, the result could be different any time this method is called.

Returns:

  • an Enumeration with the names of the currently registered Loggers.

getProperty

public synchronized String getProperty(java.lang.String name)

Returns the value of a configuration property as a String.

Parameters:

  • name -

readConfiguration

public synchronized void readConfiguration()

Configures the logging framework by reading a configuration file. The name and location of this file are specified by the system property java.util.logging.config.file. If this property is not set, the URL "{gnu.classpath.home.url}/logging.properties" is taken, where "{gnu.classpath.home.url}" stands for the value of the system property gnu.classpath.home.url.

The task of configuring the framework is then delegated to #readConfiguration(java.io.InputStream), which will notify registered listeners after having read the properties.

Throws:

  • SecurityException - if a security manager exists and the caller is not granted the permission to control the logging infrastructure, or if the caller is not granted the permission to read the configuration file.
  • IOException - if there is a problem reading in the configuration file.

readConfiguration

public synchronized void readConfiguration(java.io.InputStream inputStream)

Parameters:

  • inputStream -

removePropertyChangeListener

public synchronized void removePropertyChangeListener(java.beans.PropertyChangeListener listener)

Unregisters a listener. If listener has not been registered previously, nothing happens. Also, no exception is thrown if listener is null.

Parameters:

  • listener -

reset

public synchronized void reset()

Resets the logging configuration by removing all handlers for registered named loggers and setting their level to null. The level of the root logger will be set to Level.INFO.

Throws:

  • SecurityException - if a security manager exists and the caller is not granted the permission to control the logging infrastructure.