java.lang.Object | |
↳ | java.util.logging.Logger |
Loggers are used to log records to certain outputs, including file, console, etc. They use various handlers to actually do the output-dependent operations.
Client applications can get named loggers by calling the getLogger
methods. They can also get anonymous loggers by calling the
getAnonymousLogger
methods. Named loggers are organized in a
namespace hierarchy managed by a log manager. The naming convention is
usually the same as java package's naming convention, that is using
dot-separated strings. Anonymous loggers do not belong to any namespace.
Loggers "inherit" log level setting from their parent if their own level is
set to null
. This is also true for the resource bundle. The logger's
resource bundle is used to localize the log messages if no resource bundle
name is given when a log method is called. If getUseParentHandlers()
returns true
, loggers also inherit their parent's handlers. In this
context, "inherit" only means that "behavior" is inherited. The internal
field values will not change, for example, getLevel()
still returns
null
.
When loading a given resource bundle, the logger first tries to use the context classloader. If that fails, it tries the system classloader. And if that still fails, it searches up the class stack and uses each class's classloader to try to locate the resource bundle.
Some log methods accept log requests that do not specify the source class and source method. In these cases, the logging framework will automatically infer the calling class and method, but this is not guaranteed to be accurate.
Once a LogRecord
object has been passed into the logging framework,
it is owned by the logging framework and the client applications should not
use it any longer.
All methods of this class are thread-safe.
Constants | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
Logger | global | The global logger is provided as convenience for casual use. |
Protected Constructors | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
Constructs a
Logger object with the supplied name and resource
bundle name; notifiyParentHandlers is set to true . |
Public Methods | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
Adds a handler to this logger.
| |||||||||||
Logs a message of level
Level.CONFIG ; the message is transmitted
to all subscribed handlers. | |||||||||||
Logs a message indicating that a method has been entered.
| |||||||||||
Logs a message indicating that a method has been entered.
| |||||||||||
Logs a message indicating that a method has been entered.
| |||||||||||
Logs a message indicating that a method is exited.
| |||||||||||
Logs a message indicating that a method is exited.
| |||||||||||
Logs a message of level
Level.FINE ; the message is transmitted
to all subscribed handlers. | |||||||||||
Logs a message of level
Level.FINER ; the message is transmitted
to all subscribed handlers. | |||||||||||
Logs a message of level
Level.FINEST ; the message is transmitted
to all subscribed handlers. | |||||||||||
Gets an anonymous logger to use internally in a thread.
| |||||||||||
Gets an anonymous logger to use internally in a thread.
| |||||||||||
Gets the filter used by this logger.
| |||||||||||
Gets all the handlers associated with this logger.
| |||||||||||
Gets the logging level of this logger.
| |||||||||||
Gets a named logger.
| |||||||||||
Gets a named logger associated with the supplied resource bundle.
| |||||||||||
Gets the name of this logger,
null for anonymous loggers. | |||||||||||
Gets the nearest parent of this logger in the namespace, a
null
value will be returned if called on the root logger. | |||||||||||
Gets the loaded resource bundle used by this logger to localize logging
messages.
| |||||||||||
Gets the name of the loaded resource bundle used by this logger to
localize logging messages.
| |||||||||||
Gets the flag which indicates whether to use the handlers of this
logger's parent to publish incoming log records, potentially recursively
up the namespace.
| |||||||||||
Logs a message of level
Level.INFO ; the message is transmitted
to all subscribed handlers. | |||||||||||
Determines whether this logger will actually log messages of the
specified level.
| |||||||||||
Logs a message of the specified level with the supplied
Throwable
object. | |||||||||||
Logs a message of the specified level with the supplied parameter array.
| |||||||||||
Logs a message of the specified level.
| |||||||||||
Logs a message of the specified level with the supplied parameter.
| |||||||||||
Logs a given log record.
| |||||||||||
Logs a message of the given level with the specified source class name,
source method name and parameter array.
| |||||||||||
Logs a message of the given level with the specified source class name
and source method name.
| |||||||||||
Logs a message of the given level with the specified source class name,
source method name and parameter.
| |||||||||||
Logs a message of the given level with the specified source class name,
source method name and
Throwable object. | |||||||||||
Logs a message of the given level with the specified source class name
and source method name, using the given resource bundle to localize the
message.
| |||||||||||
Logs a message of the given level with the specified source class name,
source method name and
Throwable object, using the given resource
bundle to localize the message. | |||||||||||
Logs a message of the given level with the specified source class name,
source method name and parameter, using the given resource bundle to
localize the message.
| |||||||||||
Logs a message of the given level with the specified source class name,
source method name and parameter array, using the given resource bundle
to localize the message.
| |||||||||||
Removes a handler from this logger.
| |||||||||||
Sets the filter used by this logger.
| |||||||||||
Sets the logging level for this logger.
| |||||||||||
Sets the parent of this logger in the namespace.
| |||||||||||
Sets the flag which indicates whether to use the handlers of this
logger's parent, potentially recursively up the namespace.
| |||||||||||
Logs a message of level
Level.SEVERE ; the message is transmitted
to all subscribed handlers. | |||||||||||
Logs a message indicating that an exception is thrown.
| |||||||||||
Logs a message of level
Level.WARNING ; the message is
transmitted to all subscribed handlers. |
[Expand]
Inherited Methods | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
From class java.lang.Object
|
The global logger is provided as convenience for casual use.
Constructs a Logger
object with the supplied name and resource
bundle name; notifiyParentHandlers
is set to true
.
Notice : Loggers use a naming hierarchy. Thus "z.x.y" is a child of "z.x".
name | the name of this logger, may be null for anonymous
loggers. |
---|---|
resourceBundleName | the name of the resource bundle used to localize logging
messages, may be null . |
MissingResourceException | if the specified resource bundle can not be loaded. |
---|
Adds a handler to this logger. The name
will be fed with log
records received by this logger.
handler | the handler object to add, cannot be null . |
---|
SecurityException | if a security manager determines that the caller does not have the required permission. |
---|
Logs a message of level Level.CONFIG
; the message is transmitted
to all subscribed handlers.
msg | the message to log. |
---|
Logs a message indicating that a method has been entered. A log record
with log level Level.FINER
, log message "ENTRY", the specified
source class name, source method name and array of parameters is
submitted for logging.
sourceClass | the source class name. |
---|---|
sourceMethod | the source method name. |
params | an array of parameters for the method call. |
Logs a message indicating that a method has been entered. A log record
with log level Level.FINER
, log message "ENTRY", the specified
source class name, source method name and one parameter is submitted for
logging.
sourceClass | the source class name. |
---|---|
sourceMethod | the source method name. |
param | the parameter for the method call. |
Logs a message indicating that a method has been entered. A log record
with log level Level.FINER
, log message "ENTRY", the specified
source class name and source method name is submitted for logging.
sourceClass | the calling class name. |
---|---|
sourceMethod | the method name. |
Logs a message indicating that a method is exited. A log record with log
level Level.FINER
, log message "RETURN", the specified source
class name, source method name and return value is submitted for logging.
sourceClass | the source class name. |
---|---|
sourceMethod | the source method name. |
result | the return value of the method call. |
Logs a message indicating that a method is exited. A log record with log
level Level.FINER
, log message "RETURN", the specified source
class name and source method name is submitted for logging.
sourceClass | the calling class name. |
---|---|
sourceMethod | the method name. |
Logs a message of level Level.FINE
; the message is transmitted
to all subscribed handlers.
msg | the message to log. |
---|
Logs a message of level Level.FINER
; the message is transmitted
to all subscribed handlers.
msg | the message to log. |
---|
Logs a message of level Level.FINEST
; the message is transmitted
to all subscribed handlers.
msg | the message to log. |
---|
Gets an anonymous logger to use internally in a thread. Anonymous loggers are not registered in the log manager's namespace. No security checks will be performed when updating an anonymous logger's control settings.
The anonymous loggers' parent is set to be the root logger. This way it inherits the default logging level and handlers from the root logger.
Gets an anonymous logger to use internally in a thread. Anonymous loggers are not registered in the log manager's namespace. No security checks will be performed when updating an anonymous logger's control settings.
The anonymous loggers' parent is set to be the root logger. This way it inherits default logging level and handlers from the root logger.
resourceBundleName | the name of the resource bundle used to localize log messages. |
---|
MissingResourceException | if the specified resource bundle can not be loaded. |
---|
Gets the filter used by this logger.
null
.
Gets all the handlers associated with this logger.
Gets the logging level of this logger. A null
level indicates
that this logger inherits its parent's level.
Gets a named logger. The returned logger may already exist or may be
newly created. In the latter case, its level will be set to the
configured level according to the LogManager
's properties.
name | the name of the logger to get, cannot be null . |
---|
MissingResourceException | If the specified resource bundle can not be loaded. |
---|
Gets a named logger associated with the supplied resource bundle. The resource bundle will be used to localize logging messages.
name | the name of the logger to get, cannot be null . |
---|---|
resourceBundleName | the name of the resource bundle, may be null . |
IllegalArgumentException | if the logger identified by name is associated with a
resource bundle and its name is not equal to
resourceBundleName . |
---|---|
MissingResourceException | if the name of the resource bundle cannot be found. |
Gets the name of this logger, null
for anonymous loggers.
Gets the nearest parent of this logger in the namespace, a null
value will be returned if called on the root logger.
Gets the loaded resource bundle used by this logger to localize logging
messages. If the value is null
, the parent's resource bundle will be
inherited.
Gets the name of the loaded resource bundle used by this logger to
localize logging messages. If the value is null
, the parent's resource
bundle name will be inherited.
Gets the flag which indicates whether to use the handlers of this logger's parent to publish incoming log records, potentially recursively up the namespace.
true
if set to use parent's handlers, false
otherwise.
Logs a message of level Level.INFO
; the message is transmitted
to all subscribed handlers.
msg | the message to log. |
---|
Determines whether this logger will actually log messages of the
specified level. The effective level used to do the determination may be
inherited from its parent. The default level is Level.INFO
.
l | the level to check. |
---|
true
if this logger will actually log this level,
otherwise false
.
Logs a message of the specified level with the supplied Throwable
object. The message is then transmitted to all subscribed handlers.
logLevel | the level of the given message. |
---|---|
msg | the message to log. |
thrown | the Throwable object associated with the event that is
logged.
|
Logs a message of the specified level with the supplied parameter array. The message is then transmitted to all subscribed handlers.
logLevel | the level of the given message |
---|---|
msg | the message to log. |
params | the parameter array associated with the event that is logged. |
Logs a message of the specified level. The message is transmitted to all subscribed handlers.
logLevel | the level of the specified message. |
---|---|
msg | the message to log. |
Logs a message of the specified level with the supplied parameter. The message is then transmitted to all subscribed handlers.
logLevel | the level of the given message. |
---|---|
msg | the message to log. |
param | the parameter associated with the event that is logged. |
Logs a given log record. Only records with a logging level that is equal
or greater than this logger's level will be submitted to this logger's
handlers for logging. If getUseParentHandlers()
returns true
, the log record will also be submitted to the handlers of this
logger's parent, potentially recursively up the namespace.
Since all other log methods call this method to actually perform the logging action, subclasses of this class can override this method to catch all logging activities.
record | the log record to be logged. |
---|
Logs a message of the given level with the specified source class name, source method name and parameter array.
logLevel | the level of the given message. |
---|---|
sourceClass | the source class name. |
sourceMethod | the source method name. |
msg | the message to be logged. |
params | the parameter array associated with the event that is logged. |
Logs a message of the given level with the specified source class name and source method name.
logLevel | the level of the given message. |
---|---|
sourceClass | the source class name. |
sourceMethod | the source method name. |
msg | the message to be logged. |
Logs a message of the given level with the specified source class name, source method name and parameter.
logLevel | the level of the given message |
---|---|
sourceClass | the source class name |
sourceMethod | the source method name |
msg | the message to be logged |
param | the parameter associated with the event that is logged. |
Logs a message of the given level with the specified source class name,
source method name and Throwable
object.
logLevel | the level of the given message. |
---|---|
sourceClass | the source class name. |
sourceMethod | the source method name. |
msg | the message to be logged. |
thrown | the Throwable object.
|
Logs a message of the given level with the specified source class name
and source method name, using the given resource bundle to localize the
message. If bundleName
is null, the empty string or not valid then
the message is not localized.
logLevel | the level of the given message. |
---|---|
sourceClass | the source class name. |
sourceMethod | the source method name. |
bundleName | the name of the resource bundle used to localize the message. |
msg | the message to be logged. |
Logs a message of the given level with the specified source class name,
source method name and Throwable
object, using the given resource
bundle to localize the message. If bundleName
is null, the empty
string or not valid then the message is not localized.
logLevel | the level of the given message |
---|---|
sourceClass | the source class name |
sourceMethod | the source method name |
bundleName | the name of the resource bundle used to localize the message. |
msg | the message to be logged. |
thrown | the Throwable object.
|
Logs a message of the given level with the specified source class name,
source method name and parameter, using the given resource bundle to
localize the message. If bundleName
is null, the empty string
or not valid then the message is not localized.
logLevel | the level of the given message. |
---|---|
sourceClass | the source class name. |
sourceMethod | the source method name. |
bundleName | the name of the resource bundle used to localize the message. |
msg | the message to be logged. |
param | the parameter associated with the event that is logged. |
Logs a message of the given level with the specified source class name,
source method name and parameter array, using the given resource bundle
to localize the message. If bundleName
is null, the empty string
or not valid then the message is not localized.
logLevel | the level of the given message. |
---|---|
sourceClass | the source class name. |
sourceMethod | the source method name. |
bundleName | the name of the resource bundle used to localize the message. |
msg | the message to be logged. |
params | the parameter array associated with the event that is logged. |
Removes a handler from this logger. If the specified handler does not exist then this method has no effect.
handler | the handler to be removed. |
---|
SecurityException | if a security manager determines that the caller does not have the required permission. |
---|
Sets the filter used by this logger.
newFilter | the filter to set, may be null . |
---|
SecurityException | if a security manager determines that the caller does not have the required permission. |
---|
Sets the logging level for this logger. A null
level indicates
that this logger will inherit its parent's level.
newLevel | the logging level to set. |
---|
SecurityException | if a security manager determines that the caller does not have the required permission. |
---|
Sets the parent of this logger in the namespace. This method should be
used by the LogManager
object only.
parent | the parent logger to set. |
---|
SecurityException | if a security manager determines that the caller does not have the required permission. |
---|
Sets the flag which indicates whether to use the handlers of this logger's parent, potentially recursively up the namespace.
notifyParentHandlers | the new flag indicating whether to use the parent's handlers. |
---|
SecurityException | if a security manager determines that the caller does not have the required permission. |
---|
Logs a message of level Level.SEVERE
; the message is transmitted
to all subscribed handlers.
msg | the message to log. |
---|
Logs a message indicating that an exception is thrown. A log record with
log level Level.FINER
, log message "THROW", the specified source
class name, source method name and the Throwable
object is
submitted for logging.
sourceClass | the source class name. |
---|---|
sourceMethod | the source method name. |
thrown | the Throwable object.
|
Logs a message of level Level.WARNING
; the message is
transmitted to all subscribed handlers.
msg | the message to log. |
---|