Build 1.0_r1(from source)

java.util.logging
Class Logger

java.lang.Object
  extended by java.util.logging.Logger

public class Logger
extends Object

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 methods getLogger. They can also get anonymous loggers by calling the methods getAnonymousLogger. 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, i.e., using dot-separated strings. Anonymous loggers do not belong to any namespace.

Loggers "inherit" log level setting from their parent if its 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 is true, loggers also inherit their parent's handlers. Here "inherit" only means the "behaviors" are inherited. The internal fields value 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 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.

See Also:
LogManager

Nested Class Summary
(package private) static class Logger.PrivateSecurityManager
           
 
Field Summary
static Logger global
          The global logger is provided as convenience for casual use.
 
Constructor Summary
protected Logger(String name, String resourceBundleName)
          Constructs a Logger object with the supplied name and resource bundle name.
 
Method Summary
(package private)  void addChild(Logger logger)
           
 void addHandler(Handler handler)
          Adds a handler to this logger.
 void config(String msg)
          Logs a message of level Level.CONFIG.
 void entering(String sourceClass, String sourceMethod)
          Logs a message indicating entering a method.
 void entering(String sourceClass, String sourceMethod, Object param)
          Logs a message indicating entering a method.
 void entering(String sourceClass, String sourceMethod, Object[] params)
          Logs a message indicating entering a method.
 void exiting(String sourceClass, String sourceMethod)
          Logs a message indicating existing a method.
 void exiting(String sourceClass, String sourceMethod, Object result)
          Logs a message indicating exiting a method.
 void fine(String msg)
          Logs a message of level Level.FINE.
 void finer(String msg)
          Logs a message of level Level.FINER.
 void finest(String msg)
          Logs a message of level Level.FINEST.
static Logger getAnonymousLogger()
          Gets an anonymous logger to use internally in a thread.
static Logger getAnonymousLogger(String resourceBundleName)
          Gets an anonymous logger to use internally in a thread.
 Filter getFilter()
          Gets the filter used by this logger.
 Handler[] getHandlers()
          Gets all the handlers associated with this logger.
 Level getLevel()
          Gets the logging level of this logger.
static Logger getLogger(String name)
          Gets a named logger.
static Logger getLogger(String name, String resourceBundleName)
          Gets a named logger associated with the supplied resource bundle.
 String getName()
          Gets the name of this logger.
 Logger getParent()
          Gets the parent of this logger in the namespace.
 ResourceBundle getResourceBundle()
          Gets the loaded resource bundle used by this logger to localize logging messages.
 String getResourceBundleName()
          Gets the name of the loaded resource bundle used by this logger to localize logging messages.
 boolean getUseParentHandlers()
          Gets the flag which indicates whether to use parent's handlers to publish incoming log records, potentially recursively up the namespace.
 void info(String msg)
          Logs a message of level Level.INFO.
(package private)  void internalSetParent(Logger newParent)
          Sets the parent of this logger in the namespace.
 boolean isLoggable(Level l)
          Determines whether this logger will actually log messages of the specified level.
(package private) static ResourceBundle loadResourceBundle(String resourceBundleName)
          Load the specified resource bundle, use privileged code.
 void log(Level logLevel, String msg)
          Logs a message of the specified level.
 void log(Level logLevel, String msg, Object param)
          Logs a message of the specified level with the supplied parameter.
 void log(Level logLevel, String msg, Object[] params)
          Logs a message of the specified level with the supplied parameter array.
 void log(Level logLevel, String msg, Throwable thrown)
          Logs a message of the specified level with the supplied Throwable object.
 void log(LogRecord record)
          Logs a given log record.
 void logp(Level logLevel, String sourceClass, String sourceMethod, String msg)
          Logs a message of the given level with the specified source class name and source method name.
 void logp(Level logLevel, String sourceClass, String sourceMethod, String msg, Object param)
          Logs a message of the given level with the specified source class name and source method name and parameter.
 void logp(Level logLevel, String sourceClass, String sourceMethod, String msg, Object[] params)
          Logs a message of the given level with the specified source class name and source method name and parameter array.
 void logp(Level logLevel, String sourceClass, String sourceMethod, String msg, Throwable thrown)
          Logs a message of the given level with the specified source class name and source method name and Throwable object.
 void logrb(Level logLevel, String sourceClass, String sourceMethod, String bundleName, String msg)
          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.
 void logrb(Level logLevel, String sourceClass, String sourceMethod, String bundleName, String msg, Object param)
          Logs a message of the given level with the specified source class name and source method name and parameter, using the given resource bundle to localize the message.
 void logrb(Level logLevel, String sourceClass, String sourceMethod, String bundleName, String msg, Object[] params)
          Logs a message of the given level with the specified source class name and source method name and parameter array, using the given resource bundle to localize the message.
 void logrb(Level logLevel, String sourceClass, String sourceMethod, String bundleName, String msg, Throwable thrown)
          Logs a message of the given level with the specified source class name and source method name and Throwable object, using the given resource bundle to localize the message.
(package private)  void removeChild(Logger child)
           
 void removeHandler(Handler handler)
          Removes a handler for this logger.
(package private)  void reset()
           
 void setFilter(Filter newFilter)
          Sets the filter used by this logger.
 void setLevel(Level newLevel)
          Sets the logging level for this logger.
(package private)  void setManager(LogManager manager)
           
 void setParent(Logger parent)
          Sets the parent of this logger in the namespace.
 void setUseParentHandlers(boolean notifyParentHandlers)
          Sets the flag which indicates whether to use parent's handlers to publish incoming log records, potentially recursively up the namespace.
 void severe(String msg)
          Logs a message of level Level.SEVERE.
 void throwing(String sourceClass, String sourceMethod, Throwable thrown)
          Logs a message indicating throwing an exception.
 void warning(String msg)
          Logs a message of level Level.WARNING.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

global

public static final Logger global
The global logger is provided as convenience for casual use.

Constructor Detail

Logger

protected Logger(String name,
                 String resourceBundleName)
Constructs a Logger object with the supplied name and resource bundle name.

Parameters:
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
Throws:
MissingResourceException - If the specified resource bundle can not be loaded.
Method Detail

loadResourceBundle

static ResourceBundle loadResourceBundle(String resourceBundleName)
Load the specified resource bundle, use privileged code.

Parameters:
resourceBundleName - the name of the resource bundle to load, cannot be null
Returns:
the loaded resource bundle.
Throws:
MissingResourceException - If the specified resource bundle can not be loaded.

getAnonymousLogger

public static Logger getAnonymousLogger()
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 so that they can be used in applets.

Anonymous loggers' parent is set to be the root logger. This enables them to inherit default logging level and handlers from the root logger.

Returns:
a new instance of anonymous logger

getAnonymousLogger

public static Logger getAnonymousLogger(String resourceBundleName)
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 so that they can be used in applets.

Anonymous loggers' parent is set to be the root logger. This enables them to inherit default logging level and handlers from the root logger.

Parameters:
resourceBundleName - the name of the resource bundle used to localize log messages
Returns:
a new instance of anonymous logger
Throws:
MissingResourceException - If the specified resource bundle can not be loaded.

getLogger

public static Logger getLogger(String name)
Gets a named logger. The returned logger may already exist, or may be newly created. If the latter, its level will be set to the configured level according to the LogManager's properties if any.

Parameters:
name - the name of the logger to get, cannot be null
Returns:
a named logger
Throws:
MissingResourceException - If the specified resource bundle can not be loaded.

getLogger

public static Logger getLogger(String name,
                               String resourceBundleName)
Gets a named logger associated with the supplied resource bundle. The resource bundle will be used to localize logging messages.

Parameters:
name - the name of the logger to get, cannot be null
resourceBundleName - the name of the resource bundle, may be null
Returns:
a named logger

addHandler

public void addHandler(Handler handler)
Adds a handler to this logger. The handler will be fed with log records received by this logger.

Parameters:
handler - the handler object to add, cannot be null
Throws:
SecurityException - If a security manager determines that the caller does not have the required permission.

getHandlers

public Handler[] getHandlers()
Gets all the handlers associated with this logger.

Returns:
an array of all the handlers associated with this logger

removeHandler

public void removeHandler(Handler handler)
Removes a handler for this logger. If the specified handler does not exist, this method has no effect.

Parameters:
handler - the handler to be removed, cannot be null
Throws:
SecurityException - If a security manager determines that the caller does not have the required permission.

getFilter

public Filter getFilter()
Gets the filter used by this logger.

Returns:
the filter used by this logger

setFilter

public void setFilter(Filter newFilter)
Sets the filter used by this logger.

Parameters:
newFilter - the filter to set
Throws:
SecurityException - If a security manager determines that the caller does not have the required permission.

getLevel

public Level getLevel()
Gets the logging level of this logger.

Returns:
the logging level of this logger

setLevel

public void setLevel(Level newLevel)
Sets the logging level for this logger. A null level indicates this logger will inherit its parent's level.

Parameters:
newLevel - the logging level to set
Throws:
SecurityException - If a security manager determines that the caller does not have the required permission.

getUseParentHandlers

public boolean getUseParentHandlers()
Gets the flag which indicates whether to use parent's handlers to publish incoming log records, potentially recursively up the namespace.

Returns:
true if set to use parent's handlers, otherwise false

setUseParentHandlers

public void setUseParentHandlers(boolean notifyParentHandlers)
Sets the flag which indicates whether to use parent's handlers to publish incoming log records, potentially recursively up the namespace.

Parameters:
notifyParentHandlers - the flag whether to use parent's handlers
Throws:
SecurityException - If a security manager determines that the caller does not have the required permission.

getParent

public Logger getParent()
Gets the parent of this logger in the namespace.

Returns:
the parent of this logger in the namespace

internalSetParent

void internalSetParent(Logger newParent)
Sets the parent of this logger in the namespace. This method should usually be used by the LogManager object only. This method does not check security.

Parameters:
newParent - the parent logger to set

setParent

public void setParent(Logger parent)
Sets the parent of this logger in the namespace. This method should usually be used by the LogManager object only.

Parameters:
parent - the parent logger to set
Throws:
SecurityException - If a security manager determines that the caller does not have the required permission.

addChild

final void addChild(Logger logger)

removeChild

final void removeChild(Logger child)

getName

public String getName()
Gets the name of this logger.

Returns:
the name of this logger

getResourceBundle

public ResourceBundle getResourceBundle()
Gets the loaded resource bundle used by this logger to localize logging messages. If it's null, the parent's resource bundle will be inherited.

Returns:
the loaded resource bundle used by this logger

getResourceBundleName

public String getResourceBundleName()
Gets the name of the loaded resource bundle used by this logger to localize logging messages. If it's null, the parent's resource bundle name will be inherited.

Returns:
the name of the loaded resource bundle used by this logger

isLoggable

public boolean isLoggable(Level l)
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.

Parameters:
l - the level to check
Returns:
true if this logger will actually log this level, otherwise false

entering

public void entering(String sourceClass,
                     String sourceMethod)
Logs a message indicating entering a method. A log record with log level Level.FINER, log message "ENTRY", and the specified source class name and source method name is submitted for logging.

Parameters:
sourceClass - the calling class name
sourceMethod - the method name

entering

public void entering(String sourceClass,
                     String sourceMethod,
                     Object param)
Logs a message indicating entering a method. A log record with log level Level.FINER, log message "ENTRY", and the specified source class name and source method name and one parameter is submitted for logging.

Parameters:
sourceClass - the source class name
sourceMethod - the source method name
param - the parameter for the method call

entering

public void entering(String sourceClass,
                     String sourceMethod,
                     Object[] params)
Logs a message indicating entering a method. A log record with log level Level.FINER, log message "ENTRY", and the specified source class name and source method name and parameters is submitted for logging.

Parameters:
sourceClass - the source class name
sourceMethod - the source method name
params - an array of parameters for the method call

exiting

public void exiting(String sourceClass,
                    String sourceMethod)
Logs a message indicating existing a method. A log record with log level Level.FINER, log message "RETURN", and the specified source class name and source method name is submitted for logging.

Parameters:
sourceClass - the calling class name
sourceMethod - the method name

exiting

public void exiting(String sourceClass,
                    String sourceMethod,
                    Object result)
Logs a message indicating exiting a method. A log record with log level Level.FINER, log message "RETURN", and the specified source class name and source method name and return value is submitted for logging.

Parameters:
sourceClass - the source class name
sourceMethod - the source method name
result - the return value of the method call

throwing

public void throwing(String sourceClass,
                     String sourceMethod,
                     Throwable thrown)
Logs a message indicating throwing an exception. A log record with log level Level.FINER, log message "THROW", and the specified source class name and source method name and Throwable object is submitted for logging.

Parameters:
sourceClass - the source class name
sourceMethod - the source method name
thrown - the Throwable object

severe

public void severe(String msg)
Logs a message of level Level.SEVERE.

Parameters:
msg - the message to log

warning

public void warning(String msg)
Logs a message of level Level.WARNING.

Parameters:
msg - the message to log

info

public void info(String msg)
Logs a message of level Level.INFO.

Parameters:
msg - the message to log

config

public void config(String msg)
Logs a message of level Level.CONFIG.

Parameters:
msg - the message to log

fine

public void fine(String msg)
Logs a message of level Level.FINE.

Parameters:
msg - the message to log

finer

public void finer(String msg)
Logs a message of level Level.FINER.

Parameters:
msg - the message to log

finest

public void finest(String msg)
Logs a message of level Level.FINEST.

Parameters:
msg - the message to log

log

public void log(Level logLevel,
                String msg)
Logs a message of the specified level.

Parameters:
logLevel - the level of the given message
msg - the message to log

log

public void log(Level logLevel,
                String msg,
                Object param)
Logs a message of the specified level with the supplied parameter.

Parameters:
logLevel - the level of the given message
msg - the message to log
param - the parameter associated with the event that need to be logged

log

public void log(Level logLevel,
                String msg,
                Object[] params)
Logs a message of the specified level with the supplied parameter array.

Parameters:
logLevel - the level of the given message
msg - the message to log
params - the parameter array associated with the event that need to be logged

log

public void log(Level logLevel,
                String msg,
                Throwable thrown)
Logs a message of the specified level with the supplied Throwable object.

Parameters:
logLevel - the level of the given message
msg - the message to log
thrown - the Throwable object associated with the event that need to be logged

log

public void log(LogRecord record)
Logs a given log record. Only those with a logging level no lower than this logger's level will be submitted to this logger's handlers for logging. If getUseParentHandlers() is true, the log record will also be submitted to the parent logger's handlers, 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.

Parameters:
record - the log record to be logged

logp

public void logp(Level logLevel,
                 String sourceClass,
                 String sourceMethod,
                 String msg)
Logs a message of the given level with the specified source class name and source method name.

Parameters:
logLevel - the level of the given message
sourceClass - the source class name
sourceMethod - the source method name
msg - the message to be logged

logp

public void logp(Level logLevel,
                 String sourceClass,
                 String sourceMethod,
                 String msg,
                 Object param)
Logs a message of the given level with the specified source class name and source method name and parameter.

Parameters:
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 need to be logged

logp

public void logp(Level logLevel,