public class LoggingOutputStream extends OutputStream
Note that no data is written out to the Category until the stream is flushed or closed.
Example:
// make sure everything sent to System.err is logged System.setErr(new PrintStream(new LoggingOutputStream(Logger.getRootCategory(), Level.WARN), true)); // make sure everything sent to System.out is also logged System.setOut(new PrintStream(new LoggingOutputStream(Logger.getRootCategory(), Level.INFO), true));
{{http://www.mail-archive.com/user@slf4j.org/msg00674.html}}| Modifier and Type | Field and Description |
|---|---|
static int |
DEFAULT_BUFFER_LENGTH
The default number of bytes in the buffer.
|
| Constructor and Description |
|---|
LoggingOutputStream(org.slf4j.Logger log)
Creates the LoggingOutputStream to flush to the given Category.
|
| Modifier and Type | Method and Description |
|---|---|
void |
close()
Closes this output stream and releases any system resources
associated with this stream.
|
void |
flush()
Flushes this output stream and forces any buffered output bytes
to be written out.
|
void |
write(int b)
Writes the specified byte to this output stream.
|
write, writepublic static final int DEFAULT_BUFFER_LENGTH
public LoggingOutputStream(org.slf4j.Logger log)
throws IllegalArgumentException
log - the Logger to write toIllegalArgumentException - if log == nullpublic void close()
close
is that it closes the output stream. A closed stream cannot
perform
output operations and cannot be reopened.close in interface Closeableclose in interface AutoCloseableclose in class OutputStreampublic void write(int b)
throws IOException
write is that one byte is written
to the output stream. The byte to be written is the eight
low-order bits of the argument b. The 24
high-order bits of b are ignored.write in class OutputStreamb - the byte to writeIOException - if an I/O error occurs. In particular, an
IOException may be
thrown if the output stream has been closed.public void flush()
flush is
that calling it is an indication that, if any bytes previously
written have been buffered by the implementation of the output
stream, such bytes should immediately be written to their
intended destination.flush in interface Flushableflush in class OutputStreamCopyright © 2010-2014. All Rights Reserved.