All Packages Class Hierarchy This Package Previous Next Index
java.lang.Object | +----sdsu.logging.Logger
Other classes (ScreenLogger, FileLogger) actually implement the logging system. To use the Logger the actual logger must be registered. This is done using the register method in the logger class you wish to use. So to use the FileLogger first register it via:
FileLogger.register( LogFileName );A FileLogger object that writes to the given file is now registered with the Logger class. Then in your program use the static methods of this class to add messages to the log. For example:
Logger.debug( "Value of x: " + x );will add a debug message to the log. Note you can only register one logger per program. Also, if you do not register a logger the ScreenLogger will be used.
Four types of messages are defined: debug, warning, error, and log. Debug is for recording debug statements, log for logging routine usage of the program, warnings are for problems in usage (like someone trying to break into a server), errors are for logging exceptions and errors that occur when the program is run. More types of messages can be created by subclassing sdsu.logging.LoggerMessage.
Some logger implementations of this class allow the programmer to turn off logging of one or more types of messages while still logging the other types. Once a program is debugged, you can turn off debug messages, but leave them in the program for future use. This does incurr a slight performance penalty, but this should not be a problem for most student programs. These loggers must be accessed directly to turn logging message off or on. This direct access is done using the register method. For example:
FileLogger myLog = FileLogger.register( "LogFile"); myLog.debugOff(); myLog.warningOff();will register the FileLogger and turn off debug and warning statements. This means the statment:
Logger.debug( "Value of x: " + x );will have no effect later in the program.
The logger stores the active logger in a static field. To help insure that this class is not unloaded during garbage collection an reference to the Logger class is stored in the System properties under the key: _$sdsu.logging.Logger.instance. If you remove this reference by replacing this or all system properties, you need to store a reference to Logger in your program or turn off unloading of classes.
The logging system is based on the logging pattern by Neil Harrison in Pattern Languages of Program Design 3 Eds Martin, Riehle, Buschman, 1998, pp 277-289.
public Logger()
public static void register(LoggerImplementation aLogger)
public static boolean hasLogger()
public static LoggerImplementation getLogger()
public static void debug(String message)
public static void error(String message)
public static void error(Exception error)
public static void warning(String message)
public static void log(String message)
public static void log(LoggerMessage message)
public static void reset()
All Packages Class Hierarchy This Package Previous Next Index