Class LogOutputStream
java.lang.Object
java.io.OutputStream
java.io.ByteArrayOutputStream
eu.cloudnetservice.utils.base.io.LogOutputStream
- All Implemented Interfaces:
Closeable, Flushable, AutoCloseable
A special implementation of an output stream specifically made to log all the written content to it to a provided
logger instance.
- Since:
- 4.0
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final booleanstatic final Charsetprivate final Lockprivate final org.slf4j.event.Levelprivate final org.slf4j.LoggerFields inherited from class ByteArrayOutputStream
buf, count -
Constructor Summary
ConstructorsModifierConstructorDescriptionprivateLogOutputStream(@NonNull org.slf4j.event.Level level, @NonNull org.slf4j.Logger logger) Creates a new log output stream instance. -
Method Summary
Modifier and TypeMethodDescriptionvoidflush()static @NonNull LogOutputStreamCreates a new log output stream instance logging all messages to the given logger with the info log level.static @NonNull LogOutputStreamCreates a new log output stream instance logging all messages to the given logger with the severe log level.static @NonNull LogOutputStreamnewInstance(@NonNull org.slf4j.Logger logger, @NonNull org.slf4j.event.Level level) Creates a new log output stream instance logging all messages to the given logger using the given log level.Wraps this log output stream into a print stream which automatically flushes and uses the UTF-8 charset encoding.toPrintStream(boolean autoFlush, @NonNull Charset charset) Wraps this log output stream in a print stream using the given auto flush and charset settings.Methods inherited from class ByteArrayOutputStream
close, reset, size, toByteArray, toString, toString, toString, toString, write, write, writeBytes, writeToMethods inherited from class OutputStream
nullOutputStream, write
-
Field Details
-
DEFAULT_AUTO_FLUSH
public static final boolean DEFAULT_AUTO_FLUSH- See Also:
-
DEFAULT_CHARSET
-
level
private final org.slf4j.event.Level level -
logger
private final org.slf4j.Logger logger -
flushLock
-
-
Constructor Details
-
LogOutputStream
private LogOutputStream(@NonNull @NonNull org.slf4j.event.Level level, @NonNull @NonNull org.slf4j.Logger logger) Creates a new log output stream instance.- Parameters:
level- the level which should be used when logging messages.logger- the logger to which all messages should get logged.- Throws:
NullPointerException- if the given level or logger is null.
-
-
Method Details
-
forWarn
Creates a new log output stream instance logging all messages to the given logger with the severe log level.- Parameters:
logger- the logger to log all messages to.- Returns:
- a new log output stream instance for the given logger.
- Throws:
NullPointerException- if the given logger is null.
-
forInfo
Creates a new log output stream instance logging all messages to the given logger with the info log level.- Parameters:
logger- the logger to log all messages to.- Returns:
- a new log output stream instance for the given logger.
- Throws:
NullPointerException- if the given logger is null.
-
newInstance
@NonNull public static @NonNull LogOutputStream newInstance(@NonNull @NonNull org.slf4j.Logger logger, @NonNull @NonNull org.slf4j.event.Level level) Creates a new log output stream instance logging all messages to the given logger using the given log level.- Parameters:
logger- the logger to log all messages to.level- the level which the messages should have when logging them.- Returns:
- a new log output stream instance for the given logger and level.
- Throws:
NullPointerException- if the given logger or level is null.
-
toPrintStream
Wraps this log output stream into a print stream which automatically flushes and uses the UTF-8 charset encoding.- Returns:
- a print stream wrapping this logging output stream.
-
toPrintStream
@NonNull public @NonNull PrintStream toPrintStream(boolean autoFlush, @NonNull @NonNull Charset charset) Wraps this log output stream in a print stream using the given auto flush and charset settings.- Parameters:
autoFlush- if this buffer should be flushed automatically if content was written to the print stream.charset- the charset to use when flushing out buffer content.- Returns:
- a print stream wrapping this output stream.
- Throws:
NullPointerException- if the given charset is null.
-
flush
- Specified by:
flushin interfaceFlushable- Overrides:
flushin classOutputStream- Throws:
IOException
-