public class LogManager extends Object
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.
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 methods on the LogManager object are multi-thread safe.
Modifier | Constructor and Description |
---|---|
protected |
LogManager()
Protected constructor.
|
Modifier and Type | Method and Description |
---|---|
boolean |
addLogger(Logger logger)
Add a named logger.
|
void |
checkAccess()
Check that the current context is trusted to modify the logging
configuration.
|
Logger |
getLogger(String name)
Method to find a named logger.
|
Enumeration<String> |
getLoggerNames()
Get an enumeration of known logger names.
|
static LogManager |
getLogManager()
Return the global LogManager object.
|
void |
reset()
Reset the logging configuration.
|
protected LogManager()
public boolean addLogger(Logger logger)
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.
logger
- the new logger.NullPointerException
- if the logger name is null.public void checkAccess() throws SecurityException
If the check fails we throw a SecurityException, otherwise we return normally.
SecurityException
- if a security manager exists and if
the caller does not have LoggingPermission("control").public Logger getLogger(String name)
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.
It is also important to note that the Logger associated with the
String name
may be garbage collected at any time if there
is no strong reference to the Logger. The caller of this method
must check the return value for null in order to properly handle
the case where the Logger has been garbage collected.
name
- name of the loggerpublic Enumeration<String> getLoggerNames()
Note: Loggers may be added dynamically as new classes are loaded.
This method only reports on the loggers that are currently registered.
It is also important to note that this method only returns the name
of a Logger, not a strong reference to the Logger itself.
The returned String does nothing to prevent the Logger from being
garbage collected. In particular, if the returned name is passed
to LogManager.getLogger()
, then the caller must check the
return value from LogManager.getLogger()
for null to properly
handle the case where the Logger has been garbage collected in the
time since its name was returned by this method.
public static LogManager getLogManager()
public void reset() throws SecurityException
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.
SecurityException
- if a security manager exists and if
the caller does not have LoggingPermission("control").Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved. Use of this specification is subject to license terms.