Package org.terracotta.utilities.logging
Class LoggingOutputStream
java.lang.Object
java.io.OutputStream
org.terracotta.utilities.logging.LoggingOutputStream
- All Implemented Interfaces:
Closeable,Flushable,AutoCloseable
Implements an
OutputStream that forwards lines written to it to
a Logger at a specified level. Bytes are accumulated by this
OutputStream until a System.lineSeparator() value is found;
once the line ending is found, the line is flushed to the logger.
Bytes written to a LoggingOutputStream instance must have been
encoded using UTF-8. This affects proper
recognition of line separators and re-assembly of logged strings.
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate byte[]private intprivate intprivate booleanstatic final intprivate final byteprivate final byteprivate final MethodHandleprivate booleanprivate static final Map<org.slf4j.event.Level,MethodHandle> private static final org.slf4j.Loggerprivate final boolean -
Constructor Summary
ConstructorsConstructorDescriptionLoggingOutputStream(org.slf4j.Logger logger, org.slf4j.event.Level level) Creates a newLoggingOutputStreamwriting to the provided logger and the specified level. -
Method Summary
Modifier and TypeMethodDescriptionprivate voidappendByte(byte b) private voidvoidclose()voidflush()private voidprivate static MethodHandlegetHandle(org.slf4j.event.Level level) private voidvoidwrite(int b) Methods inherited from class java.io.OutputStream
nullOutputStream, write, write
-
Field Details
-
LOGGER
private static final org.slf4j.Logger LOGGER -
DEFAULT_BUFFER_SIZE
public static final int DEFAULT_BUFFER_SIZE- See Also:
-
LOG_METHODS
-
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 Details
-
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 Details
-
write
- Specified by:
writein classOutputStream- Throws:
IOException
-
flush
- Specified by:
flushin interfaceFlushable- Overrides:
flushin classOutputStream- Throws:
IOException
-
close
- Specified by:
closein interfaceAutoCloseable- Specified by:
closein interfaceCloseable- Overrides:
closein classOutputStream- Throws:
IOException
-
flushInternal
- Throws:
IOException
-
log
- Throws:
IOException
-
appendByte
private void appendByte(byte b) -
checkOpen
- Throws:
IOException
-
getHandle
-