tuwien.auto.calimero.log
Class LogFileWriter

java.lang.Object
  extended by tuwien.auto.calimero.log.LogWriter
      extended by tuwien.auto.calimero.log.LogStreamWriter
          extended by tuwien.auto.calimero.log.LogFileWriter

public class LogFileWriter
extends LogStreamWriter

A LogWriter using a file resource as output destination for log information.

A file name is supplied on creation of this log writer, the file is opened and used for further logging. After close()ing the log writer, it cannot be opened anymore.
For output the platform's default character set is used.
A maximum allowed file size may be specified to prevent file size explosion. If the size limit is reached, the file content is deleted before any new output.


Field Summary
 
Fields inherited from class tuwien.auto.calimero.log.LogStreamWriter
c, formatOutput
 
Constructor Summary
LogFileWriter(LogLevel level, java.lang.String file, boolean append)
          Like LogFileWriter(String, boolean), with the option to adjust the filter log level for information logged by LogFileWriter.
LogFileWriter(LogLevel level, java.lang.String file, boolean append, int maxSize)
          Like LogFileWriter(LogLevel, String, boolean), with the option to specify the maximum file size allowed for all output written.
LogFileWriter(LogLevel level, java.lang.String file, boolean append, int maxSize, boolean autoFlush)
          Like LogFileWriter(LogLevel, String, boolean, int), with the option to adjust the automatic flush behavior of data.
LogFileWriter(java.lang.String file, boolean append)
          Creates a LogFileWriter to write to the output file named by file and open the file according to append.
LogFileWriter(java.lang.String file, boolean append, boolean autoFlush)
          Like LogFileWriter(String, boolean), with the option to adjust the automatic flush behavior of data.
 
Method Summary
 void close()
          Closes the LogWriter and all its resources.
 java.lang.String getFileName()
          Returns the file name of the file resource used by this LogFileWriter or "" if the log writer has already been closed.
 int getMaxSize()
          Returns the maximum allowed file size generated by this LogFileWriter, or 0 if no maximum was set.
 void setMaxSize(int size)
          Sets the maximum allowed file size generated by this LogFileWriter.
 void write(java.lang.String logService, LogLevel level, java.lang.String msg)
          Writes a message out to this LogWriter.
 void write(java.lang.String logService, LogLevel level, java.lang.String msg, java.lang.Throwable t)
          Like LogWriter.write(String, LogLevel, String), in addition a Throwable object is taken which will be added to the message.
 
Methods inherited from class tuwien.auto.calimero.log.LogStreamWriter
flush, formatOutput, logAllowed, setOutput
 
Methods inherited from class tuwien.auto.calimero.log.LogWriter
getErrorHandler, getLogLevel, setErrorHandler, setLogLevel
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

LogFileWriter

public LogFileWriter(LogLevel level,
                     java.lang.String file,
                     boolean append)
              throws KNXLogException
Like LogFileWriter(String, boolean), with the option to adjust the filter log level for information logged by LogFileWriter.

Parameters:
level - log level used by this LogWriter to filter log information
file - file name in the file system to open or create
append - set this true to append output at end of file, or false to start writing into an empty file at the beginning
Throws:
KNXLogException - if file can not be created or opened

LogFileWriter

public LogFileWriter(LogLevel level,
                     java.lang.String file,
                     boolean append,
                     int maxSize)
              throws KNXLogException
Like LogFileWriter(LogLevel, String, boolean), with the option to specify the maximum file size allowed for all output written.

During opening of file, the file size is checked to be smaller than maxSize, otherwise the file content is erased.
If a call to write() would exceed the maximum file size specified, the file content is erased before the new log information is written.

Parameters:
level - log level used by this LogWriter to filter log information
file - file name in the file system to open or create
append - set this true to append output at end of file, or false to start writing into an empty file at the beginning
maxSize - maximum file size generated by this LogFileWriter
Throws:
KNXLogException - if file can not be created or opened

LogFileWriter

public LogFileWriter(LogLevel level,
                     java.lang.String file,
                     boolean append,
                     int maxSize,
                     boolean autoFlush)
              throws KNXLogException
Like LogFileWriter(LogLevel, String, boolean, int), with the option to adjust the automatic flush behavior of data.

Parameters:
level - log level used by this LogWriter to filter log information
file - file name in the file system to open or create
append - set this true to append output at end of file, or false to start writing into an empty file at the beginning
maxSize - maximum file size generated by this LogFileWriter
autoFlush - set true to force data be immediately written to file after every write() call, set false to buffer data and flush only on full buffer
Throws:
KNXLogException - if file can not be created or opened

LogFileWriter

public LogFileWriter(java.lang.String file,
                     boolean append)
              throws KNXLogException
Creates a LogFileWriter to write to the output file named by file and open the file according to append.

Parameters:
file - file name in the file system to open or create, the path to the file has to exist
append - set this true to append output at end of file, or false to start writing into an empty file at the beginning
Throws:
KNXLogException - if path to file does not exist, if file can not be created or opened

LogFileWriter

public LogFileWriter(java.lang.String file,
                     boolean append,
                     boolean autoFlush)
              throws KNXLogException
Like LogFileWriter(String, boolean), with the option to adjust the automatic flush behavior of data.

Parameters:
file - file name in the file system to open or create
append - set this true to append output at end of file, or false to start writing into an empty file at the beginning
autoFlush - set true to force data be immediately written to file after every write() call, set false to buffer data and flush only on full buffer
Throws:
KNXLogException - if file can not be created or opened
Method Detail

close

public void close()
Description copied from class: LogWriter
Closes the LogWriter and all its resources.

If necessary, all output is flushes before.

Overrides:
close in class LogStreamWriter

getFileName

public final java.lang.String getFileName()
Returns the file name of the file resource used by this LogFileWriter or "" if the log writer has already been closed.

The file name is the same as supplied on creation of this LogWriter, no path resolving etc. was done.

Returns:
file name

getMaxSize

public final int getMaxSize()
Returns the maximum allowed file size generated by this LogFileWriter, or 0 if no maximum was set.

Returns:
maximum file size in bytes

setMaxSize

public final void setMaxSize(int size)
Sets the maximum allowed file size generated by this LogFileWriter.

The value is only set if size >= 0.
If size has a value of 0, no file size limit is enforced.

Parameters:
size - new allowed file size in bytes

write

public void write(java.lang.String logService,
                  LogLevel level,
                  java.lang.String msg)
Description copied from class: LogWriter
Writes a message out to this LogWriter.

The message has the associated log level level. It will only be written if the LogWriter logging level is not more restrictive than level. Otherwise the message is ignored. LogWriter is responsible for formatting the output.

Overrides:
write in class LogStreamWriter
Parameters:
logService - log service name stating the source of the message
level - log level of message
msg - the message to write

write

public void write(java.lang.String logService,
                  LogLevel level,
                  java.lang.String msg,
                  java.lang.Throwable t)
Description copied from class: LogWriter
Like LogWriter.write(String, LogLevel, String), in addition a Throwable object is taken which will be added to the message.

Overrides:
write in class LogStreamWriter
Parameters:
logService - log service name stating the source of the message
level - log level of message
msg - the message to write
t - Throwable object, might be null