com.adventnet.afp.log
Class DefaultLogger

java.lang.Object
  |
  +--com.adventnet.afp.log.AbstractLogger
        |
        +--com.adventnet.afp.log.DefaultLogger
All Implemented Interfaces:
Logger

public class DefaultLogger
extends AbstractLogger


This class is the default implementation of a Logger. In a situation where some file operations are not permitted or error occurs during log module initialization,it is highly essential that all log messages are redirected to the console. This can be achieved by redirecting all the log messages to System.out and System.err.  For doing this, DefaultLogger is used.

The class DefaultLogger is the default implementation of a Logger. The Log messages will be displayed on the console based on the LogLevel of the message.

The LoggerProperties such as InstanceName, DisplayName, ClassName,  LogLevel etc., are received from the LogWriter.  The output from the Logger can be redirected to some other file, by changing the LogWriter at runtime.
 
The various methods used in Default Logger are almost same as those used in the Logger. The err method can be used for logging the error messages  with the exception trace. The message will be formatted by the formatMessage method. The default formatting has the time stamp in the format "hh:mm:ss:SSS DisplayName".

Similarly, the out method can be used for Logging general output  messages and debugging messages. The message will be formatted using the  method formatMessage. The default formatting has the time stamp in the format "hh:mm:ss:SSS DisplayName".

In both the cases stated above, the message will be logged only if the level of the message is less than or equal to the Logger's logging level.

@see Logger


Fields inherited from class com.adventnet.afp.log.AbstractLogger
listeners, loggingLevel
 
Constructor Summary
DefaultLogger()
          Creates a new DefaultLogger instance with default Logger properties.
 
Method Summary
 void err(java.lang.String message, int level)
          The err method can be used for logging the error messages.
 void err(java.lang.String message, java.lang.Throwable exception, int level)
          The err method can be used for logging the error messages with the exception trace.
 java.lang.String formatMessage(java.lang.String message, int level)
          formatMessage method formats the message to a custom format.
 void init(LoggerProperties loggerProps, LogWriter logWriter)
          The init method is used to intialize the DefaultLogger.
 void out(java.lang.String message, int level)
          The out method can be used for Logging general output messages and debugging messages.
 
Methods inherited from class com.adventnet.afp.log.AbstractLogger
addPropertyChangeListener, getInstanceName, getLogLevel, removePropertyChangeListener, setLogLevel
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

DefaultLogger

public DefaultLogger()
Creates a new DefaultLogger instance with default Logger properties.
Method Detail

init

public void init(LoggerProperties loggerProps,
                 LogWriter logWriter)
          throws LogException
The init method is used to intialize the DefaultLogger. A logger will become active and would start handling inputs only after it is initialized. The logger properties and Log Writer are passed to this method.
Overrides:
init in class AbstractLogger
Parameters:
loggerProps - specifies the properties of the Logger
logWriter - instance to which the Logger has to be associated.

out

public void out(java.lang.String message,
                int level)
The out method can be used for Logging general output messages and debugging messages. The message will be formatted using the formatMessage(java.lang.String, int). The defualt formatting has the time stamp in the format "hh:mm:ss:SSS DisplayName" The message will be logged only if the level of the message is less than or equal to that of the Logger's logging level.
Parameters:
message - String value
level - an int value

err

public void err(java.lang.String message,
                int level)
The err method can be used for logging the error messages. The message will be formatted using the formatMessage(java.lang.String, int). The defualt formatting has the time stamp in the format "hh:mm:ss:SSS DisplayName" The message will be logged only if the level of the message is less than or equal to that of the Logger's logging level.
Parameters:
message - String value describing the exception
level - an int logging value

err

public void err(java.lang.String message,
                java.lang.Throwable exception,
                int level)
The err method can be used for logging the error messages with the exception trace. The message will be formatted using the formatMessage(java.lang.String, int). The defualt formatting has the time stamp in the format "hh:mm:ss:SSS DisplayName" The message will be logged only if the level of the message is less than or equal to that of the Logger's logging level.
Parameters:
message - String value describing the exception
exception - a Throwable exception
level - an int logging value

formatMessage

public java.lang.String formatMessage(java.lang.String message,
                                      int level)
formatMessage method formats the message to a custom format. In the defualt formatting, the message is prepended with the time stamp in the format "hh:mm:ss:SSS DisplayName". This method can be overridden to get the message in the user-defined format.
Parameters:
message - a String value
level - an int value
Returns:
a String value


Copyright (c)AdventNet Inc., 1996-2004