Package com.adaptris.util.stream
Class Slf4jLoggingOutputStream
- java.lang.Object
-
- java.io.OutputStream
-
- com.adaptris.util.stream.Slf4jLoggingOutputStream
-
- All Implemented Interfaces:
java.io.Closeable
,java.io.Flushable
,java.lang.AutoCloseable
public class Slf4jLoggingOutputStream extends java.io.OutputStream
An OutputStream that flushes out to a slf4j logger.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(LogHandler.WARN)); // make sure everything sent to System.out is also logged System.setOut(new PrintStream(new LoggingOutputStream(LogHandler.INFO));
-
-
Field Summary
Fields Modifier and Type Field Description static int
DEFAULT_BUFFER_LENGTH
The default number of bytes in the buffer.protected com.adaptris.util.stream.LoggingOutputStreamImpl.LogLevel
logLevel
-
Constructor Summary
Constructors Constructor Description Slf4jLoggingOutputStream(com.adaptris.util.stream.LoggingOutputStreamImpl.LogLevel level)
Slf4jLoggingOutputStream(java.lang.String level)
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.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method 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.
-
-
-
Field Detail
-
DEFAULT_BUFFER_LENGTH
public static final int DEFAULT_BUFFER_LENGTH
The default number of bytes in the buffer. =2048- See Also:
- Constant Field Values
-
logLevel
protected transient com.adaptris.util.stream.LoggingOutputStreamImpl.LogLevel logLevel
-
-
Constructor Detail
-
Slf4jLoggingOutputStream
public Slf4jLoggingOutputStream(com.adaptris.util.stream.LoggingOutputStreamImpl.LogLevel level)
-
Slf4jLoggingOutputStream
public Slf4jLoggingOutputStream(java.lang.String level)
-
Slf4jLoggingOutputStream
public Slf4jLoggingOutputStream(org.slf4j.Logger log, com.adaptris.util.stream.LoggingOutputStreamImpl.LogLevel level) throws java.lang.IllegalArgumentException
Creates the LoggingOutputStream to flush to the given LogLevel.- Parameters:
log
- the Logger to write tolevel
- the Level to use when writing to the Logger- Throws:
java.lang.IllegalArgumentException
- if log == null or level == null
-
Slf4jLoggingOutputStream
public Slf4jLoggingOutputStream(org.slf4j.Logger log, java.lang.String level) throws java.lang.IllegalArgumentException
Creates the LoggingOutputStream to flush to the given LogLevel.- Parameters:
log
- the Logger to write tolevel
- the Level to use when writing to the Logger- Throws:
java.lang.IllegalArgumentException
- if log == null or level == null
-
-
Method Detail
-
log
protected void log(com.adaptris.util.stream.LoggingOutputStreamImpl.LogLevel level, java.lang.String s)
-
close
public void close()
Closes this output stream and releases any system resources associated with this stream. The general contract ofclose
is that it closes the output stream. A closed stream cannot perform output operations and cannot be reopened.- Specified by:
close
in interfacejava.lang.AutoCloseable
- Specified by:
close
in interfacejava.io.Closeable
- Overrides:
close
in classjava.io.OutputStream
-
write
public void write(int b) throws java.io.IOException
Writes the specified byte to this output stream. The general contract forwrite
is that one byte is written to the output stream. The byte to be written is the eight low-order bits of the argumentb
. The 24 high-order bits ofb
are ignored.- Specified by:
write
in classjava.io.OutputStream
- Parameters:
b
- thebyte
to write- Throws:
java.io.IOException
- if an I/O error occurs. In particular, anIOException
may be thrown if the output stream has been closed.
-
flush
public void flush()
Flushes this output stream and forces any buffered output bytes to be written out. The general contract offlush
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.- Specified by:
flush
in interfacejava.io.Flushable
- Overrides:
flush
in classjava.io.OutputStream
-
reset
protected void reset()
-
-