Skip to content

Most visited

Recently visited

navigation
Added in API level 1

LogManager

public class LogManager
extends Object

java.lang.Object
   ↳ java.util.logging.LogManager


LogManager is used to maintain configuration properties of the logging framework, and to manage a hierarchical namespace of all named Logger objects.

There is only one global LogManager instance in the application, which can be get by calling static method getLogManager(). This instance is created and initialized during class initialization and cannot be changed.

The LogManager class can be specified by java.util.logging.manager system property, if the property is unavailable or invalid, the default class LogManager will be used.

On initialization, LogManager reads its configuration from a properties file, which by default is the "lib/logging.properties" in the JRE directory.

However, two optional system properties can be used to customize the initial configuration process of LogManager.

These two properties can be set in three ways, by the Preferences API, by the "java" command line property definitions, or by system property definitions passed to JNI_CreateJavaVM.

The "java.util.logging.config.class" should specifies a class name. If it is set, this given class will be loaded and instantiated during LogManager initialization, so that this object's default constructor can read the initial configuration and define properties for LogManager.

If "java.util.logging.config.class" property is not set, or it is invalid, or some exception is thrown during the instantiation, then the "java.util.logging.config.file" system property can be used to specify a properties file. The LogManager will read initial configuration from this file.

If neither of these properties is defined, or some exception is thrown during these two properties using, the LogManager will read its initial configuration from default properties file, as described above.

The global logging properties may include:

This class, together with any handler and configuration classes associated with it, must be loaded from the system classpath when LogManager configuration occurs.

Besides global properties, the properties for loggers and Handlers can be specified in the property files. The names of these properties will start with the complete dot separated names for the handlers or loggers.

In the LogManager's hierarchical namespace, Loggers are organized based on their dot separated names. For example, "x.y.z" is child of "x.y".

Levels for Loggers can be defined by properties whose name end with ".level". Thus "alogger.level" defines a level for the logger named as "alogger" and for all its children in the naming hierarchy. Log levels properties are read and applied in the same order as they are specified in the property file. The root logger's level can be defined by the property named as ".level".

This class is thread safe. It is an error to synchronize on a LogManager while synchronized on a Logger.

Summary

Constants

String LOGGING_MXBEAN_NAME

The String value of the LoggingMXBean's ObjectName.

Protected constructors

LogManager()

Default constructor.

Public methods

boolean addLogger(Logger logger)

Add a given logger into the hierarchical namespace.

void addPropertyChangeListener(PropertyChangeListener l)

Add a PropertyChangeListener, which will be invoked when the properties are reread.

void checkAccess()

Does nothing.

static LogManager getLogManager()

Get the global LogManager instance.

Logger getLogger(String name)

Get the logger with the given name.

Enumeration<String> getLoggerNames()

Get a Enumeration of all registered logger names.

static LoggingMXBean getLoggingMXBean()

Get the LoggingMXBean instance.

String getProperty(String name)

Get the value of property with given name.

void readConfiguration()

Re-initialize the properties and configuration.

void readConfiguration(InputStream ins)

Re-initialize the properties and configuration from the given InputStream

Notice : No PropertyChangeEvent are fired.

void removePropertyChangeListener(PropertyChangeListener l)

Remove a PropertyChangeListener, do nothing if the given listener is not found.

void reset()

Reset configuration.

Inherited methods

From class java.lang.Object

Constants

LOGGING_MXBEAN_NAME

Added in API level 1
String LOGGING_MXBEAN_NAME

The String value of the LoggingMXBean's ObjectName.

Constant Value: "java.util.logging:type=Logging"

Protected constructors

LogManager

Added in API level 1
LogManager ()

Default constructor. This is not public because there should be only one LogManager instance, which can be get by LogManager.getLogManager(). This is protected so that application can subclass the object.

Public methods

addLogger

Added in API level 1
boolean addLogger (Logger logger)

Add a given logger into the hierarchical namespace. The Logger.addLogger() factory methods call this method to add newly created Logger. This returns false if a logger with the given name has existed in the namespace

Note that the LogManager may only retain weak references to registered loggers. In order to prevent Logger objects from being unexpectedly garbage collected it is necessary for applications to maintain references to them.

Parameters
logger Logger: the logger to be added.
Returns
boolean true if the given logger is added into the namespace successfully, false if the given logger exists in the namespace.

addPropertyChangeListener

Added in API level 3
void addPropertyChangeListener (PropertyChangeListener l)

Add a PropertyChangeListener, which will be invoked when the properties are reread.

Parameters
l PropertyChangeListener: the PropertyChangeListener to be added.

checkAccess

Added in API level 1
void checkAccess ()

Does nothing.

getLogManager

Added in API level 1
LogManager getLogManager ()

Get the global LogManager instance.

Returns
LogManager the global LogManager instance

getLogger

Added in API level 1
Logger getLogger (String name)

Get the logger with the given name.

Parameters
name String: name of logger
Returns
Logger logger with given name, or null if nothing is found.

getLoggerNames

Added in API level 1
Enumeration<String> getLoggerNames ()

Get a Enumeration of all registered logger names.

Returns
Enumeration<String> enumeration of registered logger names

getLoggingMXBean

Added in API level 3
LoggingMXBean getLoggingMXBean ()

Get the LoggingMXBean instance. this implementation always throws an UnsupportedOperationException.

Returns
LoggingMXBean the LoggingMXBean instance

getProperty

Added in API level 1
String getProperty (String name)

Get the value of property with given name.

Parameters
name String: the name of property
Returns
String the value of property

readConfiguration

Added in API level 1
void readConfiguration ()

Re-initialize the properties and configuration. The initialization process is same as the LogManager instantiation.

Notice : No PropertyChangeEvent are fired.

Throws
IOException if any IO related problems happened.

readConfiguration

Added in API level 1
void readConfiguration (InputStream ins)

Re-initialize the properties and configuration from the given InputStream

Notice : No PropertyChangeEvent are fired.

Parameters
ins InputStream: the input stream
Throws
IOException if any IO related problems happened.

removePropertyChangeListener

Added in API level 3
void removePropertyChangeListener (PropertyChangeListener l)

Remove a PropertyChangeListener, do nothing if the given listener is not found.

Parameters
l PropertyChangeListener: the PropertyChangeListener to be removed.

reset

Added in API level 1
void reset ()

Reset configuration.

All handlers are closed and removed from any named loggers. All loggers' level is set to null, except the root logger's level is set to Level.INFO.

This site uses cookies to store your preferences for site-specific language and display options.

Hooray!

This class requires API level or higher

This doc is hidden because your selected API level for the documentation is . You can change the documentation API level with the selector above the left navigation.

For more information about specifying the API level your app requires, read Supporting Different Platform Versions.