ca.bc.webarts.tools
Class Log

java.lang.Object
  |
  +--ca.bc.webarts.tools.Log

public class Log
extends java.lang.Object

A Simple Log class that can be set to output to a file, the Console or any specified OutputStream. It provides a few simple log entry methods with method entry/exit tracking.

Author:
Tom Gutwin P.Eng

Field Summary
private static java.util.Calendar calendar_
          Description of the Field
static short CONSOLE
          Constant Specifying that the logging output will go to System.out.
private static java.util.Stack currentMethod_
          A stack of the method call history.
static short DEBUG
          Constant Specifying Major Minor and Debug Log events logging will occur.
static short FILE
          Constant Specifying that the logging output will go to a spec'd file.
static short FULL
          Constant Specifying ALL log event logging will occur.
private static boolean instantiated_
           
static Log log_
           
private static java.io.File logFile_
          Description of the Field
private static java.lang.String logFileName_
          Description of the Field
private static java.io.FileWriter logFileWriter_
          Description of the Field
private static short logLevel_
          Description of the Field
private static java.io.PrintStream logOut_
          The stream that ALL logging ends upo getting directed to.
static short MAJOR
          Constant Specifying Major and Minor Log events logging will occur.
static short MINOR
          Constant Specifying only Minor Log events logging will occur.
private static java.lang.String msgSpacing_
          Description of the Field
static short NONE
          Constant Specifying NO logging will occur.
private static short outSpot_
          Description of the Field
static short PIPE
          Constant Specifying that the logging output will go to a spec'd OutputStream.
static short QUIET
          Constant Specifying minimal logging will occur (only Method entry and exit).
private static java.io.PrintStream STD_OUT
          The Standard OutputStream.
private static java.io.OutputStream userOut_
          Description of the Field
 
Constructor Summary
private Log()
          Default Constructor for the Log object.
private Log(short logLevel)
          Constructor for the Log object that sends the output to the Console at the specified Log Level.
private Log(short logLevel, java.io.File logFile)
          Constructor for the Log object that sends the output to a File at the specified Log Level.
private Log(short logLevel, java.io.OutputStream o)
          Constructor for the Log object that sends the output to an OutputStream Pipe at the specified Log Level.
private Log(short logLevel, java.lang.String logName)
          Constructor for the Log object that sends the output to a File with the spec'd filename at the specified Log Level.
 
Method Summary
static boolean alreadyInstantiated()
           
static void close()
          Cleanup method that closes any open Files.
static java.lang.String createCurrentTimeStamp()
          Creates a timestamp for the current time in the form of 'hour + "-" + min + "-" + sec + "-" + millis'.
static Log createLog(short logLevel)
          Singleton method to get the log instance going to stdout.
static Log createLog(short logLevel, java.io.File logFile)
          Singleton method to get the log instance going to a File.
static Log createLog(short logLevel, java.io.OutputStream stream)
          Singleton method to get the log instance going to an OutputStream.
static Log createLog(short logLevel, java.lang.String fName)
          Singleton method to get the log instance going to a File.
static void debug(java.lang.String value)
          Logs a Debug level message prefixed with the current methodname.
static void debug(java.lang.String methodName, java.lang.String value)
          Logs a Debug level message prefixed with the spec'd methodname.
static void endMethod()
          Logs the exit from the last entered method with a simple log message.
static void endMethod(java.lang.String methodName)
          Logs the exit from a method with a simple log message.
static Log getInstance()
          Singleton method to get the log instance NULL if not init yet with a createLog call.
static short getLogLevel()
           
private static void initLogOut()
          Initializes the logOut_ Stream based on the outSpot specifired by the user.
private static void logEntry(java.lang.String value)
          Generic uncategorized log entry.
private static void logEntry(java.lang.String value, java.lang.Exception ex)
          Generic uncategorized log entry.
private static void logEntry(java.lang.String methodName, java.lang.String value)
          A log entry method
static void major(java.lang.String value)
          Logs a Major level message prefixed with the current methodname.
static void major(java.lang.String value, java.lang.Exception ex)
          Logs a Major level message prefixed with the current methodname.
static void major(java.lang.String methodName, java.lang.String value)
          Logs a Major Log event with the spec'd method name prefix.
static void minor(java.lang.String value)
          Logs a minor level message prefixed with the current methodname.
static void minor(java.lang.String value, java.lang.Exception ex)
          Logs a minor level message prefixed with the current methodname.
static void minor(java.lang.String methodName, java.lang.String value)
          Logs a Minor level message prefixed with the spec'd methodname.
static boolean setLogFile(java.io.File logFile)
          Sets the logFile_ attribute to the spec'd File.
static boolean setLogFile(java.lang.String fName)
          Creates a File object based on the spec'd filename and then inits the logFile_ attribute.
static boolean setLogLevel(short level)
          Sets the current Logging Level.
static void startMethod(java.lang.String methodName)
          Logs an entry into a method with a simple log message.
 
Methods inherited from class java.lang.Object
, clone, equals, finalize, getClass, hashCode, notify, notifyAll, registerNatives, toString, wait, wait, wait
 

Field Detail

instantiated_

private static boolean instantiated_

log_

public static Log log_

NONE

public static final short NONE
Constant Specifying NO logging will occur.

QUIET

public static final short QUIET
Constant Specifying minimal logging will occur (only Method entry and exit).

MINOR

public static final short MINOR
Constant Specifying only Minor Log events logging will occur.

MAJOR

public static final short MAJOR
Constant Specifying Major and Minor Log events logging will occur.

DEBUG

public static final short DEBUG
Constant Specifying Major Minor and Debug Log events logging will occur.

FULL

public static final short FULL
Constant Specifying ALL log event logging will occur.

CONSOLE

public static final short CONSOLE
Constant Specifying that the logging output will go to System.out.

FILE

public static final short FILE
Constant Specifying that the logging output will go to a spec'd file.

PIPE

public static final short PIPE
Constant Specifying that the logging output will go to a spec'd OutputStream.

STD_OUT

private static final java.io.PrintStream STD_OUT
The Standard OutputStream.

logFileName_

private static java.lang.String logFileName_
Description of the Field

msgSpacing_

private static java.lang.String msgSpacing_
Description of the Field

userOut_

private static java.io.OutputStream userOut_
Description of the Field

logOut_

private static java.io.PrintStream logOut_
The stream that ALL logging ends upo getting directed to.

logFile_

private static java.io.File logFile_
Description of the Field

logFileWriter_

private static java.io.FileWriter logFileWriter_
Description of the Field

logLevel_

private static short logLevel_
Description of the Field

outSpot_

private static short outSpot_
Description of the Field

calendar_

private static java.util.Calendar calendar_
Description of the Field

currentMethod_

private static java.util.Stack currentMethod_
A stack of the method call history.
Constructor Detail

Log

private Log()
Default Constructor for the Log object. The ouput location is Console and the log level is Major.

Log

private Log(short logLevel)
Constructor for the Log object that sends the output to the Console at the specified Log Level.
Parameters:
logLevel - The desired Logging level (must be one of the Constants spec'd in this class).

Log

private Log(short logLevel,
            java.io.OutputStream o)
Constructor for the Log object that sends the output to an OutputStream Pipe at the specified Log Level.
Parameters:
logLevel - The desired Logging level (must be one of the Constants spec'd in this class).
o - The OutputStream to Pipe the logging to.

Log

private Log(short logLevel,
            java.io.File logFile)
Constructor for the Log object that sends the output to a File at the specified Log Level.
Parameters:
logLevel - The desired Logging level (must be one of the Constants spec'd in this class).
logFile - The File to send the Logging to.

Log

private Log(short logLevel,
            java.lang.String logName)
Constructor for the Log object that sends the output to a File with the spec'd filename at the specified Log Level.
Parameters:
logLevel - The desired Logging level (must be one of the Constants spec'd in this class).
logName - The filename for the File to send Logging output to.
Method Detail

createLog

public static Log createLog(short logLevel,
                            java.io.File logFile)
Singleton method to get the log instance going to a File.

createLog

public static Log createLog(short logLevel,
                            java.io.OutputStream stream)
Singleton method to get the log instance going to an OutputStream.

createLog

public static Log createLog(short logLevel,
                            java.lang.String fName)
Singleton method to get the log instance going to a File.

createLog

public static Log createLog(short logLevel)
Singleton method to get the log instance going to stdout.

getInstance

public static Log getInstance()
Singleton method to get the log instance NULL if not init yet with a createLog call.

alreadyInstantiated

public static boolean alreadyInstantiated()

setLogLevel

public static boolean setLogLevel(short level)
Sets the current Logging Level.
Returns:
true if it was set false if NOT set due to level out out bounds.

getLogLevel

public static short getLogLevel()

setLogFile

public static boolean setLogFile(java.lang.String fName)
Creates a File object based on the spec'd filename and then inits the logFile_ attribute.
Parameters:
fName - The filename to use for the new logFile_.
Returns:
true if successfully created and init.

setLogFile

public static boolean setLogFile(java.io.File logFile)
Sets the logFile_ attribute to the spec'd File.
Parameters:
logFile - The File object to setr to the logFile_.
Returns:
true if successfully init.

createCurrentTimeStamp

public static java.lang.String createCurrentTimeStamp()
Creates a timestamp for the current time in the form of 'hour + "-" + min + "-" + sec + "-" + millis'.
Returns:
The CurrentTimeStamp value.

close

public static void close()
Cleanup method that closes any open Files.

logEntry

private static void logEntry(java.lang.String value)
Generic uncategorized log entry.
Parameters:
value - The String to dump into the Log.

logEntry

private static void logEntry(java.lang.String value,
                             java.lang.Exception ex)
Generic uncategorized log entry.
Parameters:
value - The String to dump into the Log.

logEntry

private static void logEntry(java.lang.String methodName,
                             java.lang.String value)
A log entry method
Parameters:
methodName - Description of Parameter
value - The String to dump into the Log.

startMethod

public static void startMethod(java.lang.String methodName)
Logs an entry into a method with a simple log message. It also keeps track of the entry so it can manage tabbing/spacing of log entries.
Parameters:
methodName - The method being entered.

endMethod

public static void endMethod(java.lang.String methodName)
Logs the exit from a method with a simple log message. It also keeps track of the exit so it can manage tabbing/spacing of log entries.
Parameters:
methodName - The method being exited.

endMethod

public static void endMethod()
Logs the exit from the last entered method with a simple log message. It also keeps track of the exit so it can manage tabbing/spacing of log entries.

major

public static void major(java.lang.String methodName,
                         java.lang.String value)
Logs a Major Log event with the spec'd method name prefix.
Parameters:
methodName - The methodname to prefix the log message with.
value - The String to dump into the Log.

minor

public static void minor(java.lang.String methodName,
                         java.lang.String value)
Logs a Minor level message prefixed with the spec'd methodname.
Parameters:
methodName - The methodname to prefix the log message with.
value - The String to dump into the Log.

debug

public static void debug(java.lang.String methodName,
                         java.lang.String value)
Logs a Debug level message prefixed with the spec'd methodname.
Parameters:
methodName - The methodname to prefix the log message with.
value - The String to dump into the Log.

debug

public static void debug(java.lang.String value)
Logs a Debug level message prefixed with the current methodname.
Parameters:
value - The String to dump into the Log.

major

public static void major(java.lang.String value)
Logs a Major level message prefixed with the current methodname.
Parameters:
value - The String to dump into the Log.

major

public static void major(java.lang.String value,
                         java.lang.Exception ex)
Logs a Major level message prefixed with the current methodname.
Parameters:
value - The String to dump into the Log.
ex - An exception that will dump its stacktrace into the log.

minor

public static void minor(java.lang.String value)
Logs a minor level message prefixed with the current methodname.
Parameters:
value - The String to dump into the Log.

minor

public static void minor(java.lang.String value,
                         java.lang.Exception ex)
Logs a minor level message prefixed with the current methodname.
Parameters:
value - The String to dump into the Log.
ex - An exception that will dump its stacktrace into the log.

initLogOut

private static void initLogOut()
Initializes the logOut_ Stream based on the outSpot specifired by the user.