fwpUtil
Class Logger

public class Logger
Title: Logger.

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

Copyright: Copyright (c) 2011

Version:
1.0 - 2011
Author:
Fred Pospeschil - This file is placed in the public domain and can be used and adapted without restrictions. The user of the code is totally responsible for insuring its suitability in the intended application.

NOTE: This JavaDoc file was post processed with Microsoft FrontPage and regenerating the file will cause the graphics and format changes to be lost.
Method Detail

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";

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.

// Set up the logging process by getting the user's current
// directory and adding a file seperator (\) to the end of the string.
String logFilePath = System.getProperty("user.dir")
                   + System.getProperty("file.separator");
// Designate a default name for the log file
String logFileName = "Log.txt";
// Start the logging capability
String helpFileName = "LogItHelp.htm";
// Start the logging capability.  Put log and help files in same directory.
Logger.startLogger(logFilePath, logFileName, logFilePath, helpFileName);
// Set the initial logging level
Logger.setLogLevel(Logger.ALL);


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.

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.

logger.writeLog(Logger.CONFIG, "BaseScrollMapFrame User printing map.");

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.

toString

public java.lang.String toString()
Returns the name of the class.
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