Package org.terracotta.utilities.logging
Class LoggingOutputStream
- java.lang.Object
-
- java.io.OutputStream
-
- org.terracotta.utilities.logging.LoggingOutputStream
-
- All Implemented Interfaces:
java.io.Closeable,java.io.Flushable,java.lang.AutoCloseable
public class LoggingOutputStream extends java.io.OutputStreamImplements anOutputStreamthat forwards lines written to it to aLoggerat a specified level. Bytes are accumulated by thisOutputStreamuntil aSystem.lineSeparator()value is found; once the line ending is found, the line is flushed to the logger.Bytes written to a
LoggingOutputStreaminstance must have been encoded usingUTF-8. This affects proper recognition of line separators and re-assembly of logged strings.
-
-
Field Summary
Fields Modifier and Type Field Description private byte[]bufferprivate intbufferSizeprivate intbyteCountprivate booleanclosedstatic intDEFAULT_BUFFER_SIZEprivate byteeolprivate byteeolLeaderprivate java.lang.invoke.MethodHandlehandleprivate booleanhaveLeaderprivate static java.util.Map<org.slf4j.event.Level,java.lang.invoke.MethodHandle>LOG_METHODSprivate static org.slf4j.LoggerLOGGERprivate booleantwoByteLineSeparator
-
Constructor Summary
Constructors Constructor Description LoggingOutputStream(org.slf4j.Logger logger, org.slf4j.event.Level level)Creates a newLoggingOutputStreamwriting to the provided logger and the specified level.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description private voidappendByte(byte b)private voidcheckOpen()voidclose()voidflush()private voidflushInternal()private static java.lang.invoke.MethodHandlegetHandle(org.slf4j.event.Level level)private voidlog(java.lang.String line)voidwrite(int b)
-
-
-
Field Detail
-
LOGGER
private static final org.slf4j.Logger LOGGER
-
DEFAULT_BUFFER_SIZE
public static final int DEFAULT_BUFFER_SIZE
- See Also:
- Constant Field Values
-
LOG_METHODS
private static final java.util.Map<org.slf4j.event.Level,java.lang.invoke.MethodHandle> LOG_METHODS
-
handle
private final java.lang.invoke.MethodHandle handle
-
twoByteLineSeparator
private final boolean twoByteLineSeparator
-
eol
private final byte eol
-
eolLeader
private final byte eolLeader
-
closed
private volatile boolean closed
-
buffer
private byte[] buffer
-
bufferSize
private int bufferSize
-
byteCount
private int byteCount
-
haveLeader
private boolean haveLeader
-
-
Constructor Detail
-
LoggingOutputStream
public LoggingOutputStream(org.slf4j.Logger logger, org.slf4j.event.Level level)Creates a newLoggingOutputStreamwriting to the provided logger and the specified level.Bytes written to this
LoggingOutputStreammust be UTF-8 encoded characters.- Parameters:
logger- the SLF4JLoggerinstance to which the stream should writelevel- the SLF4J level at which the stream is recorded tologger
-
-
Method Detail
-
write
public void write(int b) throws java.io.IOException- Specified by:
writein classjava.io.OutputStream- Throws:
java.io.IOException
-
flush
public void flush() throws java.io.IOException- Specified by:
flushin interfacejava.io.Flushable- Overrides:
flushin classjava.io.OutputStream- Throws:
java.io.IOException
-
close
public void close() throws java.io.IOException- Specified by:
closein interfacejava.lang.AutoCloseable- Specified by:
closein interfacejava.io.Closeable- Overrides:
closein classjava.io.OutputStream- Throws:
java.io.IOException
-
flushInternal
private void flushInternal() throws java.io.IOException- Throws:
java.io.IOException
-
log
private void log(java.lang.String line) throws java.io.IOException- Throws:
java.io.IOException
-
appendByte
private void appendByte(byte b)
-
checkOpen
private void checkOpen() throws java.io.IOException- Throws:
java.io.IOException
-
getHandle
private static java.lang.invoke.MethodHandle getHandle(org.slf4j.event.Level level)
-
-