Class StdoutConsoleHandler

java.lang.Object
java.util.logging.Handler
rma.util.logging.StdoutConsoleHandler

public final class StdoutConsoleHandler extends Handler
The Class StdoutConsoleHandler. Based on answer here: http://stackoverflow.com/questions/194165/how-do-i-change-java-logging-console-output-from-std-err-to-std-out The default java.util.logging.ConsoleHandler sends all output to System.err Eclipse colors text from System.err red. This is annoying when the log messages aren't errors but are debug messages. This Handler will send all output to System.out. I know, thats just as bad as ConsoleHandler. But configure logging to use the two handlers together. Set WARNING and SEVERE to go to ConsoleHandler. Set Finest-Info to ConsoleHandler. Addendum: This Handler will react to changes to System.out, such as when libraries call System.setOut(newOut) such as hec.io.Console and com.rma.client.Console. If the System.out reference has been updated a new writer will be created. In order to do so this class borrows code from both java.util.logging.ConsoleHandler and its parent class java.util.logging.StreamHandler
  • Constructor Details

    • StdoutConsoleHandler

      public StdoutConsoleHandler()
      Create a ConsoleHandler for System.out.

      The ConsoleHandler is configured based on LogManager properties (or their default values).

  • Method Details

    • publish

      public void publish(LogRecord logRecord)
      Publish a LogRecord.

      The logging request was made initially to a Logger object, which initialized the LogRecord and forwarded it here.

      Specified by:
      publish in class Handler
      Parameters:
      logRecord - description of the log event. A null logRecord is silently ignored and is not published
    • close

      public void close()
      Override StreamHandler.close to do a flush but not to close the output stream. That is, we do not close System.err.
      Specified by:
      close in class Handler
    • setEncoding

      public void setEncoding(String encoding) throws SecurityException, UnsupportedEncodingException
      Set (or change) the character encoding used by this Handler.

      The encoding should be set before any LogRecords are written to the Handler.

      Overrides:
      setEncoding in class Handler
      Parameters:
      encoding - The name of a supported character encoding. May be null, to indicate the default platform encoding.
      Throws:
      SecurityException - if a security manager exists and if the caller does not have LoggingPermission("control").
      UnsupportedEncodingException - if the named encoding is not supported.
    • isLoggable

      public boolean isLoggable(LogRecord logRecord)
      Check if this Handler would actually log a given LogRecord.

      This method checks if the LogRecord has an appropriate level and whether it satisfies any Filter. It will also return false if no output stream has been assigned yet or the LogRecord is null.

      Overrides:
      isLoggable in class Handler
      Parameters:
      logRecord - a LogRecord
      Returns:
      true if the LogRecord would be logged.
    • flush

      public void flush()
      Flush any buffered messages.
      Specified by:
      flush in class Handler