All Packages  Class Hierarchy  This Package  Previous  Next  Index

Class sdsu.logging.Logger

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

public class Logger
extends 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 Index

 o Logger()

Method Index

 o debug(String)
Add the message to the log as a debug statement.
 o error(Exception)
Add the message to the log as a debug statement.
 o error(String)
Add the message to the log as an error statement.
 o getLogger()
Returns the active logger.
 o hasLogger()
Returns true if a logger has been registered
 o log(LoggerMessage)
Add the LoggerMessage object to the log.
 o log(String)
Add the message to the log as a log statement.
 o register(LoggerImplementation)
Sets the active logger.
 o reset()
Resets logger.
 o warning(String)
Add the message to the log as a warning statement.

Constructors

 o Logger
 public Logger()

Methods

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

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

 o getLogger
 public static LoggerImplementation getLogger()
Returns the active logger.

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

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

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

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

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

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

 o 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.


All Packages  Class Hierarchy  This Package  Previous  Next  Index