qflib 0.98.0

de.qfs.lib.log
Class StreamLogWriter

java.lang.Object
  |
  +--de.qfs.lib.log.StreamLogWriter
All Implemented Interfaces:
LogWriter
Direct Known Subclasses:
FileLogWriter

public class StreamLogWriter
extends java.lang.Object
implements LogWriter

An implementation of the LogWriter interface that writes LogEntries to a PrintStream or a PrintWriter.

Since:
0.98.0
Version:
$Revision: 1.3 $
Author:
Gregor Schmid

Field Summary
protected  boolean closed
          Whether the StreamLogWriter has been closed.
protected  LogFormat format
          The format used to print LogEntries.
protected  boolean mustClose
          Whether the stream or writer must be closed in close.
protected  java.io.PrintStream ps
          A stream to print to.
protected  java.io.PrintWriter pw
          A writer to print to.
 
Constructor Summary
StreamLogWriter()
          Create a new StreamLogWriter that uses a DefaultLogFormat to print LogEntries to System.err.
StreamLogWriter(LogFormat format)
          Create a new StreamLogWriter that prints LogEntries to System.err.
StreamLogWriter(java.io.PrintStream ps, boolean own)
          Create a new StreamLogWriter that uses a DefaultLogFormat to print LogEntries to a stream.
StreamLogWriter(java.io.PrintStream ps, boolean own, LogFormat format)
          Create a new StreamLogWriter that prints LogEntries to a stream.
StreamLogWriter(java.io.PrintWriter pw, boolean own)
          Create a new StreamLogWriter that uses a DefaultLogFormat to print LogEntries to a writer.
StreamLogWriter(java.io.PrintWriter pw, boolean own, LogFormat format)
          Create a new StreamLogWriter that prints LogEntries to a writer.
 
Method Summary
 void close()
          Close the StreamLogWriter.
 LogFormat getFormat()
          Get the format the StreamLogWriter uses to print LogEntries.
 void setFormat(LogFormat format)
          Set the format to use for printing LogEntries.
 void write(LogEntry entry)
          Write one LogEntry.
 void write(LogEntry[] entries)
          Write an array of LogEntires in one go.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

format

protected LogFormat format
The format used to print LogEntries.

ps

protected java.io.PrintStream ps
A stream to print to.

pw

protected java.io.PrintWriter pw
A writer to print to.

mustClose

protected boolean mustClose
Whether the stream or writer must be closed in close.

closed

protected boolean closed
Whether the StreamLogWriter has been closed.
Constructor Detail

StreamLogWriter

public StreamLogWriter()
Create a new StreamLogWriter that uses a DefaultLogFormat to print LogEntries to System.err.

StreamLogWriter

public StreamLogWriter(LogFormat format)
Create a new StreamLogWriter that prints LogEntries to System.err.
Parameters:
format - The format used to print LogEntries.

StreamLogWriter

public StreamLogWriter(java.io.PrintStream ps,
                       boolean own)
Create a new StreamLogWriter that uses a DefaultLogFormat to print LogEntries to a stream.
Parameters:
ps - The stream to print to.
own - Whether the stream is owned by the StreamLogWriter and should be closed when the StreamLogWriter is closed.

StreamLogWriter

public StreamLogWriter(java.io.PrintStream ps,
                       boolean own,
                       LogFormat format)
Create a new StreamLogWriter that prints LogEntries to a stream.
Parameters:
ps - The stream to print to.
own - Whether the stream is owned by the StreamLogWriter and should be closed when the StreamLogWriter is closed.
format - The format used to print LogEntries.

StreamLogWriter

public StreamLogWriter(java.io.PrintWriter pw,
                       boolean own)
Create a new StreamLogWriter that uses a DefaultLogFormat to print LogEntries to a writer.
Parameters:
pw - The writer to print to.
own - Whether the writer is owned by the StreamLogWriter and should be closed when the StreamLogWriter is closed.

StreamLogWriter

public StreamLogWriter(java.io.PrintWriter pw,
                       boolean own,
                       LogFormat format)
Create a new StreamLogWriter that prints LogEntries to a writer.
Parameters:
pw - The writer to print to.
own - Whether the writer is owned by the StreamLogWriter and should be closed when the StreamLogWriter is closed.
format - The format used to print LogEntries.
Method Detail

write

public void write(LogEntry entry)
Write one LogEntry.
Specified by:
write in interface LogWriter
Parameters:
entry - The entry to write.

write

public void write(LogEntry[] entries)
Write an array of LogEntires in one go. Clients of the StreamLogWriter should use this method in preference to write(LogEntry), since it is more efficient.
Specified by:
write in interface LogWriter
Parameters:
entries - The entries to write.

close

public void close()
Close the StreamLogWriter. Closes the stream or writer used if it is owned by the StreamLogWriter.
Specified by:
close in interface LogWriter

getFormat

public final LogFormat getFormat()
Get the format the StreamLogWriter uses to print LogEntries.
Specified by:
getFormat in interface LogWriter
Returns:
The format of the StreamLogWriter.

setFormat

public final void setFormat(LogFormat format)
Set the format to use for printing LogEntries.
Specified by:
setFormat in interface LogWriter
Parameters:
format - The format to set.

qflib 0.98.0