java.util.logging

Class 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 {@link #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:

The LogManager has a level of INFO by default, and this will be inherited by Loggers unless they override it either by properties or programmatically.

Field Summary
static StringLOGGING_MXBEAN_NAME
The object name for the logging management bean.
Constructor Summary
protected LogManager()
Method Summary
booleanaddLogger(Logger logger)
Adds a named logger.
voidaddPropertyChangeListener(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.
LoggergetLogger(String name)
Returns a Logger given its name.
Enumeration<String>getLoggerNames()
Returns an Enumeration of currently registered Logger names.
static LoggingMXBeangetLoggingMXBean()
Return the logging bean.
static LogManagergetLogManager()
Returns the globally shared LogManager instance.
StringgetProperty(String name)
Returns the value of a configuration property as a String.
voidreadConfiguration()
Configures the logging framework by reading a configuration file.
voidreadConfiguration(InputStream inputStream)
voidremovePropertyChangeListener(PropertyChangeListener listener)
Unregisters a listener.
voidreset()
Resets the logging configuration by removing all handlers for registered named loggers and setting their level to null.

Field Detail

LOGGING_MXBEAN_NAME

public static final String LOGGING_MXBEAN_NAME
The object name for the logging management bean.

Since: 1.5

Constructor Detail

LogManager

protected LogManager()

Method Detail

addLogger

public boolean addLogger(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: logger the logger to be added.

Returns: trueif logger was added, false otherwise.

Throws: NullPointerException if name is null.

addPropertyChangeListener

public void addPropertyChangeListener(PropertyChangeListener listener)
Registers a listener which will be notified when the logging properties are re-read.

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.

getLogger

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

UNKNOWN: java.lang.NullPointerException if name is null.

getLoggerNames

public Enumeration<String> 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.

getLoggingMXBean

public static LoggingMXBean getLoggingMXBean()
Return the logging bean. There is a single logging bean per VM instance.

Since: 1.5

getLogManager

public static LogManager getLogManager()
Returns the globally shared LogManager instance.

getProperty

public String getProperty(String name)
Returns the value of a configuration property as a String.

readConfiguration

public 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 {@link #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 void readConfiguration(InputStream inputStream)

removePropertyChangeListener

public void removePropertyChangeListener(PropertyChangeListener listener)
Unregisters a listener. If listener has not been registered previously, nothing happens. Also, no exception is thrown if listener is null.

reset

public 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.