|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object | +--sdsu.logging.Logger
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.
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 |
public Logger()
Method Detail |
public static void register(LoggerImplementation aLogger)
public static boolean hasLogger()
public static LoggerImplementation getLogger()
public static void debug(java.lang.String message)
public static void error(java.lang.String message)
public static void error(java.lang.Exception error)
public static void warning(java.lang.String message)
public static void log(java.lang.String message)
public static void log(LoggerMessage message)
public static void reset()
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |