Class Logging.ReacquiringConsoleHandler

  • Enclosing class:
    Logging

    public static class Logging.ReacquiringConsoleHandler
    extends java.util.logging.ConsoleHandler
    A ConsoleHandler with a couple of extra features, allowing it to be targeted at an an arbitrary OutputStream which it can be asked to reacquire the reference for on demand through reacquireOutputStream(). It can also prevent a LogRecord's output if a specified prioritizedHandler would have outputted it.
    Since:
    14052
    • Field Summary

      Fields 
      Modifier and Type Field Description
      private java.io.OutputStream outputStreamMemo  
      private java.util.function.Supplier<java.io.OutputStream> outputStreamSupplier  
      private java.util.logging.Handler prioritizedHandler  
      private boolean superCompleted
      This variables is set to true as soon as the superconstructor has completed.
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      void publish​(java.util.logging.LogRecord logRecord)  
      void reacquireOutputStream()
      Set output stream to one acquired from calling outputStreamSupplier
      void setOutputStream​(java.io.OutputStream outputStream)  
      • Methods inherited from class java.util.logging.ConsoleHandler

        close
      • Methods inherited from class java.util.logging.StreamHandler

        flush, isLoggable, setEncoding
      • Methods inherited from class java.util.logging.Handler

        getEncoding, getErrorManager, getFilter, getFormatter, getLevel, reportError, setErrorManager, setFilter, setFormatter, setLevel
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Field Detail

      • outputStreamSupplier

        private final java.util.function.Supplier<java.io.OutputStream> outputStreamSupplier
      • superCompleted

        private final boolean superCompleted
        This variables is set to true as soon as the superconstructor has completed. The superconstructor calls setOutputStream(System.err), any subsequent call of setOutputStream(OutputStream) would then flush and close System.err. To avoid this, we override setOutputStream(OutputStream) to completely ignore all calls from the superconstructor.
    • Constructor Detail

      • ReacquiringConsoleHandler

        public ReacquiringConsoleHandler​(java.util.function.Supplier<java.io.OutputStream> outputStreamSupplier,
                                         java.util.logging.Handler prioritizedHandler)
        Parameters:
        outputStreamSupplier - A Supplier which will return the desired OutputStream for this handler when called. Particularly useful if you happen to be using a test framework which will switch out references to the stderr/stdout streams with new dummy ones from time to time.
        prioritizedHandler - If non-null, will suppress output of any log records which pass this handler's Handler#isLoggable(LogRecord) method.
    • Method Detail

      • reacquireOutputStream

        public void reacquireOutputStream()
        Set output stream to one acquired from calling outputStreamSupplier
      • setOutputStream

        public void setOutputStream​(java.io.OutputStream outputStream)
        Overrides:
        setOutputStream in class java.util.logging.StreamHandler
      • publish

        public void publish​(java.util.logging.LogRecord logRecord)
        Overrides:
        publish in class java.util.logging.ConsoleHandler