SalesPoint Framework v3.0

log
Class Log

java.lang.Object
  |
  +--log.Log

public class Log
extends Object
implements LogContext

Represents a log file.

There is one global writable log file in the whole system. An instance of LogCreator is used to create the global log file as well as any local log file.

Anything loggable must suit the Loggable interface and must be able to generate an instance of LogEntry

To read in log files see LogInputStream.

Hooks:
Incorporate New Log Type , Log Opening Or Closing Of Log File
Since:
v1.0
Version:
1.0
Author:
Steffen Zschaler

Field Summary
protected  ObjectOutputStream ooOutput
          The log files output stream.
protected static OutputStream theGlobalOutputStream
          Reference to the global output stream.
 
Constructor Summary
Log(OutputStream os)
          Construct a new log file.
 
Method Summary
 void changeOutputStream(OutputStream os)
          Change this log's outputstream.
static void closeGlobalLog()
          Closes the global log file if any log file was open.
 void closeLog()
          Closes this Log file.
static Log createLog(OutputStream os)
          Create a new Log file using the current Log creator.
protected  void finalize()
          Called by the garbage collector on an object when garbage collection determines that there are no more references to the object.
static Log getGlobalLog()
          Returns the current global log file.
 void log(Loggable l)
          Adds one entry to the log file.
protected  void logCloseLog()
          Add a log entry when closing the log file.
protected  void logOpenLog()
          Add a log entry when opening the log file.
static void setGlobalOutputStream(OutputStream newOutputStream)
          Changes the current OutputStream of the global log file.
static void setLogCreator(LogCreator lc)
          Change the Log creator.
 
Methods inherited from class java.lang.Object
clone, equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

ooOutput

protected ObjectOutputStream ooOutput
The log files output stream.
See Also:
changeOutputStream(java.io.OutputStream), log(log.Loggable)

theGlobalOutputStream

protected static OutputStream theGlobalOutputStream
Reference to the global output stream.

Read Only

See Also:
setGlobalOutputStream(java.io.OutputStream)
Constructor Detail

Log

public Log(OutputStream os)
Construct a new log file.
Parameters:
os - the outputstream to write to.
Method Detail

closeLog

public void closeLog()
              throws IOException
Closes this Log file.
Override:
Never.
Throws:
IOException - if an error occurred while closing the underlying stream.
See Also:
closeGlobalLog()

finalize

protected void finalize()
                 throws IOException
Called by the garbage collector on an object when garbage collection determines that there are no more references to the object.

Disposes of this log file. If this is the global log file, calls closeGlobalLog(), else calls closeLog().

Override:
Never.
Throws:
IOException - if an error occurs while closing the underlying stream.
Overrides:
finalize in class Object
See Also:
closeLog(), closeGlobalLog()

changeOutputStream

public void changeOutputStream(OutputStream os)
                        throws IOException
Change this log's outputstream.

If an outputstream exists it is closed prior to setting the new outputstream.

Override:
Never.
Parameters:
os - the new output stream.
Throws:
IOException - if an error occured while closing the old stream.
See Also:
setGlobalOutputStream(java.io.OutputStream)

logCloseLog

protected void logCloseLog()
Add a log entry when closing the log file.

Currently does nothing. You can override this to write a log entry when the log file is being closed.

Override:
Sometimes.
Override this method if you want to add a log entry when the log file is closed.
Hooks:
Log Opening Or Closing Of Log File
See Also:
closeLog()

logOpenLog

protected void logOpenLog()
Add a log entry when opening the log file.

Currently does nothing. You can override this to write a log entry when the log file is being opened.

Override:
Sometimes.
Override this method if you want to add a log entry when the log file is opened.
Hooks:
Log Opening Or Closing Of Log File
See Also:
changeOutputStream(java.io.OutputStream)

log

public void log(Loggable l)
         throws LogNoOutputStreamException,
                IOException
Adds one entry to the log file. Calls l.getLogData().
Override:
Never.
Specified by:
log in interface LogContext
Parameters:
l - the event to be logged.
Throws:
LogNoOutputStreamException - if no OutputStream has been specified.
IOException - if an IOException occurs when writing to the stream.
See Also:
Loggable

getGlobalLog

public static Log getGlobalLog()
                        throws LogNoOutputStreamException
Returns the current global log file.

If no log file exists, creates it using the Outputstream as specified by setGlobalOutputStream(java.io.OutputStream)

Throws:
LogNoOutputStreamException - if setGlobalOutputStream() has not been called yet.
See Also:
setGlobalOutputStream(java.io.OutputStream), closeGlobalLog()

createLog

public static Log createLog(OutputStream os)
Create a new Log file using the current Log creator.

You should prefer calling this method to directly creating a new Log file as this method will provide an easy interface for adapting to new log classes.

Parameters:
os - the OutputStream to be used.

setLogCreator

public static void setLogCreator(LogCreator lc)
Change the Log creator.

Call to provide support for descended Log classes.

Parameters:
lc - the log creator to be used when creating log files.
Hooks:
Incorporate New Log Type
See Also:
getGlobalLog()

closeGlobalLog

public static void closeGlobalLog()
                           throws IOException
Closes the global log file if any log file was open.

If no log file exists no exception is thrown. Closes the log file and it's OutputStream.

Throws:
IOException - if an error occurs while closing the underlying stream.
See Also:
getGlobalLog(), setGlobalOutputStream(java.io.OutputStream)

setGlobalOutputStream

public static void setGlobalOutputStream(OutputStream newOutputStream)
                                  throws IOException
Changes the current OutputStream of the global log file.

This method must be called at least once before any global log operation takes place.

If an OutputStream exists it will be closed automatically. To close the entire global log file use closeGlobalLog().

Parameters:
newOutputStream - the new global output stream
Throws:
IOException - if an error occurs while closing the original stream.
See Also:
getGlobalLog(), closeGlobalLog(), changeOutputStream(java.io.OutputStream)

SalesPoint Framework v3.0