Package rma.util.logging
Class StdoutConsoleHandler
java.lang.Object
java.util.logging.Handler
rma.util.logging.StdoutConsoleHandler
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 Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoid
close()
Override StreamHandler.close to do a flush but not to close the output stream.void
flush()
Flush any buffered messages.boolean
isLoggable
(LogRecord logRecord) Check if this Handler would actually log a given LogRecord.void
Publish a LogRecord.void
setEncoding
(String encoding) Set (or change) the character encoding used by this Handler.Methods inherited from class java.util.logging.Handler
getEncoding, getErrorManager, getFilter, getFormatter, getLevel, reportError, setErrorManager, setFilter, setFormatter, setLevel
-
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
Publish a LogRecord.The logging request was made initially to a Logger object, which initialized the LogRecord and forwarded it here.
-
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. -
setEncoding
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 classHandler
- 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
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 classHandler
- Parameters:
logRecord
- a LogRecord- Returns:
- true if the LogRecord would be logged.
-
flush
public void flush()Flush any buffered messages.
-