public class WriterLogger extends Object implements LogListener
Writer
.
This class defines a LogListener
that logs its messages to a character stream
Writer
. This formats and writes to the output stream all log events passed to
LogListener.messageLogged(org.apache.oodt.commons.io.LogEvent)
, one per line. Each line is separated with the
system's line separator characters, specified by the line.separator
system
property.
It ignores all events passed to LogListener.streamStarted(org.apache.oodt.commons.io.LogEvent)
and
LogListener.streamStopped(org.apache.oodt.commons.io.LogEvent)
.
It quietly hides all IO errors that may occur during writing.
Log
Modifier and Type | Field and Description |
---|---|
protected boolean |
autoFlush
If true, flush after every message logged.
|
protected String |
lineSep
What the line separator is.
|
protected Writer |
writer
The writer to which we write log messages.
|
Constructor and Description |
---|
WriterLogger(OutputStream outputStream)
Constructor given an output stream.
|
WriterLogger(Writer writer)
Constructor given a writer.
|
WriterLogger(Writer writer,
boolean autoFlush)
General constructor.
|
Modifier and Type | Method and Description |
---|---|
void |
close()
Close the writer.
|
protected String |
formatMessage(Date timestamp,
String source,
Object category,
String message)
Format a message for logging.
|
void |
messageLogged(LogEvent event)
Log a message to the writer.
|
void |
propertyChange(PropertyChangeEvent ignore) |
void |
streamStarted(LogEvent event)
Ignore the stream started event.
|
void |
streamStopped(LogEvent event)
Ignore the stream stopped event.
|
protected Writer writer
protected boolean autoFlush
protected String lineSep
public WriterLogger(OutputStream outputStream)
outputStream
- The output stream to which to write events.public WriterLogger(Writer writer)
writer
- The writer to which to write events.public WriterLogger(Writer writer, boolean autoFlush)
writer
- The writer to which to write events.autoFlush
- If true, call flush on the writer after every message
logged. If false, don't call flush.public final void close()
public final void messageLogged(LogEvent event)
formatMessage(java.util.Date, java.lang.String, java.lang.Object, java.lang.String)
to format the message, and then
writes the message to the output stream.messageLogged
in interface LogListener
event
- The event describing the message that was logged.protected String formatMessage(Date timestamp, String source, Object category, String message)
where epochTime is the time in milliseconds since midnight, 1st
January 1970 GMT, time is human-readable time, source is
the source of the message, category is the category under which the
message was logged, and message is the message.
You can override this method and provide your own formatting.epochTime (time) source category:
message
timestamp
- Timestamp for the message.source
- Source of the message.category
- Category of the message.message
- The message text.public void streamStarted(LogEvent event)
streamStarted
in interface LogListener
event
- The event to ignore.public void streamStopped(LogEvent event)
streamStopped
in interface LogListener
event
- The event to ignore.public void propertyChange(PropertyChangeEvent ignore)
propertyChange
in interface PropertyChangeListener
Copyright © 1999–2017 Apache OODT. All rights reserved.