|
SalesPoint v3.3 API | ||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object log.Log
public class Log
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
and LogFileContent
.
Field Summary | |
---|---|
protected ObjectOutputStream |
ooOutput
The log file's output stream. |
protected boolean |
saveToPersistence
Save log file to persistence file or not. |
protected static OutputStream |
theGlobalOutputStream
Reference to the global output stream. |
Constructor Summary | |
---|---|
Log(OutputStream os)
Construct a new log file. |
Method Summary | |
---|---|
void |
addLogEntries(LogFileContent lfc)
Appends all LogEntries that are saved in lfc to the current log. |
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. |
static File |
getGlobalLogFile()
|
static boolean |
getSaveToPersistence()
States if the log file should be saved to the persistence 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 |
setGlobalLogFile(String filename)
Sets the global log file and assigns a FileOutputStream to it. |
static void |
setGlobalLogFile(String filename,
boolean overwrite,
boolean save)
Sets the global log file and assigns a FileOutputStream to it. |
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 |
---|
protected ObjectOutputStream ooOutput
changeOutputStream(java.io.OutputStream)
,
log(log.Loggable)
protected boolean saveToPersistence
protected static OutputStream theGlobalOutputStream
Read Only
setGlobalOutputStream(java.io.OutputStream)
Constructor Detail |
---|
public Log(OutputStream os)
os
- the outputstream to write to.Method Detail |
---|
public void closeLog() throws IOException
IOException
- if an error occurred while closing the underlying stream.closeGlobalLog()
protected void finalize() throws IOException
Disposes this log file. If this is the global log file, calls
closeGlobalLog()
, else calls closeLog()
.
finalize
in class Object
IOException
- if an error occurs while closing the underlying stream.closeLog()
,
closeGlobalLog()
public void changeOutputStream(OutputStream os) throws IOException
If an outputstream exists it is closed prior to setting the new outputstream.
os
- the new output stream.
IOException
- if an error occured while closing the old stream.setGlobalOutputStream(java.io.OutputStream)
protected void logCloseLog()
Currently does nothing. You can override this to write a log entry when the log file is being closed.
closeLog()
protected void logOpenLog()
Currently does nothing. You can override this to write a log entry when the log file is being opened.
changeOutputStream(java.io.OutputStream)
public void log(Loggable l) throws LogNoOutputStreamException, IOException
log
in interface LogContext
l
- the loggable event to be logged.
LogNoOutputStreamException
- if no OutputStream has been
specified.
IOException
- if an IOException occurs when writing to the
stream.Loggable
public void addLogEntries(LogFileContent lfc) throws LogNoOutputStreamException, IOException
lfc
to the current log. This method is used
when restoring a log file from a persistence file.
lfc
- contains the LogEntries to be added
LogNoOutputStreamException
- if no OutputStream is specified
IOException
- if a log entry cannot be written zu the output streampublic static Log getGlobalLog() throws LogNoOutputStreamException
If no log exists, one is created using the Outputstream as specified
by setGlobalOutputStream(java.io.OutputStream)
LogNoOutputStreamException
- if setGlobalOutputStream()
has not been called yet.setGlobalOutputStream(java.io.OutputStream)
,
closeGlobalLog()
public static Log createLog(OutputStream os)
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.
os
- the OutputStream to be used.public static void setLogCreator(LogCreator lc)
Call to provide support for descended Log classes.
lc
- the log creator to be used when creating log files.getGlobalLog()
public static void closeGlobalLog() throws IOException
If no log file exists no exception is thrown. Closes the log file and it's OutputStream.
IOException
- if an error occurs while closing the underlying stream.getGlobalLog()
,
setGlobalOutputStream(java.io.OutputStream)
public static void setGlobalOutputStream(OutputStream newOutputStream) throws IOException
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()
.
newOutputStream
- the new global output stream
IOException
- if an error occurs while closing the original stream.getGlobalLog()
,
closeGlobalLog()
,
changeOutputStream(java.io.OutputStream)
public static void setGlobalLogFile(String filename, boolean overwrite, boolean save) throws IOException
filename
- the file to be used as global log file.overwrite
- if true
, an existing file with the name fileName
will be
overwritten, if false
, the LogEntries will be appended to that existing file.save
- if true
, the global log file will be written to the persistence file when
the Shop is saved and accordingly loaded when the Shop's state is loaded. When that happens, the
current log file will be deleted, even if overwrite
is set to false
.
IOException
public static void setGlobalLogFile(String filename) throws IOException
setGlobalLogFile(filename, false, false)
, that is, Log entries will
be append to older log files, if they exist. The log files will not be saved/restored when the Shop
is saved/restored.
filename
- the file to be used as global log file.
IOException
public static File getGlobalLogFile()
null
public static boolean getSaveToPersistence()
true
if the log file should be saved to the persistence file, otherwise
false
.
|
SalesPoint v3.3 API | ||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |