public class TextFileApplicationLogger extends AbstractApplicationLogger implements java.io.Closeable, java.io.Flushable
ApplicationLogger
appends all log messages to a text file, where every
message is written to one line. Additional constructors also allow to write messages into any
PrintWriter
instead, so this class can also be used to send log messages to standard out or
standard error.
Note that the close()
method of this logger has to be called after the end of the logging
process if messages are written to a file. Otherwise the file will not be terminated and information
may be lost.
Constructor and Description |
---|
TextFileApplicationLogger(java.io.File file)
Creates a new instance of this class and appends all messaged to the specified file.
|
TextFileApplicationLogger(java.io.File file,
boolean append)
Creates a new instance of this class and writes all messaged to the specified file.
|
TextFileApplicationLogger(java.io.PrintWriter writer)
Creates a new instance of this class that writes into the specified writer instead of a file.
|
Modifier and Type | Method and Description |
---|---|
void |
addMessage(ApplicationLoggerMessage message)
Outputs a usual message to the user.
|
void |
close()
Closes the underlying writer or the target file.
|
void |
flush() |
static TextFileApplicationLogger |
newStandardErrorInstance()
Creates a new instance of this class that writes to the standard error.
|
static TextFileApplicationLogger |
newStandardOutInstance()
Creates a new instance of this class that writes to the standard out.
|
addError, addError, addError, addError, addMessage, addMessage, addWarning, addWarning
public TextFileApplicationLogger(java.io.PrintWriter writer)
writer
- the writer to write the messages intopublic TextFileApplicationLogger(java.io.File file, boolean append) throws java.io.IOException
file
- the output fileappend
- Specify true
here if you want messages to be appended to an existing file
or false
if an existing file shall be overwritten.java.io.IOException
public TextFileApplicationLogger(java.io.File file) throws java.io.IOException
file
- the output filejava.io.IOException
public static TextFileApplicationLogger newStandardOutInstance()
public static TextFileApplicationLogger newStandardErrorInstance()
public void addMessage(ApplicationLoggerMessage message)
ApplicationLogger
addMessage
in interface ApplicationLogger
public void close()
close
in interface java.io.Closeable
close
in interface java.lang.AutoCloseable
Closeable.close()
public void flush()
flush
in interface java.io.Flushable