Description: A basic logger capability which uses the same logging levels as the much larger standard Java logger.
Copyright: Copyright (c) 2011
Method Detail |
public static void startLogger(java.lang.String logPath, java.lang.String logName, java.lang.String helpPath, java.lang.String helpName)
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.
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: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: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);
public static java.lang.String getLogFileName()
public static java.lang.String getLogFilePath()
public static java.lang.String getlogItHelpFileName()
public static java.lang.String getLogItHelpPath()
public static int getLogLevel()
public static void setLogFileName(java.lang.String fileName)
fileName
- The log file name.public static void setLogFilePath(java.lang.String pathName)
pathName
- A String defining the path to the log file. This string must end with a file separator.public static void setlogItHelpFileName(java.lang.String fileName)
fileName
- The log help file name.public static void setLogItHelpPath(java.lang.String pathName)
pathName
- A String defining the path to the LogIt help file. This string must end with a file separator.public static void setLogLevel(int level)
level
- Logger.OFF, Logger.SEVERE, Logger.WARNING, Logger.INFO, Logger.CONFIG, Logger.FINE, Logger.FINER, Logger.FINEST, and Logger.ALL.public static void writeLog(int level, java.lang.String textMessage)
logger.writeLog(Logger.CONFIG, "BaseScrollMapFrame User printing map.");
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.public java.lang.String toString()
Logger LogFile=D:\A JOptionPanel\Log.txt Log Level=1 HelpFile=D:\A JOptionPanel\LogItHelp.htm