public class

Logger

extends Object
java.lang.Object
   ↳ com.microstrategy.utils.log.Logger

Class Overview

A Logger object is used to log messages for a specific system or application component. Loggers are normally named, using a hierarchical dot-separated namespace. Logger names can be arbitrary strings, but they should normally be based on the package name or class name of the logged component, such as java.net or javax.swing. In additon it is possible to create "anonymous" Loggers that are not stored in the Logger namespace.

Logger objects may be obtained by calls on one of the getLogger factory methods. These will either create a new Logger or return a suitable existing Logger.

Logging messages will be forwarded to registered Handler objects, which can forward the messages to a variety of destinations, including consoles, files, OS logs, etc.

Each Logger keeps track of a "parent" Logger, which is its nearest existing ancestor in the Logger namespace.

Each Logger has a "Level" associated with it. This reflects a minimum Level that this logger cares about - default level is OFF.

Summary

Fields
protected List handlers
protected boolean publishToRoot
Protected Constructors
Logger(String loggerName)
Protected method to construct a logger for a named subsystem.
Public Methods
synchronized void addHandler(Handler handler)
Add a log Handler to receive logging messages.
void entering(String className, String methodName, Object[] args)
Log a method entry, with an array of parameters.
void entering(String className, String methodName)
Log a method entry.
void entering(String className, String methodName, Object singleArg)
Log a method entry, with one parameter.
void exiting(String className, String methodName)
Log a method return.
void exiting(String className, String methodName, Object result)
Log a method return, with result object.
Filter getFilter()
synchronized Handler[] getHandlers()
Get the Handlers associated with this logger.
synchronized Level getLevel()
Get the log Level that has been specified for this Logger.
String getName()
Get the name for this logger.
boolean isLoggable(Level level)
Check if a message of the given level would actually be logged by this logger.
void log(Level level, String message)
Log a message, with no arguments.
void log(LogRecord logRecord)
Log a LogRecord.
void logp(Level level, String className, String methodName, String message, Object singleArg)
Log a message, specifying source class and method, with a single object parameter to the log message.
void logp(Level level, String className, String methodName, String message, Throwable thrown)
Log a message, specifying source class and method, with associated Throwable information.
void logp(Level level, String className, String methodName, String message, Object[] args)
Log a message, specifying source class and method, with an array of object arguments.
void logp(Level level, String className, String methodName, String message)
Log a message, specifying source class and method, with no arguments.
synchronized void removeHandler(Handler handler)
Remove a log Handler.
void setFilter(Filter filter)
Set a filter to control output on this Logger.
synchronized void setLevel(Level level)
Set the log level specifying which message levels will be logged by this logger.
void throwing(String className, String methodName, Throwable thrown)
Log throwing an exception.
String toString()
Returns a string representation of the object
[Expand]
Inherited Methods
From class java.lang.Object

Fields

protected List handlers

protected boolean publishToRoot

Protected Constructors

protected Logger (String loggerName)

Protected method to construct a logger for a named subsystem.

Parameters
loggerName A name for the logger. This should be a dot-separated name and should normally be based on the package name or class name of the subsystem

Public Methods

public synchronized void addHandler (Handler handler)

Add a log Handler to receive logging messages.

Parameters
handler a logging Handler

public void entering (String className, String methodName, Object[] args)

Log a method entry, with an array of parameters.

This is a convenience method that can be used to log entry to a method. A LogRecord with message "ENTRY" (followed by a format {N} indicator for each entry in the parameter array), log level FINER, and the given sourceMethod, sourceClass, and parameters is logged.

Parameters
className name of class that issued the logging request
methodName name of method that is being entered
args array of parameters to the method being entered

public void entering (String className, String methodName)

Log a method entry.

This is a convenience method that can be used to log entry to a method. className LogRecord with message "ENTRY", log level FINER, and the given sourceMethod and sourceClass is logged.

Parameters
className name of class that issued the logging request
methodName name of method that is being entered

public void entering (String className, String methodName, Object singleArg)

Log a method entry, with one parameter.

This is a convenience method that can be used to log entry to a method. A LogRecord with message "ENTRY {0}", log level FINER, and the given sourceMethod, sourceClass, and parameter is logged.

Parameters
className name of class that issued the logging request
methodName name of method that is being entered
singleArg parameter to the method being entered

public void exiting (String className, String methodName)

Log a method return.

This is a convenience method that can be used to log returning from a method. A LogRecord with message "RETURN", log level FINER, and the given sourceMethod and sourceClass is logged.

Parameters
className name of class that issued the logging request
methodName name of the method

public void exiting (String className, String methodName, Object result)

Log a method return, with result object.

This is a convenience method that can be used to log returning from a method. A LogRecord with message "RETURN {0}", log level FINER, and the gives sourceMethod, sourceClass, and result object is logged.

Parameters
className name of class that issued the logging request
methodName name of the method
result Object that is being returned

public Filter getFilter ()

public synchronized Handler[] getHandlers ()

Get the Handlers associated with this logger.

Returns
  • an array of all registered Handlers

public synchronized Level getLevel ()

Get the log Level that has been specified for this Logger. The result may be null, which means that this logger's effective level will be inherited from its parent.

Returns
  • this Logger's level

public String getName ()

Get the name for this logger.

Returns
  • logger name. Will be null for anonymous Loggers.

public boolean isLoggable (Level level)

Check if a message of the given level would actually be logged by this logger. This check is based on the Loggers effective level, which may be inherited from its parent.

Parameters
level a message logging level
Returns
  • true if the given message level is currently being logged.

public void log (Level level, String message)

Log a message, with no arguments.

If the logger is currently enabled for the given message level then the given message is forwarded to all the registered output Handler objects.

Parameters
level One of the message level identifiers, e.g. SEVERE
message The string message (or a key in the message catalog)

public void log (LogRecord logRecord)

Log a LogRecord.

All the other logging methods in this class call through this method to actually perform any logging. Subclasses can override this single method to capture all log activity.

Parameters
logRecord the LogRecord to be published

public void logp (Level level, String className, String methodName, String message, Object singleArg)

Log a message, specifying source class and method, with a single object parameter to the log message.

If the logger is currently enabled for the given message level then a corresponding LogRecord is created and forwarded to all the registered output Handler objects.

Parameters
level One of the message level identifiers, e.g. SEVERE
className name of class that issued the logging request
methodName name of method that issued the logging request
message The string message (or a key in the message catalog)
singleArg Parameter to the log message.

public void logp (Level level, String className, String methodName, String message, Throwable thrown)

Log a message, specifying source class and method, with associated Throwable information.

If the logger is currently enabled for the given message level then the given arguments are stored in a LogRecord which is forwarded to all registered output handlers.

Note that the thrown argument is stored in the LogRecord thrown property, rather than the LogRecord parameters property. Thus is it processed specially by output Formatters and is not treated as a formatting parameter to the LogRecord message property.

Parameters
level One of the message level identifiers, e.g. SEVERE
className name of class that issued the logging request
methodName name of method that issued the logging request
message The string message (or a key in the message catalog)
thrown Throwable associated with log message.

public void logp (Level level, String className, String methodName, String message, Object[] args)

Log a message, specifying source class and method, with an array of object arguments.

If the logger is currently enabled for the given message level then a corresponding LogRecord is created and forwarded to all the registered output Handler objects.

Parameters
level One of the message level identifiers, e.g. SEVERE
className name of class that issued the logging request
methodName name of method that issued the logging request
message The string message (or a key in the message catalog)
args Array of parameters to the message

public void logp (Level level, String className, String methodName, String message)

Log a message, specifying source class and method, with no arguments.

If the logger is currently enabled for the given message level then the given message is forwarded to all the registered output Handler objects.

Parameters
level One of the message level identifiers, e.g. SEVERE
className name of class that issued the logging request
methodName name of method that issued the logging request
message The string message (or a key in the message catalog)

public synchronized void removeHandler (Handler handler)

Remove a log Handler.

Parameters
handler a logging Handler

public void setFilter (Filter filter)

Set a filter to control output on this Logger.

After passing the initial "level" check, the Logger will call this Filter to check if a log record should really be published.

Parameters
filter a filter object (may be null)

public synchronized void setLevel (Level level)

Set the log level specifying which message levels will be logged by this logger. Message levels lower than this value will be discarded. The level value Level.OFF can be used to turn off logging.

If the new level is null, it means that this node should inherit its level from its nearest ancestor with a specific (non-null) level value.

Parameters
level the new value for the log level (may be null)

public void throwing (String className, String methodName, Throwable thrown)

Log throwing an exception.

This is a convenience method to log that a method is terminating by throwing an exception. The logging is done using the FINER level.

If the logger is currently enabled for the given message level then the given arguments are stored in a LogRecord which is forwarded to all registered output handlers. The LogRecord's message is set to "THROW".

Note that the thrown argument is stored in the LogRecord thrown property, rather than the LogRecord parameters property. Thus is it processed specially by output Formatters and is not treated as a formatting parameter to the LogRecord message property.

Parameters
className name of class that issued the logging request
methodName name of the method.
thrown The Throwable that is being thrown.

public String toString ()

Returns a string representation of the object