public class Slf4jLoggingOutputStream
extends java.io.OutputStream
Note that no data is written out to the Category until the stream is flushed or closed.
// make sure everything sent to System.err is logged
System.setErr(new PrintStream(new LoggingOutputStream(LogHandler.WARN));
// make sure everything sent to System.out is also logged
System.setOut(new PrintStream(new LoggingOutputStream(LogHandler.INFO));
Modifier and Type | Class and Description |
---|---|
static class |
com.adaptris.util.stream.LoggingOutputStreamImpl.LogLevel |
Modifier and Type | Field and Description |
---|---|
static int |
DEFAULT_BUFFER_LENGTH
The default number of bytes in the buffer.
|
protected com.adaptris.util.stream.LoggingOutputStreamImpl.LogLevel |
logLevel |
Constructor and Description |
---|
Slf4jLoggingOutputStream(org.slf4j.Logger log,
com.adaptris.util.stream.LoggingOutputStreamImpl.LogLevel level)
Creates the LoggingOutputStream to flush to the given LogLevel.
|
Slf4jLoggingOutputStream(org.slf4j.Logger log,
java.lang.String level)
Creates the LoggingOutputStream to flush to the given LogLevel.
|
Slf4jLoggingOutputStream(com.adaptris.util.stream.LoggingOutputStreamImpl.LogLevel level) |
Slf4jLoggingOutputStream(java.lang.String level) |
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.
|
protected void |
log(com.adaptris.util.stream.LoggingOutputStreamImpl.LogLevel level,
java.lang.String s) |
protected void |
reset() |
void |
write(int b)
Writes the specified byte to this output stream.
|
public static final int DEFAULT_BUFFER_LENGTH
protected transient com.adaptris.util.stream.LoggingOutputStreamImpl.LogLevel logLevel
public Slf4jLoggingOutputStream(com.adaptris.util.stream.LoggingOutputStreamImpl.LogLevel level)
public Slf4jLoggingOutputStream(java.lang.String level)
public Slf4jLoggingOutputStream(org.slf4j.Logger log, com.adaptris.util.stream.LoggingOutputStreamImpl.LogLevel level) throws java.lang.IllegalArgumentException
log
- the Logger to write tolevel
- the Level to use when writing to the Loggerjava.lang.IllegalArgumentException
- if log == null or level == nullpublic Slf4jLoggingOutputStream(org.slf4j.Logger log, java.lang.String level) throws java.lang.IllegalArgumentException
log
- the Logger to write tolevel
- the Level to use when writing to the Loggerjava.lang.IllegalArgumentException
- if log == null or level == nullprotected void log(com.adaptris.util.stream.LoggingOutputStreamImpl.LogLevel level, java.lang.String s)
public void close()
close
is that it closes
the output stream. A closed stream cannot perform output operations and
cannot be reopened.close
in interface java.io.Closeable
close
in interface java.lang.AutoCloseable
close
in class java.io.OutputStream
public void write(int b) throws java.io.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 java.io.OutputStream
b
- the byte
to writejava.io.IOException
- 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 java.io.Flushable
flush
in class java.io.OutputStream
protected void reset()