Package emissary.util.io
Class LoggingPrintStream
- java.lang.Object
-
- java.io.OutputStream
-
- java.io.FilterOutputStream
-
- java.io.PrintStream
-
- emissary.util.io.LoggingPrintStream
-
- All Implemented Interfaces:
Closeable
,Flushable
,Appendable
,AutoCloseable
public class LoggingPrintStream extends PrintStream
This class is designed to be put in place of StdOut and StdErr in order to log anything that is sent there.
-
-
Field Summary
Fields Modifier and Type Field Description static String
LOG_SUBSTITUTION
The log string used to identify substitutions.static String
NORMAL_LOG_FORMAT
The log format used for "normal" messages.static String
NORMAL_SEPARATOR
The string used to separate the stream name from the message for "normal" messages.static String
THROWABLE_LOG_FORMAT
The log format used for "throwable" messages.static String
THROWABLE_PREFIX
The prefix used for "throwable" messages.-
Fields inherited from class java.io.FilterOutputStream
out
-
-
Constructor Summary
Constructors Constructor Description LoggingPrintStream(OutputStream outputStream, String streamName, org.slf4j.Logger logger, org.slf4j.event.Level level, long closeWaitTime, TimeUnit closeWaitTimeUnit)
Constructs a custom PrintStream that logs anything it receives.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
close()
Closes the stream.void
print(String string)
Prints a string.void
println(Object object)
Prints an Object and then terminate the line.-
Methods inherited from class java.io.PrintStream
append, append, append, checkError, clearError, flush, format, format, print, print, print, print, print, print, print, print, printf, printf, println, println, println, println, println, println, println, println, println, setError, write, write
-
Methods inherited from class java.io.FilterOutputStream
write
-
Methods inherited from class java.io.OutputStream
nullOutputStream
-
-
-
-
Field Detail
-
THROWABLE_PREFIX
public static final String THROWABLE_PREFIX
The prefix used for "throwable" messages.- See Also:
- Constant Field Values
-
NORMAL_SEPARATOR
public static final String NORMAL_SEPARATOR
The string used to separate the stream name from the message for "normal" messages.- See Also:
- Constant Field Values
-
LOG_SUBSTITUTION
public static final String LOG_SUBSTITUTION
The log string used to identify substitutions.- See Also:
- Constant Field Values
-
THROWABLE_LOG_FORMAT
public static final String THROWABLE_LOG_FORMAT
The log format used for "throwable" messages.- See Also:
- Constant Field Values
-
NORMAL_LOG_FORMAT
public static final String NORMAL_LOG_FORMAT
The log format used for "normal" messages.- See Also:
- Constant Field Values
-
-
Constructor Detail
-
LoggingPrintStream
public LoggingPrintStream(OutputStream outputStream, String streamName, org.slf4j.Logger logger, org.slf4j.event.Level level, long closeWaitTime, TimeUnit closeWaitTimeUnit)
Constructs a custom PrintStream that logs anything it receives.- Parameters:
outputStream
- where the received data is to be written.streamName
- the name of the outputStream to be included in the log messages.logger
- that is to be used to log the messages.level
- the logging level to use for log statements.closeWaitTime
- the time to wait for logging tasks to finish when closing.closeWaitTimeUnit
- the time unit to use for the closeWaitTime.
-
-
Method Detail
-
print
public void print(String string)
Prints a string. If the argument isnull
then the string"null"
is printed. Otherwise, the string's characters are converted into bytes according to the character encoding given to the constructor, or the platform's default character encoding if none specified. These bytes are written in exactly the manner of thePrintStream.write(int)
method.- Overrides:
print
in classPrintStream
- Parameters:
string
- TheString
to be printed
-
println
public void println(Object object)
Prints an Object and then terminate the line. This method calls at first String.valueOf(x) to get the printed object's string value, then behaves as though it invokesprint(String)
and thenPrintStream.println()
.- Overrides:
println
in classPrintStream
- Parameters:
object
- TheObject
to be printed.
-
close
public void close()
Closes the stream. This is done by flushing the stream and then closing the underlying output stream.- Specified by:
close
in interfaceAutoCloseable
- Specified by:
close
in interfaceCloseable
- Overrides:
close
in classPrintStream
- See Also:
OutputStream.close()
-
-