org.j4me.logging
Class Log

java.lang.Object
  extended by org.j4me.logging.Log

public class Log
extends java.lang.Object

Maintains a recording of the application's operation. The Log takes in strings for events that happen during the program's execution. Each event has a Level, or priority, associated with it.

The log can be read later to examine problems.

The following two examples illustrate how to record things in the log. The first statement shows that the logging level should be checked before logging because it stops the expensive string concatenation when the log level is off. The second shows logging an exception.

        if ( Log.isDebugEnabled() )
        {
                Log.debug("X = " + x + " which I only care about when debugging");
        }
  
        Log.warn("Problem with HTTP", exception);
 

See Also:
Level

Constructor Summary
Log()
           
 
Method Summary
static void clear()
          Empties the log of all messages.
static void debug(java.lang.String message)
          Log a message string at the DEBUG Level.
static void debug(java.lang.String message, java.lang.Throwable t)
          Log a message string with the DEBUG level including the stack trace of the Throwable t passed as parameter.
static void error(java.lang.String message)
          Log a message string with the ERROR Level.
static void error(java.lang.String message, java.lang.Throwable t)
          Log a message string with the ERROR level including the stack trace of the Throwable t passed as parameter.
static Level getLogLevel()
          Returns the lowest level of statements that are logged.
static LogMessage[] getLogMessages()
          Gets all the log messages still in memory.
static void info(java.lang.String message)
          Log a message string with the INFO Level.
static void info(java.lang.String message, java.lang.Throwable t)
          Log a message string with the INFO level including the stack trace of the Throwable t passed as parameter.
static boolean isDebugEnabled()
          Check whether logging at the DEBUG level is enabled.
static boolean isInfoEnabled()
          Check whether logging at the INFO level is enabled.
static void setLevel(int level)
          Sets the level log statements are evaluated.
static void setLevel(Level level)
          Sets the level log statements are evaluated.
static void warn(java.lang.String message)
          Log a message string with the WARN Level.
static void warn(java.lang.String message, java.lang.Throwable t)
          Log a message string with the WARN level including the stack trace of the Throwable t passed as parameter.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

Log

public Log()
Method Detail

getLogLevel

public static Level getLogLevel()
Returns the lowest level of statements that are logged.

Returns:
The value of the lowest level of log statements written to the log. It can later be passed to the setLevel method to reset the logging level.

setLevel

public static void setLevel(int level)
Sets the level log statements are evaluated. Anything at level or higher will be logged.

The int value level should come from the getLogLevel method.

Parameters:
level - is the lowest priority of statements that will be logged.

setLevel

public static void setLevel(Level level)
Sets the level log statements are evaluated. Anything at level or higher will be logged.

Parameters:
level - is the lowest priority of statements that will be logged.

debug

public static void debug(java.lang.String message)
Log a message string at the DEBUG Level.

This method first checks if this category is DEBUG enabled by comparing the level of this category with DEBUG Level. If the category is DEBUG enabled, then it will log the message.

Parameters:
message - is the message to log.

debug

public static void debug(java.lang.String message,
                         java.lang.Throwable t)
Log a message string with the DEBUG level including the stack trace of the Throwable t passed as parameter.

See debug(String) for more detailed information.

Parameters:
message - is the message to log.
t - is the exception to log.

info

public static void info(java.lang.String message)
Log a message string with the INFO Level.

This method first checks if this category is INFO enabled by comparing the level of this category with INFO Level. If the category is INFO enabled, then it will log the message.

Parameters:
message - is the message to log.

info

public static void info(java.lang.String message,
                        java.lang.Throwable t)
Log a message string with the INFO level including the stack trace of the Throwable t passed as parameter.

See info(String) for more detailed information.

Parameters:
message - is the message to log.
t - is the exception to log.

warn

public static void warn(java.lang.String message)
Log a message string with the WARN Level.

This method first checks if this category is WARN enabled by comparing the level of this category with WARN Level. If the category is WARN enabled, then it will log the message.

Parameters:
message - is the message to log.

warn

public static void warn(java.lang.String message,
                        java.lang.Throwable t)
Log a message string with the WARN level including the stack trace of the Throwable t passed as parameter.

See warn(String) for more detailed information.

Parameters:
message - is the message to log.
t - is the exception to log.

error

public static void error(java.lang.String message)
Log a message string with the ERROR Level.

This method first checks if this category is ERROR enabled by comparing the level of this category with ERROR Level. If the category is ERROR enabled, then it will log the message.

Parameters:
message - is the message to log.

error

public static void error(java.lang.String message,
                         java.lang.Throwable t)
Log a message string with the ERROR level including the stack trace of the Throwable t passed as parameter.

See error(String) for more detailed information.

Parameters:
message - is the message to log.
t - is the exception to log.

isDebugEnabled

public static boolean isDebugEnabled()
Check whether logging at the DEBUG level is enabled.

This function is intended to lessen the computational cost of disabled log statements. All debug logs that perform string concatenation should be written as:

 if ( Log.isDebugEnabled() )
 {
        Log.debug("This is entry number: " + i);
 }
 

Returns:
true if debug messages are logged; false if not.

isInfoEnabled

public static boolean isInfoEnabled()
Check whether logging at the INFO level is enabled.

This function is intended to lessen the computational cost of disabled log statements. All info logs that perform string concatenation should be written as:

 if ( Log.isInfoEnabled() )
 {
        Log.info("This is entry number: " + i);
 }
 

Returns:
true if info messages are logged; false if not.

getLogMessages

public static LogMessage[] getLogMessages()
Gets all the log messages still in memory. Internally the log messages are kept in a circular buffer and once it fills, the oldest messages will be discarded.

The returned array references all of the log messages and does not stop logging from continuing. In other words the returned logs are a snapshot in time.

Returns:
An array of the previously logged messages. The higher the array index, the more recently it was logged. Therefore length - 1 will be the last message logged. If no messages have been logged this will return an array of length zero (i.e. it never returns null).

clear

public static void clear()
Empties the log of all messages.