com.foxsmart.ic.util
Class Logger

java.lang.Object
  extended by com.foxsmart.ic.util.Logger

public class Logger
extends java.lang.Object

This class handles logging of trace messages to various locations. By default, logging goes to Standard Out and System.out and System.err are left alone.


Field Summary
static java.lang.String DEBUG
           
static java.lang.String DEBUG_DETAIL
           
static java.lang.String INFO
           
static java.lang.String NONE
           
 
Constructor Summary
Logger()
           
 
Method Summary
static void clearPausedMessages()
          Clears any paused messages in the internal buffer.
static java.lang.String getLogLevel()
          Gets the current logging level.
static java.io.PrintStream getNormalStandardError()
          Gets the normal Standard Error location.
static java.io.PrintStream getNormalStandardOut()
          Gets the normal Standard Out location.
static java.io.ByteArrayOutputStream getPausedMessages()
          Gets all messages that are being stored internally while logging is paused.
static boolean isLoggingOutputPaused()
          Returns whether logging output is paused or not.
static void log(java.lang.Object object)
          Logs a message as an INFO level message with no timestamp.
static void log(java.lang.Object object, java.lang.String logLevel)
          Logs a message in the specified log level with no timestamp.
static void log(java.lang.Object object, java.lang.String logLevel, boolean includeTimestamp)
          Logs a message in the specified log level with a timestamp specifier.
static void logToFile(java.lang.String filename)
          Sets logging to go to a file.
static void logToFile(java.lang.String filename, boolean append)
          Sets logging to go to a file.
static void logToNormalStdOutAndErr()
          Sets logging to go to the original Standard Out and Standard Error locations.
static void main(java.lang.String[] args)
          Test Driver.
static void pauseLoggingOutput()
          Pauses logging.
static void resumeLoggingOutput()
          Resumes logging.
static void setLogLevel(java.lang.String logLevel)
          Sets the logging level.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

NONE

public static final java.lang.String NONE
See Also:
Constant Field Values

INFO

public static final java.lang.String INFO
See Also:
Constant Field Values

DEBUG

public static final java.lang.String DEBUG
See Also:
Constant Field Values

DEBUG_DETAIL

public static final java.lang.String DEBUG_DETAIL
See Also:
Constant Field Values
Constructor Detail

Logger

public Logger()
Method Detail

setLogLevel

public static void setLogLevel(java.lang.String logLevel)
                        throws java.lang.Exception
Sets the logging level. Valid log levels are Logger.NONE, Logger.INFO and Logger.DEBUG.

Parameters:
logLevel - The log level to set.
Throws:
java.lang.Exception - if the log level is invalid.

getLogLevel

public static java.lang.String getLogLevel()
Gets the current logging level.

Returns:
the log level.

getNormalStandardOut

public static java.io.PrintStream getNormalStandardOut()
Gets the normal Standard Out location. This may be useful in case Standard Out was redirected by the logger.

Returns:
The normal Standard Out location.

getNormalStandardError

public static java.io.PrintStream getNormalStandardError()
Gets the normal Standard Error location. This may be useful in case Standard Error was redirected by the logger.

Returns:
The normal Standard Error location.

logToNormalStdOutAndErr

public static void logToNormalStdOutAndErr()
Sets logging to go to the original Standard Out and Standard Error locations.


logToFile

public static void logToFile(java.lang.String filename)
                      throws java.io.IOException
Sets logging to go to a file. The file will be overwritten.

Parameters:
filename - The filename to log messages to.
Throws:
java.io.IOException - if the file could not be written to.

logToFile

public static void logToFile(java.lang.String filename,
                             boolean append)
                      throws java.io.IOException
Sets logging to go to a file.

Parameters:
filename - The filename to log messages to.
append - If true, log messages will be appended to the end of the file if it currently exists. If false, the file will be overwritten if it exists.
Throws:
java.io.IOException - if the file could not be written to.

isLoggingOutputPaused

public static boolean isLoggingOutputPaused()
Returns whether logging output is paused or not.

Returns:
True if logging output is paused or false if not.

pauseLoggingOutput

public static void pauseLoggingOutput()
Pauses logging. All log messages will be stored internally until logging is restored.


clearPausedMessages

public static void clearPausedMessages()
Clears any paused messages in the internal buffer. Future messages will continue to be stored internally.


getPausedMessages

public static java.io.ByteArrayOutputStream getPausedMessages()
Gets all messages that are being stored internally while logging is paused. If logging is not paused, null is returned. Note that any messages written to the returned ByteArrayOutputStream will be written to the log output when logging output is restored.

Returns:
The paused log messages.

resumeLoggingOutput

public static void resumeLoggingOutput()
Resumes logging. All messages that have been saved during a pause will be sent to their previous output. Note that if the output location is the original Standard Out and Standard Error, all saved messages will go to Standard Out only.


log

public static void log(java.lang.Object object)
Logs a message as an INFO level message with no timestamp.

Parameters:
object - The object whose toString method will be logged.

log

public static void log(java.lang.Object object,
                       java.lang.String logLevel)
Logs a message in the specified log level with no timestamp.

Parameters:
object - The object whose toString method will be logged.
logLevel - The log level for the message.

log

public static void log(java.lang.Object object,
                       java.lang.String logLevel,
                       boolean includeTimestamp)
Logs a message in the specified log level with a timestamp specifier.

Parameters:
object - The object whose toString method will be logged. If null is passed in, no message will be logged.
logLevel - The log level for the message. If the log level is not recognized, the default INFO level will be used.
includeTimestamp - If true, the message will be logged with a timestamp. If false, no timestamp will be logged.

main

public static void main(java.lang.String[] args)
Test Driver.

Parameters:
args - program arguments.


Copyright © 2005-2008 Fox Smart, Inc. All Rights Reserved.