org.jlf.log
Class AbstractLoggingMechanism

java.lang.Object
  |
  +--org.jlf.log.AbstractLoggingMechanism
Direct Known Subclasses:
AbstractFileLoggingMechanism, SMTPLoggingMechanism, StandardErrLoggingMechanism

public abstract class AbstractLoggingMechanism
extends java.lang.Object

AbstractLoggingMechanism is an abstract class which serves to define a hierarchy of different logging mechanisms. Subclasses of this class will implement the different mechanisms defined herein. The main responsibility of this class hierarchy is to offload the implementation work for differences in logging streams for different mechanisms. For example, the standard error stream is a very different implementation than a shared local output file.


Field Summary
protected static java.text.SimpleDateFormat compactDateFormat
           
protected static java.text.DateFormat dateFormat
           
protected  java.util.Date dateOpened
          The date the mechanism was first opened.
protected  java.util.Vector logs
           
protected  java.io.PrintWriter printStream
           
protected static java.text.SimpleDateFormat timeFormat
           
 
Constructor Summary
AbstractLoggingMechanism()
           
 
Method Summary
protected  void close()
          This method closes the particular logging mechanism so that messages no longer get logged to the mechanism.
protected  void closeForLog(Log log)
          Logs call this method to deregister themselves with the mechanism.
protected  java.lang.String compactCurrentDate()
           
protected  java.lang.String currentDate()
           
protected  java.lang.String currentTime()
           
protected static AbstractLoggingMechanism getLoggingMechanismForString(java.lang.String mechanismString)
           
 java.lang.String getName()
          Return the name of the mechanism.
protected  boolean hasDateRolledOver()
          Checks the current date verses the date the log was opened.
protected  boolean isDatedLog()
          Mechanisms can be dated or non-dated.
protected  boolean isSharedLog()
          Mechanisms can be shared or unique.
protected  java.lang.String loggingPrefix(Log log, int loggingLevel)
          Returns a string which is to be concatenated before the log message, so that the log message can be properly understood in the context of other messages and logs (if a shared log).
protected  void logString(Log log, int loggingLevel, java.lang.String logString)
          Logs a string to printStream, complete with a descriptive prefix so viewers of the log can interpret who logged which strings and how important they were.
protected  void notifyLogClosed(Log log)
           
protected  void notifyLoggingLevelChange(Log log, int loggingLevel)
           
protected  void notifyLogOpened(Log log, int loggingLevel)
           
protected  void open(Log log)
          This method opens the particular logging mechanism so that messages can be output to the printSteam instance variable.
protected  void openForLog(Log log, int loggingLevel)
          Logs call this method to register themselves with the mechanism.
protected  void rollLogOver()
          Rolls a log over, typically on a date change, by closing the log and re-opening it.
 java.lang.String toString()
          Return a nice debug string.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

printStream

protected java.io.PrintWriter printStream

dateOpened

protected java.util.Date dateOpened
The date the mechanism was first opened.


logs

protected java.util.Vector logs

timeFormat

protected static java.text.SimpleDateFormat timeFormat

compactDateFormat

protected static java.text.SimpleDateFormat compactDateFormat

dateFormat

protected static java.text.DateFormat dateFormat
Constructor Detail

AbstractLoggingMechanism

public AbstractLoggingMechanism()
Method Detail

currentDate

protected java.lang.String currentDate()

compactCurrentDate

protected java.lang.String compactCurrentDate()

currentTime

protected java.lang.String currentTime()

isDatedLog

protected boolean isDatedLog()
Mechanisms can be dated or non-dated. If dated, the log needs to have a date appended to a file name (if it has one) and it must be rolled over to a new one when the current date changes. The default setting is non-dated, this method must be overridden when dated.


isSharedLog

protected boolean isSharedLog()
Mechanisms can be shared or unique. Shared mechanisms require the log name to be in every log entry (so you can distinguish between the log entries). Unique mechanisms name themselves uniquely (for example, have the log name in their file name) so they do not have to put the name of the log in their log entry. The default is shared (true).


loggingPrefix

protected java.lang.String loggingPrefix(Log log,
                                         int loggingLevel)
Returns a string which is to be concatenated before the log message, so that the log message can be properly understood in the context of other messages and logs (if a shared log).
 The format is [loggingLevel]|[time]|
 where  [loggingLevel] is the integer logging level the msg was logged at
        [time] is the local time in SHORT DateFormat
 


open

protected void open(Log log)
This method opens the particular logging mechanism so that messages can be output to the printSteam instance variable.


close

protected void close()
This method closes the particular logging mechanism so that messages no longer get logged to the mechanism. Overrides should call the superclass method so that printStream gets reset to StdErr in case a subsequent open has problems and the error can be logged somewhere!


notifyLogOpened

protected void notifyLogOpened(Log log,
                               int loggingLevel)

notifyLogClosed

protected void notifyLogClosed(Log log)

notifyLoggingLevelChange

protected void notifyLoggingLevelChange(Log log,
                                        int loggingLevel)

openForLog

protected void openForLog(Log log,
                          int loggingLevel)
Logs call this method to register themselves with the mechanism. It will automatically open the mechanism if needed and log the fact that a log started using this mechanism.


closeForLog

protected void closeForLog(Log log)
Logs call this method to deregister themselves with the mechanism. It will automatically close the mechanism if needed and log the fact that a log stopped using this mechanism.


hasDateRolledOver

protected boolean hasDateRolledOver()
Checks the current date verses the date the log was opened. If the current date is one or more days greater (that is, have we passed midnight), return true. Else, return false. To make this method reasonably fast, it does not compare years, only days within a year.


rollLogOver

protected void rollLogOver()
Rolls a log over, typically on a date change, by closing the log and re-opening it.


logString

protected void logString(Log log,
                         int loggingLevel,
                         java.lang.String logString)
Logs a string to printStream, complete with a descriptive prefix so viewers of the log can interpret who logged which strings and how important they were.


getLoggingMechanismForString

protected static AbstractLoggingMechanism getLoggingMechanismForString(java.lang.String mechanismString)
                                                                throws java.lang.Exception
java.lang.Exception

getName

public java.lang.String getName()
Return the name of the mechanism. Today this is the full class name.


toString

public java.lang.String toString()
Return a nice debug string.

Overrides:
toString in class java.lang.Object