AppLog.
- By Todd Lauinger
- July 17, 2000
Enterprise Java
JLog: A Java Logging Framework
Todd Lauinger
Listing 1. AppLog.
package log;
/**
* <code>AppLog</code> wraps the Log class to do
* application-general logging. It provides a singleton accessor,
* along with lots of handy class method {static} accessors. <p>
* <code>AppLog</code> should be your general application
* log to write out events of a non-specific nature. You can create
* additional special-purpose logs (for example, DbLog to log
* database events) by copying this class and creating your own
* handy class method accessors. <p>
*
* @see Log
*/
public class AppLog {
/**
* Provides the class variable for the Singleton pattern,
* to keep track of the one and only instance of this class.
*/
protected static Log singleton = new MultiThreadLog("AppLog");
/**
* Returns the singleton instance of this class.
*/
public static Log getInstance() {
return singleton;
}
/**
* Logs a text string at the logging level specified.
*
* This method is used when your code needs to parameterize
* the logging level. Otherwise you probably should use the
* err(), warning(), info(), detail(), or trace() methods below,
* they will be less verbose in your code.
*/
public static void logString(String logString, int errorLevel) {
// Dispatch the call to the instance side
singleton.logString(logString, errorLevel);
}
/**
* Logs a text string at CRITICAL_ERROR_LEVEL
*
* This method provides the implementation for a quick accessor
* to log a critical error,
* replacing typical calls to System.err.println().
*/
public static void criticalError(String logString) {
logString(logString, Log.CRITICAL_ERROR_LEVEL);
}
/**
* Logs a text string at ERROR_LEVEL
*
* This method provides the implementation for a quick accessor
* to log a critical error,
* replacing typical calls to System.err.println().
*/
public static void error(String logString) {
logString(logString, Log.ERROR_LEVEL);
}
/**
* Logs a text string at WARNING_LEVEL
*/
public static void warning(String logString) {
logString(logString, Log.WARNING_LEVEL);
}
/**
* Logs a text string at INFO_LEVEL
*/
public static void info(String logString) {
logString(logString, Log.INFO_LEVEL);
}
/**
* Logs a text string at DETAIL_LEVEL
*/
public static void detail(String logString) {
logString(logString, Log.DETAIL_LEVEL);
}
/**
* Logs a text string at TRACE_LEVEL
*/
public static void trace(String logString) {
logString(logString, Log.TRACE_LEVEL);
}
}