|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||
java.lang.Objecttuwien.auto.calimero.log.LogWriter
tuwien.auto.calimero.log.LogStreamWriter
public class LogStreamWriter
LogWriter using a Writer for output.
An existing output stream has to be supplied on creation of this LogWriter. All output
will be checked against the internal log level, on logging permitted the output is
formatted (optional) and handed to the underlying writer.
Output is not automatically flushed after each write by default.
Using autoFlush = true in the constructor ensures that no data buffering
will delay the output. Note that this may degrade performance.
For occasional flushing use flush() manually.
| Field Summary | |
|---|---|
protected static java.util.Calendar |
c
Calendar used to generate date/time of logged output message. |
protected boolean |
formatOutput
Set the formatting behavior of LogStreamWriter. |
protected java.lang.String |
lineSep
Line separator, retrieved from the property "line.separator" and set in the constructor. |
| Constructor Summary | |
|---|---|
protected |
LogStreamWriter()
Sets line separator; also called by subtypes creating the output stream on their own. |
|
LogStreamWriter(LogLevel level,
java.io.OutputStream os)
Creates a LogStreamWriter with specified log level and output
stream. |
|
LogStreamWriter(LogLevel level,
java.io.OutputStream os,
boolean autoFlush)
Creates a LogStreamWriter with specified log level and output
stream. |
|
LogStreamWriter(java.io.OutputStream os)
Creates a LogStreamWriter with specified output stream. |
| Method Summary | |
|---|---|
void |
close()
Closes the LogWriter and all its resources. |
void |
flush()
Flushes all buffered output. |
protected java.lang.String |
formatOutput(java.lang.String svc,
LogLevel l,
java.lang.String msg,
java.lang.Throwable t)
Creates a formatted output string from the input parameters. |
protected boolean |
logAllowed(LogLevel level)
Checks if logging output with log level is possible and would get
accepted by this LogStreamWriter. |
protected void |
setOutput(java.io.Writer w)
Sets the underlying writer to use for logging output. |
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.LogWriter |
|---|
getErrorHandler, getLogLevel, setErrorHandler, setLogLevel |
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Field Detail |
|---|
protected static final java.util.Calendar c
protected boolean formatOutput
LogStreamWriter.
Determines if LogStreamWriter should call
formatOutput(LogLevel,
String, Throwable) before writing out the log message. Defaults to
true, but might be set to false by subtypes if
message given to write is already formatted.
protected java.lang.String lineSep
| Constructor Detail |
|---|
protected LogStreamWriter()
public LogStreamWriter(LogLevel level,
java.io.OutputStream os)
LogStreamWriter with specified log level and output
stream.
level - log level assigned with this LogStreamWriteros - an OutputStream used by this LogStreamWriterLogStreamWriter(OutputStream)
public LogStreamWriter(LogLevel level,
java.io.OutputStream os,
boolean autoFlush)
LogStreamWriter with specified log level and output
stream. Parameter autoFlush sets flushing behavior on write() calls.
level - log level assigned with this LogStreamWriteros - an OutputStream used by this LogStreamWriterautoFlush - flush output after every successful call to write()LogStreamWriter(LogLevel, OutputStream)public LogStreamWriter(java.io.OutputStream os)
LogStreamWriter with specified output stream.
The output stream is wrapped by a BufferedWriter.
os - an OutputStream used by this LogStreamWriter| Method Detail |
|---|
public void close()
LogWriterIf necessary, all output is flushes before.
close in class LogWriterpublic void flush()
LogWriter
flush in class LogWriter
protected java.lang.String formatOutput(java.lang.String svc,
LogLevel l,
java.lang.String msg,
java.lang.Throwable t)
Override this method to provide a different output format.
The output returned by default follows the shown format. The date/time format is
according ISO 8601 representation, extended format with decimal fraction of second
(milliseconds):
"YYYY-MM-DD hh:mm:ss,sss level=level.toString(),
logService: msg (t.getMessage())"
or, if throwable is null or throwable-message is null
"YYYY-MM-DD hh:mm:ss,sss logService, LogLevel=level.toString():
msg".
If logService contains '.' in the name, only the part after the last
'.' will be used. This way names like "package.subpackage.name" are shortened to
"name". Nevertheless, if the first character after '.' is numeric, no truncation
will be done to allow e.g. IP addresses in the log service name.
svc - name of the log service the message comes froml - log level of message and throwablemsg - message to formatt - an optional throwable object to format, might be null
protected boolean logAllowed(LogLevel level)
level is possible and would get
accepted by this LogStreamWriter.
Therefore this method also checks that the underlying output stream is opened.
level - log level to check against
protected final void setOutput(java.io.Writer w)
The log stream writer obtains ownership of the writer object.
w - the Writer
public void write(java.lang.String logService,
LogLevel level,
java.lang.String msg)
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.
write in class LogWriterlogService - log service name stating the source of the messagelevel - log level of messagemsg - the message to write
public void write(java.lang.String logService,
LogLevel level,
java.lang.String msg,
java.lang.Throwable t)
LogWriterLogWriter.write(String, LogLevel, String), in addition a
Throwable object is taken which will be added to the message.
write in class LogWriterlogService - log service name stating the source of the messagelevel - log level of messagemsg - the message to writet - Throwable object, might be null
|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||