public static class Logging.ReacquiringConsoleHandler extends java.util.logging.ConsoleHandler
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.| Modifier and Type | Field and 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.
|
| Constructor and Description |
|---|
ReacquiringConsoleHandler(java.util.function.Supplier<java.io.OutputStream> outputStreamSupplier,
java.util.logging.Handler prioritizedHandler)
Construct a new
Logging.ReacquiringConsoleHandler. |
| Modifier and Type | Method and Description |
|---|---|
void |
publish(java.util.logging.LogRecord record) |
void |
reacquireOutputStream()
Set output stream to one acquired from calling outputStreamSupplier
|
void |
setOutputStream(java.io.OutputStream outputStream) |
private final java.util.function.Supplier<java.io.OutputStream> outputStreamSupplier
private final java.util.logging.Handler prioritizedHandler
private java.io.OutputStream outputStreamMemo
private final boolean superCompleted
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.public ReacquiringConsoleHandler(java.util.function.Supplier<java.io.OutputStream> outputStreamSupplier, java.util.logging.Handler prioritizedHandler)
Logging.ReacquiringConsoleHandler.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.public void reacquireOutputStream()
public void setOutputStream(java.io.OutputStream outputStream)
setOutputStream in class java.util.logging.StreamHandlerpublic void publish(java.util.logging.LogRecord record)
publish in class java.util.logging.ConsoleHandler