Class StatusConsoleListener

  • All Implemented Interfaces:
    java.io.Closeable, java.lang.AutoCloseable, java.util.EventListener, StatusListener

    public class StatusConsoleListener
    extends java.lang.Object
    implements StatusListener
    A StatusListener that writes to the console.
    • Method Summary

      All Methods Static Methods Instance Methods Concrete Methods Deprecated Methods 
      Modifier and Type Method Description
      void close()
      Resets the level and output stream to its initial values, and closes the output stream, if it is a non-system one.
      private static void closeNonSystemStream​(java.io.OutputStream stream)  
      Level getStatusLevel()
      Returns the level for which the listener should receive events.
      void log​(StatusData data)
      Writes status messages to the console.
      void setFilters​(java.lang.String... filters)
      Deprecated.
      since 2.23.0, this method is ineffective and only kept for binary backward compatibility.
      void setLevel​(Level level)
      Sets the level to a new value.
      void setStream​(java.io.PrintStream stream)
      Sets the output stream to a new value.
      • Methods inherited from class java.lang.Object

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

      • lock

        private final java.util.concurrent.locks.Lock lock
      • initialLevel

        private final Level initialLevel
      • initialStream

        private final java.io.PrintStream initialStream
      • level

        private volatile Level level
      • stream

        private volatile java.io.PrintStream stream
    • Constructor Detail

      • StatusConsoleListener

        public StatusConsoleListener​(Level level)
        Constructs a StatusConsoleListener instance writing to System.out using the supplied level.
        Parameters:
        level - the level of status messages that should appear on the console
        Throws:
        java.lang.NullPointerException - on null level
      • StatusConsoleListener

        public StatusConsoleListener​(Level level,
                                     java.io.PrintStream stream)
        Constructs a StatusConsoleListener instance using the supplied level and stream.

        Make sure not to use a logger stream of some sort to avoid creating an infinite loop of indirection!

        Parameters:
        level - the level of status messages that should appear on the console
        stream - the stream to write to
        Throws:
        java.lang.NullPointerException - on null level or stream
    • Method Detail

      • setLevel

        public void setLevel​(Level level)
        Sets the level to a new value.
        Parameters:
        level - the new level
        Throws:
        java.lang.NullPointerException - on null level
      • setStream

        public void setStream​(java.io.PrintStream stream)
        Sets the output stream to a new value.
        Parameters:
        stream - the new output stream
        Throws:
        java.lang.NullPointerException - on null stream
        Since:
        2.23.0
      • getStatusLevel

        public Level getStatusLevel()
        Returns the level for which the listener should receive events.
        Specified by:
        getStatusLevel in interface StatusListener
        Returns:
        the log level
      • log

        public void log​(StatusData data)
        Writes status messages to the console.
        Specified by:
        log in interface StatusListener
        Parameters:
        data - a status data
        Throws:
        java.lang.NullPointerException - on null data
      • setFilters

        @Deprecated
        public void setFilters​(java.lang.String... filters)
        Deprecated.
        since 2.23.0, this method is ineffective and only kept for binary backward compatibility.
        Adds package name filters to exclude.
        Parameters:
        filters - An array of package names to exclude.
      • close

        public void close()
        Resets the level and output stream to its initial values, and closes the output stream, if it is a non-system one.
        Specified by:
        close in interface java.lang.AutoCloseable
        Specified by:
        close in interface java.io.Closeable
      • closeNonSystemStream

        private static void closeNonSystemStream​(java.io.OutputStream stream)