Spatial DataBlade
JAVA API v8.21

com.ibm.spatial.util
Class Logger

java.lang.Object
  extended by com.ibm.spatial.util.Logger

public class Logger
extends java.lang.Object

Logs API messages.

Note: This class is used internally, to ensure logging functionality for API code running on JRE versions prior to 1.4. In a future version, this implementation will probably be deprecated. Instead, the "java.util.logging" package (defined in J2SE 1.4) will be used.

An instance of this class will log messages for the API. Logger objects should not be created directly. Instead, logging should be activated using the SpatialManager logging facade methods SpatialManager.setLogWriter and SpatialManager.setLogLevel.

Logging messages will be forwarded to a registered Writer object.

A Logger has a logging level associated with it, which reflects a minimum message level that this logger cares about. The log level can be dynamically changed by calls on the Logger.setLevel method.

On each logging call the Logger initially performs a check of the request level (e.g. Logger.SEVERE or Logger.INFO) against the effective log level of the logger. If the request level is lower than the log level, the logging call returns immediately.

Most of the logger output methods take a "msg" argument. This msg argument is a message code. Messages are stored in ResourceBundle fields inside SpatialManager. The format style used is the java.text.MessageFormat style, so for example a format string "{0} {1}" would format two parameters as strings.

The logging methods will take a log level, a message code, and optionally the originating class and method name, and some parameters to the message. There are also convenience methods for tracing method entries (the "entering" methods) and method returns (the "exiting" methods).


Field Summary
static int ALL
          ALL indicates that all messages should be logged.
static int INFO
          INFO is a message level for informational messages.
static int OFF
          OFF is a special level that can be used to turn off logging.
static int SEVERE
          SEVERE is a message level indicating a failure.
static int WARNING
          WARNING is a message level indicating a potential problem.
 
Constructor Summary
Logger()
          Constructor
 
Method Summary
 void entering(java.lang.String className, java.lang.String methodName)
          Logs a method entry.
 void exiting(java.lang.String className, java.lang.String methodName)
          Logs a method return.
static Logger getInstance()
          Finds or creates a logger object.
 int getLevel()
          Gets the log level that has been specified for this Logger.
 MessageProvider getMessageProvider()
          Gets the MessageProvider associated with this Logger.
 boolean isLoggable(int level)
          Checks if a message of the given level would actually be logged by this logger.
 void log(int level, int msg)
          Logs a message, with no argument.
 void log(int level, int msg, java.lang.Object param)
          Logs a message, with an object argument.
 void log(int level, int msg, java.lang.Object[] params)
          Logs a message, with an array of object arguments.
 void log(int level, int msg, java.lang.Throwable ex)
          Logs a message, with associated Throwable information.
 void log(int level, java.lang.String className, java.lang.String methodName, int msg)
          Logs a message with source class and method, with no arguments.
 void log(int level, java.lang.String className, java.lang.String methodName, int msg, java.lang.Object[] params)
          Log a message with source class and method, with an array of object arguments.
 void log(int level, java.lang.String className, java.lang.String methodName, int msg, java.lang.Object[] params, java.lang.Throwable ex)
          Logs a message, specifying source class and method, with associated Throwable information.
 void setLevel(int newLevel)
          Sets the log level specifying which message levels will be logged by this logger.
 void setMessageProvider(MessageProvider provider)
          Sets a MessageProvider object to retrieve localized and formatted messages given a message code.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

OFF

public static final int OFF
OFF is a special level that can be used to turn off logging.

See Also:
Constant Field Values

SEVERE

public static final int SEVERE
SEVERE is a message level indicating a failure.

In general SEVERE messages should describe events that will prevent normal program execution.

See Also:
Constant Field Values

WARNING

public static final int WARNING
WARNING is a message level indicating a potential problem.

In general WARNING messages should describe events that indicate potential problems.

See Also:
Constant Field Values

INFO

public static final int INFO
INFO is a message level for informational messages.

See Also:
Constant Field Values

ALL

public static final int ALL
ALL indicates that all messages should be logged.

See Also:
Constant Field Values
Constructor Detail

Logger

public Logger()
Constructor

Method Detail

getInstance

public static Logger getInstance()
Finds or creates a logger object.

Returns:
a suitable Logger

setLevel

public void setLevel(int newLevel)
Sets 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 Logger.OFF can be used to turn off logging.

Parameters:
newLevel - the new value for the log level

getLevel

public int getLevel()
Gets the log level that has been specified for this Logger.

Returns:
this Logger's level

isLoggable

public boolean isLoggable(int level)
Checks if a message of the given level would actually be logged by this logger. This check is based on the Loggers level.

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

setMessageProvider

public void setMessageProvider(MessageProvider provider)
Sets a MessageProvider object to retrieve localized and formatted messages given a message code.

Parameters:
provider - a MessageProvider

getMessageProvider

public MessageProvider getMessageProvider()
Gets the MessageProvider associated with this Logger.

Returns:
a MessageProvider associated with this logger

log

public void log(int level,
                int msg)
Logs a message, with no argument.

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

Parameters:
level - One of the message level identifiers, e.g. Logger.WARNING
msg - The message code

log

public void log(int level,
                int msg,
                java.lang.Object param)
Logs a message, with an object argument.

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

Parameters:
level - One of the message level identifiers, e.g. Logger.WARNING
msg - The message code
param - parameter to the message

log

public void log(int level,
                int msg,
                java.lang.Object[] params)
Logs a message, with an array of object arguments.

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

Parameters:
level - One of the message level identifiers, e.g. Logger.WARNING
msg - The message code
params - array of parameters to the message

log

public void log(int level,
                int msg,
                java.lang.Throwable ex)
Logs a message, with associated Throwable information.

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

Parameters:
level - One of the message level identifiers, e.g. Logger.WARNING
msg - The message code
thrown - Throwable associated with log message.

log

public void log(int level,
                java.lang.String className,
                java.lang.String methodName,
                int msg)
Logs a message with source class and method, with no arguments.

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

Parameters:
level - One of the message level identifiers, e.g. Logger.WARNING
className - name of class that issued the logging request
methodName - name of method that issued the logging request
msg - The message code

log

public void log(int level,
                java.lang.String className,
                java.lang.String methodName,
                int msg,
                java.lang.Object[] params)
Log a message with 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. Logger.WARNING
className - name of class that issued the logging request
methodName - name of method that issued the logging request
msg - The message code
params - Array of parameters associated to the message

log

public void log(int level,
                java.lang.String className,
                java.lang.String methodName,
                int msg,
                java.lang.Object[] params,
                java.lang.Throwable ex)
Logs 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. Logger.WARNING
className - name of class that issued the logging request
methodName - name of method that issued the logging request
msg - The message code
ex - Throwable object associated with log message.

entering

public void entering(java.lang.String className,
                     java.lang.String methodName)
Logs a method entry.

This is a convenience method that can be used to log entry to a method. A message with log level Logger.INFO and the given className and methodName is logged.

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

exiting

public void exiting(java.lang.String className,
                    java.lang.String methodName)
Logs a method return.

This is a convenience method that can be used to log returning from a method. A message with log level Logger.INFO and the given className and methodName is logged.

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

Spatial DataBlade
JAVA API v8.21


Licensed Materials - Property of IBM
Copyright IBM Corp. 2002, 2012 All Rights Reserved.