org.jscience.util.logging
Class LogFile

java.lang.Object
  extended by org.jscience.util.logging.AbstractLogWriter
      extended by org.jscience.util.logging.LogFile
All Implemented Interfaces:
Filter<LogEntry>, LogWriter

public class LogFile
extends AbstractLogWriter

LogFile provides great convenience for logging information from a program into a file. Every call to a write method is flushed immediatey, so the content of a LogFile always accurately corresponds to how far a logging program actually ran; i.e. the logging as a LogWriter is done synchronously. IOExceptions are replaced with LogException, which should make it easier to write the code for the logging program - with the usual drawbacks of ensuring proper Exception handling. For most cases, however, this should make things easier.

See Also:
LogException, Logger, LogEntry, DBLineLogFormatter

Field Summary
 
Fields inherited from class org.jscience.util.logging.AbstractLogWriter
filter, formatter
 
Constructor Summary
LogFile(java.io.File file)
          uses a DBLineLogFormatter
LogFile(java.io.File file, LogEntryFormatter formatter)
          constructs a LogFile based on the given file and formatter
LogFile(java.lang.String fileName)
          This constructor simply calls LogFile(new File(fileName))
 
Method Summary
 void close()
          closes the underlying writer.
 long elapsedTime()
          returns the elapsed time since LogFile initialization or since the last call to resetTime().
protected  void finalize()
          DOCUMENT ME!
 void flush()
          only needed if getAlwaysFlush() returns false
 boolean getAlwaysFlush()
          true by default
 java.io.File getFile()
          DOCUMENT ME!
 LogEntryFormatter getLogFormatter()
          DOCUMENT ME!
 void reInitialize(java.io.File file, LogEntryFormatter formatter)
          This method initializes the LogFile to a new file.
 void resetTime()
          resets the time of the embedded Stopwatch that gets initialized with the constructor
 void setAlwaysFlush(boolean flag)
          DOCUMENT ME!
 void setLogFormatter(LogEntryFormatter formatter)
          DOCUMENT ME!
 java.lang.String toString()
          DOCUMENT ME!
protected  void write(java.lang.String text)
          This is the only method actually writing to the file; all other 'write' methods call this method
 void writeElapsedTime()
          writes a LogFile entry with the elapsed time since initialization or since the last call to resetTime().
 void writeln()
          DOCUMENT ME!
 void writeln(java.lang.Object o)
          note that this function doesn't write serialized objects, but it calls toString() on the object and writes the String to the file
 void writeln(java.lang.String text)
          DOCUMENT ME!
 void writeLogEntry(java.lang.Object pattern)
          This method writes a one-line version String of the entry into the file.
 
Methods inherited from class org.jscience.util.logging.AbstractLogWriter
accept, getLogFilter, setLogFilter, write
 
Methods inherited from class java.lang.Object
clone, equals, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

LogFile

public LogFile(java.lang.String fileName)
        throws java.io.IOException
This constructor simply calls LogFile(new File(fileName))

Parameters:
fileName - DOCUMENT ME!
Throws:
java.io.IOException - DOCUMENT ME!

LogFile

public LogFile(java.io.File file)
        throws java.io.IOException
uses a DBLineLogFormatter

Parameters:
file - DOCUMENT ME!
Throws:
java.io.IOException - DOCUMENT ME!

LogFile

public LogFile(java.io.File file,
               LogEntryFormatter formatter)
        throws java.io.IOException
constructs a LogFile based on the given file and formatter

Parameters:
file - DOCUMENT ME!
formatter - DOCUMENT ME!
Throws:
java.io.IOException - DOCUMENT ME!
Method Detail

reInitialize

public void reInitialize(java.io.File file,
                         LogEntryFormatter formatter)
                  throws java.io.IOException
This method initializes the LogFile to a new file.

Parameters:
file - DOCUMENT ME!
formatter - DOCUMENT ME!
Throws:
java.io.IOException - DOCUMENT ME!

resetTime

public void resetTime()
resets the time of the embedded Stopwatch that gets initialized with the constructor

See Also:
Stopwatch

elapsedTime

public long elapsedTime()
returns the elapsed time since LogFile initialization or since the last call to resetTime().

Returns:
DOCUMENT ME!

writeLogEntry

public void writeLogEntry(java.lang.Object pattern)
                   throws LogException
This method writes a one-line version String of the entry into the file.

Specified by:
writeLogEntry in class AbstractLogWriter
Parameters:
pattern - DOCUMENT ME!
Throws:
LogException - DOCUMENT ME!
See Also:
DBLineLogFormatter

getLogFormatter

public LogEntryFormatter getLogFormatter()
DOCUMENT ME!

Overrides:
getLogFormatter in class AbstractLogWriter
Returns:
DOCUMENT ME!

setLogFormatter

public void setLogFormatter(LogEntryFormatter formatter)
DOCUMENT ME!

Overrides:
setLogFormatter in class AbstractLogWriter
Parameters:
formatter - DOCUMENT ME!

writeElapsedTime

public void writeElapsedTime()
                      throws LogException
writes a LogFile entry with the elapsed time since initialization or since the last call to resetTime().

Throws:
LogException - DOCUMENT ME!

writeln

public void writeln()
             throws java.io.IOException
DOCUMENT ME!

Throws:
java.io.IOException - DOCUMENT ME!

writeln

public void writeln(java.lang.String text)
             throws java.io.IOException
DOCUMENT ME!

Parameters:
text - DOCUMENT ME!
Throws:
java.io.IOException - DOCUMENT ME!

write

protected void write(java.lang.String text)
              throws java.io.IOException
This is the only method actually writing to the file; all other 'write' methods call this method

Parameters:
text - DOCUMENT ME!
Throws:
java.io.IOException - DOCUMENT ME!

flush

public void flush()
           throws java.io.IOException
only needed if getAlwaysFlush() returns false

Throws:
java.io.IOException - DOCUMENT ME!

setAlwaysFlush

public void setAlwaysFlush(boolean flag)
DOCUMENT ME!

Parameters:
flag - DOCUMENT ME!

getAlwaysFlush

public boolean getAlwaysFlush()
true by default

Returns:
DOCUMENT ME!

writeln

public void writeln(java.lang.Object o)
             throws java.io.IOException
note that this function doesn't write serialized objects, but it calls toString() on the object and writes the String to the file

Parameters:
o - DOCUMENT ME!
Throws:
java.io.IOException - DOCUMENT ME!

close

public void close()
           throws java.io.IOException
closes the underlying writer. A note that the file was closed will be written into the log.

Throws:
java.io.IOException - DOCUMENT ME!

getFile

public java.io.File getFile()
DOCUMENT ME!

Returns:
DOCUMENT ME!

toString

public java.lang.String toString()
DOCUMENT ME!

Overrides:
toString in class java.lang.Object
Returns:
DOCUMENT ME!

finalize

protected void finalize()
                 throws java.lang.Exception
DOCUMENT ME!

Overrides:
finalize in class java.lang.Object
Throws:
java.lang.Exception - DOCUMENT ME!