fwpUtil
Class Logger

java.lang.Object
  extended by fwpUtil.Logger

public class Logger
extends java.lang.Object

Title: Logger.

Description: A basic logger capability which uses the same logging levels as the much larger standard Java logger.

Copyright: Copyright (c) 2011


Field Summary
static int ALL
           
static int CONFIG
           
static int FINE
           
static int FINER
           
static int FINEST
           
static int INFO
           
static int OFF
           
static int SEVERE
           
static int WARNING
           
 
Constructor Summary
Logger()
           
 
Method Summary
static java.lang.String getLogFileName()
          Gets the currently set log file name.
static java.lang.String getLogFilePath()
          Gets the currently set log file path.
static java.lang.String getlogItHelpFileName()
          Gets the log help file name.
static java.lang.String getLogItHelpPath()
          Gets the LogIt help file path.
static int getLogLevel()
          Gets the current logging level.
static void setLogFileName(java.lang.String fileName)
          Sets the log file name.
static void setLogFilePath(java.lang.String pathName)
          Sets the log file path.
static void setlogItHelpFileName(java.lang.String fileName)
          Sets the log help file name.
static void setLogItHelpPath(java.lang.String pathName)
          Sets the LogIt help file path.
static void setLogLevel(int level)
          Sets the logging level.
static void startLogger(java.lang.String logPath, java.lang.String logName, java.lang.String helpPath, java.lang.String helpName)
          Creates a program flow and data logging capability.
 java.lang.String toString()
          Returns the name of the class.
static void writeLog(int level, java.lang.String textMessage)
          Write a message to the log file if the level parameter is greater than the currently set logging level.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

ALL

public static final int ALL
See Also:
Constant Field Values

CONFIG

public static final int CONFIG
See Also:
Constant Field Values

FINE

public static final int FINE
See Also:
Constant Field Values

FINER

public static final int FINER
See Also:
Constant Field Values

FINEST

public static final int FINEST
See Also:
Constant Field Values

INFO

public static final int INFO
See Also:
Constant Field Values

OFF

public static final int OFF
See Also:
Constant Field Values

SEVERE

public static final int SEVERE
See Also:
Constant Field Values

WARNING

public static final int WARNING
See Also:
Constant Field Values
Constructor Detail

Logger

public Logger()
Method Detail

getLogFileName

public static java.lang.String getLogFileName()
Gets the currently set log file name.

Returns:
The log file name.

getLogFilePath

public static java.lang.String getLogFilePath()
Gets the currently set log file path.

Returns:
The log file path.

getlogItHelpFileName

public static java.lang.String getlogItHelpFileName()
Gets the log help file name.

Returns:
The log file name.

getLogItHelpPath

public static java.lang.String getLogItHelpPath()
Gets the LogIt help file path.

Returns:
The LogIt help file path.

getLogLevel

public static int getLogLevel()
Gets the current logging level.

Returns:
Logger.OFF, Logger.SEVERE, Logger.WARNING, Logger.INFO, Logger.CONFIG, Logger.FINE, Logger.FINER, Logger.FINEST, and Logger.ALL.

setLogFileName

public static void setLogFileName(java.lang.String fileName)
Sets the log file name.

Parameters:
fileName - The log file name.

setLogFilePath

public static void setLogFilePath(java.lang.String pathName)
Sets the log file path.

Parameters:
pathName - A String defining the path to the log file. This string must end with a file separator.

setlogItHelpFileName

public static void setlogItHelpFileName(java.lang.String fileName)
Sets the log help file name.

Parameters:
fileName - The log help file name.

setLogItHelpPath

public static void setLogItHelpPath(java.lang.String pathName)
Sets the LogIt help file path.

Parameters:
pathName - A String defining the path to the LogIt help file. This string must end with a file separator.

setLogLevel

public static void setLogLevel(int level)
Sets the logging level.

Parameters:
level - Logger.OFF, Logger.SEVERE, Logger.WARNING, Logger.INFO, Logger.CONFIG, Logger.FINE, Logger.FINER, Logger.FINEST, and Logger.ALL.

startLogger

public static void startLogger(java.lang.String logPath,
                               java.lang.String logName,
                               java.lang.String helpPath,
                               java.lang.String helpName)
Creates a program flow and data logging capability.

When activated, the Logger directs all logging messages as well as all System.out and System.err output to a disk based text file. Program generated log messages and exception stack traces are also directed to the file in the exact order they were generated. Nine levels of logging are supported: Logger.OFF, Logger.SEVERE, Logger.WARNING, Logger.INFO, Logger.CONFIG, Logger.FINE, Logger.FINER, Logger.FINEST, and Logger.ALL.

The log file name and path are set by the parameters passed by the calling method.

The Logger is started with:

Logger.startLogger(logPath, LogName, helpPath, helpName);

Set a new logging level with : Logger.setLogLevel(logger.CONFIG);

When a writeLog call is made, the value of the level parameter is tested against the value passed in the last call to setLogLevel. If the value is greater, then the log message is written to the log file. In the list above, the logging levels are listed in decreasing order were OFF has the greatest value and ALL has the lowest.

Parameters:
filePath - The path to the directory which is to hold the log file. This string must end with a file separator appropriate for the system on which the program is running. For example: String logPath = System.getProperty("user.dir") + System.getProperty("file.separator");

logName - The name of the log file. For example: String logFileName = "Log.txt";

helpPath - The path to the LogIt htm help file. Unless there is a reason not to, the help file could easily go into the same directory as the log file.

helpName - The name of the LogIt htm help file. For example: String helpFileName = "LogItHelp.htm"; // The default name

Example usage: The following code can be copied into program initialization area and it will do everyting necessary to get the logger going. The log file will be placed in the directory where the program is located. The default LogIt help file () should also be placed it that directory. These files do not need to be co-located and can be placed anywhere.

See the Logger documentation in the fwpUtil directory for the example.


toString

public java.lang.String toString()
Returns the name of the class.

Overrides:
toString in class java.lang.Object
Returns:
The class name, log file path+name, log level and log help file path+name. For example:

Logger LogFile=D:\A JOptionPanel\Log.txt Log Level=1 HelpFile=D:\A JOptionPanel\LogItHelp.htm


writeLog

public static void writeLog(int level,
                            java.lang.String textMessage)
Write a message to the log file if the level parameter is greater than the currently set logging level.

Parameters:
level - Logger.OFF, Logger.SEVERE, Logger.WARNING, Logger.INFO, Logger.CONFIG, Logger.FINE, Logger.FINER, Logger.FINEST, and Logger.ALL.

textessage - The message to be written to the log file.