sdsu.logging
Class Logger

java.lang.Object
  |
  +--sdsu.logging.Logger

public class Logger
extends java.lang.Object

This class is the interface for using the logging system in sdsu.logging. The intent is to provide a static interface to the logging system, so that exact same lines of code are used to log messages. This insures that you can change the type of logger used in a program by changing just one line of code.

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.

Version:
1.1 18 January 1998
Author:
Roger Whitney (whitney@cs.sdsu.edu)
See Also:
ScreenLogger, FileLogger, NullLogger

Constructor Summary
Logger()
           
 
Method Summary
static void debug(java.lang.String message)
          Add the message to the log as a debug statement.
static void error(java.lang.Exception error)
          Add the message to the log as a debug statement.
static void error(java.lang.String message)
          Add the message to the log as an error statement.
static LoggerImplementation getLogger()
          Returns the active logger.
static boolean hasLogger()
          Returns true if a logger has been registered
static void log(LoggerMessage message)
          Add the LoggerMessage object to the log.
static void log(java.lang.String message)
          Add the message to the log as a log statement.
static void register(LoggerImplementation aLogger)
          Sets the active logger.
static void reset()
          Resets logger.
static void warning(java.lang.String message)
          Add the message to the log as a warning statement.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

Logger

public Logger()
Method Detail

register

public static void register(LoggerImplementation aLogger)
Sets the active logger. Used by logger implementations to register them selves with the Logger.

hasLogger

public static boolean hasLogger()
Returns true if a logger has been registered

getLogger

public static LoggerImplementation getLogger()
Returns the active logger.

debug

public static void debug(java.lang.String message)
Add the message to the log as a debug statement.

error

public static void error(java.lang.String message)
Add the message to the log as an error statement.

error

public static void error(java.lang.Exception error)
Add the message to the log as a debug statement.

warning

public static void warning(java.lang.String message)
Add the message to the log as a warning statement.

log

public static void log(java.lang.String message)
Add the message to the log as a log statement.

log

public static void log(LoggerMessage message)
Add the LoggerMessage object to the log.

reset

public static void reset()
Resets logger. Erases any permanment storage of the log. This is to allow students to reset their log file. Not normally part of a logging system.