Package com.iizix
Class LogStreamRedirector
java.lang.Object
com.iizix.LogStreamRedirector
Input stream redirector class to the IIZI log. It is typically used to redirect the output of an external process to the log.
- Author:
- Christopher Mindus
Constructor Summary
ConstructorDescriptionLogStreamRedirector
(int level, String originator, InputStream inputStream) Creates a stream reader redirector to the IIZI log, running in a separate thread.LogStreamRedirector
(int level, String originator, String prefix, InputStream inputStream) Creates a stream reader redirector to the IIZI log, running in a separate thread.Method Summary
Modifier and TypeMethodDescriptionvoid
close()
Closes the stream reader redirector without completing potential pending unprocessed input in the stream.boolean
Waits indefinitely for the stream reader to complete all input reading by waiting for the input stream to be closed, then disposes of this instance.boolean
closeWait
(long timeout) Waits for the stream reader to complete all input reading by waiting for the input stream to be closed, then disposes of this instance.static void
createStreamReadirector
(int level, String originator, Process process) Helper to create a stdout stream reader redirecting to the log when the process stderr has been redirected to stdout.static void
createStreamReadirectors
(String originator, Process process) Helper to create stdout and stderr stream readers redirecting to the log.boolean
isClosed()
Checks whether this stream reader instance is disposed of or not.static boolean
shouldIgnore
(int level, String msg) Checks if a log message should be ignored or not, typically SEVERE level messages for different ANTLR versions used at runtime or parser, thus omitting "worrying" SEVERE ANTLR version mismatch when "not dangerous".
Constructor Details
LogStreamRedirector
Creates a stream reader redirector to the IIZI log, running in a separate thread.- Parameters:
level
- Log level (1-7), e.g.ILog.INFO
orILog.SEVERE
.originator
- The originator.inputStream
- The input stream.
LogStreamRedirector
Creates a stream reader redirector to the IIZI log, running in a separate thread.- Parameters:
level
- Log level (1-7), e.g.ILog.INFO
orILog.SEVERE
.originator
- The originator.prefix
- Prefix for each line,null
or empty string for none.inputStream
- The input stream.
Method Details
shouldIgnore
Checks if a log message should be ignored or not, typically SEVERE level messages for different ANTLR versions used at runtime or parser, thus omitting "worrying" SEVERE ANTLR version mismatch when "not dangerous".- Parameters:
level
- The log level.msg
- The message.- Returns:
true
if themsg
is a message likeANTLR Tool version 4.10.1 used for code generation does not match the current runtime version 4.11.1
orANTLR Runtime version 4.10.1 used for parser compilation does not match the current runtime version 4.11.1
.
createStreamReadirector
Helper to create a stdout stream reader redirecting to the log when the process stderr has been redirected to stdout.- Parameters:
level
- The log level.originator
- The originator.process
- The process.
createStreamReadirectors
Helper to create stdout and stderr stream readers redirecting to the log.- Parameters:
originator
- The originator.process
- The process.
closeWait
Waits indefinitely for the stream reader to complete all input reading by waiting for the input stream to be closed, then disposes of this instance.- Returns:
- Success flag.
- Throws:
InterruptedException
- In case the waiting was interrupted.
closeWait
Waits for the stream reader to complete all input reading by waiting for the input stream to be closed, then disposes of this instance.- Parameters:
timeout
- The timeout to wait for the thread,-1L
for indefinite wait.- Returns:
- Success flag.
- Throws:
InterruptedException
- In case the waiting was interrupted.
isClosed
public boolean isClosed()Checks whether this stream reader instance is disposed of or not.- Returns:
- The dispose state.
close
public void close()Closes the stream reader redirector without completing potential pending unprocessed input in the stream.