Index (Frames) | Index (No Frames) | Package | Package Tree | Tree
java.util.logging

Class Logger

java.lang.Object
|
+--java.util.logging.Logger


public class Logger

extends Object

A Logger is used for logging information about events. Usually, there is a seprate logger for each subsystem or component, although there is a shared instance for components that make only occasional use of the logging framework.

It is common to name a logger after the name of a corresponding Java package. Loggers are organized into a hierarchical namespace; for example, the logger "org.gnu.foo" is the parent of logger "org.gnu.foo.bar".

A logger for a named subsystem can be obtained through java.util.logging.Logger#getLogger(java.lang.String). However, only code which has been granted the permission to control the logging infrastructure will be allowed to customize that logger. Untrusted code can obtain a private, anonymous logger through #getAnonymousLogger() if it wants to perform any modifications to the logger.

FIXME: Write more documentation.

Author:

Field Summary

static java.util.logging.Loggerglobal

A logger provided to applications that make only occasional use of the logging framework, typically early prototypes.

Constructor Summary

Logger(java.lang.String name, java.lang.String resourceBundleName)

Constructs a Logger for a subsystem.

Method Summary

synchronized voidaddHandler(java.util.logging.Handler handler)

Adds a handler to the set of handlers that get notified when a log record is to be published.
synchronized voidconfig(java.lang.String message)

Logs a message with severity level CONFIG.
synchronized voidentering(java.lang.String sourceClass, java.lang.String sourceMethod)

synchronized voidentering(java.lang.String sourceClass, java.lang.String sourceMethod, java.lang.Object param)

synchronized voidentering(java.lang.String sourceClass, java.lang.String sourceMethod, java.lang.Object[] params)

synchronized voidexiting(java.lang.String sourceClass, java.lang.String sourceMethod)

synchronized voidexiting(java.lang.String sourceClass, java.lang.String sourceMethod, java.lang.Object result)

synchronized voidfine(java.lang.String message)

Logs a message with severity level FINE.
synchronized voidfiner(java.lang.String message)

Logs a message with severity level FINER.
synchronized voidfinest(java.lang.String message)

Logs a message with severity level FINEST.
static java.util.logging.LoggergetAnonymousLogger()

Creates a new, unnamed logger.
static java.util.logging.LoggergetAnonymousLogger(java.lang.String resourceBundleName)

Creates a new, unnamed logger.
synchronized java.util.logging.FiltergetFilter()

synchronized java.util.logging.Handler[]getHandlers()

Returns the handlers currently registered for this Logger.
synchronized java.util.logging.LevelgetLevel()

Returns the severity level threshold for this Handler.
static java.util.logging.LoggergetLogger(java.lang.String name)

Finds a registered logger for a subsystem, or creates one in case no logger has been registered yet.
static java.util.logging.LoggergetLogger(java.lang.String name, java.lang.String resourceBundleName)

Finds a registered logger for a subsystem, or creates one in case no logger has been registered yet.
java.lang.StringgetName()

Returns the name of this logger.
synchronized java.util.logging.LoggergetParent()

Returns the parent of this logger.
synchronized java.util.ResourceBundlegetResourceBundle()

Returns the resource bundle that is being used for localizing messages.
synchronized java.lang.StringgetResourceBundleName()

Returns the name of the resource bundle that is being used for localizing messages.
synchronized booleangetUseParentHandlers()

Returns whether or not this Logger forwards log records to handlers registered for its parent loggers.
synchronized voidinfo(java.lang.String message)

Logs a message with severity level INFO.
synchronized booleanisLoggable(java.util.logging.Level level)

Returns whether or not a message of the specified level would be logged by this logger.
synchronized voidlog(java.util.logging.LogRecord record)

Passes a record to registered handlers, provided the record is considered as loggable both by #isLoggable(Level) and a possibly installed custom #setFilter(Filter) filter.
voidlog(java.util.logging.Level level, java.lang.String message)

synchronized voidlog(java.util.logging.Level level, java.lang.String message, java.lang.Object param)

synchronized voidlog(java.util.logging.Level level, java.lang.String message, java.lang.Object[] params)

synchronized voidlog(java.util.logging.Level level, java.lang.String message, java.lang.Throwable thrown)

synchronized voidlogp(java.util.logging.Level level, java.lang.String sourceClass, java.lang.String sourceMethod, java.lang.String message)

synchronized voidlogp(java.util.logging.Level level, java.lang.String sourceClass, java.lang.String sourceMethod, java.lang.String message, java.lang.Object param)

synchronized voidlogp(java.util.logging.Level level, java.lang.String sourceClass, java.lang.String sourceMethod, java.lang.String message, java.lang.Object[] params)

synchronized voidlogp(java.util.logging.Level level, java.lang.String sourceClass, java.lang.String sourceMethod, java.lang.String message, java.lang.Throwable thrown)

synchronized voidlogrb(java.util.logging.Level level, java.lang.String sourceClass, java.lang.String sourceMethod, java.lang.String bundleName, java.lang.String message)

synchronized voidlogrb(java.util.logging.Level level, java.lang.String sourceClass, java.lang.String sourceMethod, java.lang.String bundleName, java.lang.String message, java.lang.Object param)

synchronized voidlogrb(java.util.logging.Level level, java.lang.String sourceClass, java.lang.String sourceMethod, java.lang.String bundleName, java.lang.String message, java.lang.Object[] params)

synchronized voidlogrb(java.util.logging.Level level, java.lang.String sourceClass, java.lang.String sourceMethod, java.lang.String bundleName, java.lang.String message, java.lang.Throwable thrown)

synchronized voidremoveHandler(java.util.logging.Handler handler)

Removes a handler from the set of handlers that get notified when a log record is to be published.
synchronized voidsetFilter(java.util.logging.Filter filter)

synchronized voidsetLevel(java.util.logging.Level level)

Sets the severity level threshold for this Handler.
synchronized voidsetParent(java.util.logging.Logger parent)

Sets the parent of this logger.
synchronized voidsetUseParentHandlers(boolean useParentHandlers)

Sets whether or not this Logger forwards log records to handlers registered for its parent loggers.
synchronized voidsevere(java.lang.String message)

Logs a message with severity level SEVERE, indicating a serious failure that prevents normal program execution.
synchronized voidthrowing(java.lang.String sourceClass, java.lang.String sourceMethod, java.lang.Throwable thrown)

synchronized voidwarning(java.lang.String message)

Logs a message with severity level WARNING, indicating a potential problem that does not prevent normal program execution.

Field Details

global

public static final Logger global

A logger provided to applications that make only occasional use of the logging framework, typically early prototypes. Serious products are supposed to create and use their own Loggers, so they can be controlled individually.


Constructor Details

Logger

protected Logger(java.lang.String name, java.lang.String resourceBundleName)

Constructs a Logger for a subsystem. Most applications do not need to create new Loggers explicitly; instead, they should call the static factory methods #getLogger(java.lang.String,java.lang.String) getLogger (with ResourceBundle for localization) or #getLogger(java.lang.String) getLogger (without ResourceBundle), respectively.

Parameters:

Throws:


Method Details

addHandler

public synchronized void addHandler(java.util.logging.Handler handler)

Adds a handler to the set of handlers that get notified when a log record is to be published. #getAnonymousLogger(java.lang.String) getAnonymousLogger.

Parameters:

Throws:


config

public synchronized void config(java.lang.String message)

Logs a message with severity level CONFIG. Level#CONFIG is intended for static configuration messages, for example about the windowing environment, the operating system version, etc.

Parameters:


entering

public synchronized void entering(java.lang.String sourceClass, java.lang.String sourceMethod)

Parameters:


entering

public synchronized void entering(java.lang.String sourceClass, java.lang.String sourceMethod, java.lang.Object param)

Parameters:


entering

public synchronized void entering(java.lang.String sourceClass, java.lang.String sourceMethod, java.lang.Object[] params)

Parameters:


exiting

public synchronized void exiting(java.lang.String sourceClass, java.lang.String sourceMethod)

Parameters:


exiting

public synchronized void exiting(java.lang.String sourceClass, java.lang.String sourceMethod, java.lang.Object result)

Parameters:


fine

public synchronized void fine(java.lang.String message)

Logs a message with severity level FINE. Level#FINE is intended for messages that are relevant for developers using the component generating log messages. Examples include minor, recoverable failures, or possible inefficiencies.

Parameters:


finer

public synchronized void finer(java.lang.String message)

Logs a message with severity level FINER. Level#FINER is intended for rather detailed tracing, for example entering a method, returning from a method, or throwing an exception.

Parameters:


finest

public synchronized void finest(java.lang.String message)

Logs a message with severity level FINEST. Level#FINEST is intended for highly detailed tracing, for example reaching a certain point inside the body of a method.

Parameters:


getAnonymousLogger

public static Logger getAnonymousLogger()

Creates a new, unnamed logger. Unnamed loggers are not registered in the namespace of the LogManager, and no special security permission is required for changing their state. Therefore, untrusted applets are able to modify their private logger instance obtained through this method.

The parent of the newly created logger will the the root logger, from which the level threshold and the handlers are inherited.


getAnonymousLogger

public static Logger getAnonymousLogger(java.lang.String resourceBundleName)

Creates a new, unnamed logger. Unnamed loggers are not registered in the namespace of the LogManager, and no special security permission is required for changing their state. Therefore, untrusted applets are able to modify their private logger instance obtained through this method.

The parent of the newly created logger will the the root logger, from which the level threshold and the handlers are inherited.

Parameters:

Throws:


getFilter

public synchronized Filter getFilter()


getHandlers

public synchronized Handler[] getHandlers()

Returns the handlers currently registered for this Logger. When a log record has been deemed as being loggable, it will be passed to all registered handlers for publication. In addition, if the logger uses parent handlers (see #getUseParentHandlers() getUseParentHandlers and #setUseParentHandlers(boolean) setUseParentHandlers, the log record will be passed to the parent's handlers.


getLevel

public synchronized Level getLevel()

Returns the severity level threshold for this Handler. All log records with a lower severity level will be discarded; a log record of the same or a higher level will be published unless an installed Filter decides to discard it.

Returns:


getLogger

public static Logger getLogger(java.lang.String name)

Finds a registered logger for a subsystem, or creates one in case no logger has been registered yet.

Parameters:

Returns:

Throws:


getLogger

public static Logger getLogger(java.lang.String name, java.lang.String resourceBundleName)

Finds a registered logger for a subsystem, or creates one in case no logger has been registered yet.

If a logger with the specified name has already been registered, the behavior depends on the resource bundle that is currently associated with the existing logger.

Parameters:

Returns:

Throws:


getName

public String getName()

Returns the name of this logger.

Returns:


getParent

public synchronized Logger getParent()

Returns the parent of this logger. By default, the parent is assigned by the LogManager by inspecting the logger's name.

Returns:


getResourceBundle

public synchronized ResourceBundle getResourceBundle()

Returns the resource bundle that is being used for localizing messages.

Returns:


getResourceBundleName

public synchronized String getResourceBundleName()

Returns the name of the resource bundle that is being used for localizing messages.

Returns:


getUseParentHandlers

public synchronized boolean getUseParentHandlers()

Returns whether or not this Logger forwards log records to handlers registered for its parent loggers.

Returns:


info

public synchronized void info(java.lang.String message)

Logs a message with severity level INFO. Level#INFO is intended for purely informational messages that do not indicate error or warning situations. In the default logging configuration, INFO messages will be written to the system console. For this reason, the INFO level should be used only for messages that are important to end users and system administrators. Messages at this level should be understandable to an inexperienced, non-technical user.

Parameters:


isLoggable

public synchronized boolean isLoggable(java.util.logging.Level level)

Returns whether or not a message of the specified level would be logged by this logger.

Parameters:

Throws:


log

public void log(java.util.logging.Level level, java.lang.String message)

Parameters:


log

public synchronized void log(java.util.logging.Level level, java.lang.String message, java.lang.Object param)

Parameters:


log

public synchronized void log(java.util.logging.Level level, java.lang.String message, java.lang.Object[] params)

Parameters:


log

public synchronized void log(java.util.logging.Level level, java.lang.String message, java.lang.Throwable thrown)

Parameters:


log

public synchronized void log(java.util.logging.LogRecord record)

Passes a record to registered handlers, provided the record is considered as loggable both by #isLoggable(Level) and a possibly installed custom #setFilter(Filter) filter.

If the logger has been configured to use parent handlers, the record will be forwarded to the parent of this logger in addition to being processed by the handlers registered with this logger.

The other logging methods in this class are convenience methods that merely create a new LogRecord and pass it to this method. Therefore, subclasses usually just need to override this single method for customizing the logging behavior.

Parameters:


logp

public synchronized void logp(java.util.logging.Level level, java.lang.String sourceClass, java.lang.String sourceMethod, java.lang.String message)

Parameters:


logp

public synchronized void logp(java.util.logging.Level level, java.lang.String sourceClass, java.lang.String sourceMethod, java.lang.String message, java.lang.Object param)

Parameters:


logp

public synchronized void logp(java.util.logging.Level level, java.lang.String sourceClass, java.lang.String sourceMethod, java.lang.String message, java.lang.Object[] params)

Parameters:


logp

public synchronized void logp(java.util.logging.Level level, java.lang.String sourceClass, java.lang.String sourceMethod, java.lang.String message, java.lang.Throwable thrown)

Parameters:


logrb

public synchronized void logrb(java.util.logging.Level level, java.lang.String sourceClass, java.lang.String sourceMethod, java.lang.String bundleName, java.lang.String message)

Parameters:


logrb

public synchronized void logrb(java.util.logging.Level level, java.lang.String sourceClass, java.lang.String sourceMethod, java.lang.String bundleName, java.lang.String message, java.lang.Object param)

Parameters:


logrb

public synchronized void logrb(java.util.logging.Level level, java.lang.String sourceClass, java.lang.String sourceMethod, java.lang.String bundleName, java.lang.String message, java.lang.Object[] params)

Parameters:


logrb

public synchronized void logrb(java.util.logging.Level level, java.lang.String sourceClass, java.lang.String sourceMethod, java.lang.String bundleName, java.lang.String message, java.lang.Throwable thrown)

Parameters:


removeHandler

public synchronized void removeHandler(java.util.logging.Handler handler)

Removes a handler from the set of handlers that get notified when a log record is to be published.

Parameters:

Throws:


setFilter

public synchronized void setFilter(java.util.logging.Filter filter)

#getAnonymousLogger(java.lang.String) getAnonymousLogger.

Parameters:

Throws:


setLevel

public synchronized void setLevel(java.util.logging.Level level)

Sets the severity level threshold for this Handler. All log records with a lower severity level will be discarded immediately. A log record of the same or a higher level will be published unless an installed Filter decides to discard it. #getAnonymousLogger(java.lang.String) getAnonymousLogger.

Parameters:

Throws:


setParent

public synchronized void setParent(java.util.logging.Logger parent)

Sets the parent of this logger. Usually, applications do not call this method directly. Instead, the LogManager will ensure that the tree of loggers reflects the hierarchical logger namespace. Basically, this method should not be public at all, but the GNU implementation follows the API specification. #getAnonymousLogger(java.lang.String) getAnonymousLogger.

Parameters:

Throws:


setUseParentHandlers

public synchronized void setUseParentHandlers(boolean useParentHandlers)

Sets whether or not this Logger forwards log records to handlers registered for its parent loggers. #getAnonymousLogger(java.lang.String) getAnonymousLogger.

Parameters:

Throws:


severe

public synchronized void severe(java.lang.String message)

Logs a message with severity level SEVERE, indicating a serious failure that prevents normal program execution. Messages at this level should be understandable to an inexperienced, non-technical end user. Ideally, they explain in simple words what actions the user can take in order to resolve the problem.

Parameters:

See Also:


throwing

public synchronized void throwing(java.lang.String sourceClass, java.lang.String sourceMethod, java.lang.Throwable thrown)

Parameters:


warning

public synchronized void warning(java.lang.String message)

Logs a message with severity level WARNING, indicating a potential problem that does not prevent normal program execution. Messages at this level should be understandable to an inexperienced, non-technical end user. Ideally, they explain in simple words what actions the user can take in order to resolve the problem.

Parameters:

See Also: