Package com.iizix

Class LogStreamRedirector

java.lang.Object
com.iizix.LogStreamRedirector

public class LogStreamRedirector extends Object
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

    Constructors
    Constructor
    Description
    LogStreamRedirector(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 Type
    Method
    Description
    void
    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
    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".

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Constructor Details

    • LogStreamRedirector

      public LogStreamRedirector(int level, String originator, InputStream inputStream)
      Creates a stream reader redirector to the IIZI log, running in a separate thread.
      Parameters:
      level - Log level (1-7), e.g. ILog.INFO or ILog.SEVERE.
      originator - The originator.
      inputStream - The input stream.
    • LogStreamRedirector

      public LogStreamRedirector(int level, String originator, String prefix, InputStream inputStream)
      Creates a stream reader redirector to the IIZI log, running in a separate thread.
      Parameters:
      level - Log level (1-7), e.g. ILog.INFO or ILog.SEVERE.
      originator - The originator.
      prefix - Prefix for each line, null or empty string for none.
      inputStream - The input stream.
  • Method Details

    • shouldIgnore

      public 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".
      Parameters:
      level - The log level.
      msg - The message.
      Returns:
      true if the msg is a message like ANTLR Tool version 4.10.1 used for code generation does not match the current runtime version 4.11.1 or ANTLR Runtime version 4.10.1 used for parser compilation does not match the current runtime version 4.11.1.
    • createStreamReadirector

      public 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.
      Parameters:
      level - The log level.
      originator - The originator.
      process - The process.
    • createStreamReadirectors

      public static void createStreamReadirectors(String originator, Process process)
      Helper to create stdout and stderr stream readers redirecting to the log.
      Parameters:
      originator - The originator.
      process - The process.
    • closeWait

      public boolean closeWait() throws InterruptedException
      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

      public boolean closeWait(long timeout) throws InterruptedException
      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.