Package eu.cloudnetservice.common.log.io
Class LogOutputStream
java.lang.Object
java.io.OutputStream
java.io.ByteArrayOutputStream
eu.cloudnetservice.common.log.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 Levelprivate final LoggerFields inherited from class java.io.ByteArrayOutputStream
buf, count -
Constructor Summary
ConstructorsModifierConstructorDescriptionprivateLogOutputStream(@NonNull Level level, @NonNull Logger logger) Creates a new log output stream instance. -
Method Summary
Modifier and TypeMethodDescriptionvoidflush()static @NonNull LogOutputStreamforInformative(@NonNull Logger logger) Creates 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 Logger logger, @NonNull 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 java.io.ByteArrayOutputStream
close, reset, size, toByteArray, toString, toString, toString, toString, write, write, writeBytes, writeToMethods inherited from class java.io.OutputStream
nullOutputStream, write
-
Field Details
-
DEFAULT_AUTO_FLUSH
public static final boolean DEFAULT_AUTO_FLUSH- See Also:
-
DEFAULT_CHARSET
-
level
-
logger
-
flushLock
-
-
Constructor Details
-
LogOutputStream
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
-
forSevere
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.
-
forInformative
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 Logger logger, @NonNull @NonNull 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
-