Package org.openstreetmap.josm.tools
Class Logging.ReacquiringConsoleHandler
- java.lang.Object
-
- java.util.logging.Handler
-
- java.util.logging.StreamHandler
-
- java.util.logging.ConsoleHandler
-
- org.openstreetmap.josm.tools.Logging.ReacquiringConsoleHandler
-
- Enclosing class:
- Logging
public static class Logging.ReacquiringConsoleHandler extends ConsoleHandler
AConsoleHandler
with a couple of extra features, allowing it to be targeted at an an arbitraryOutputStream
which it can be asked to reacquire the reference for on demand throughreacquireOutputStream()
. It can also prevent a LogRecord's output if a specifiedprioritizedHandler
would have outputted it.- Since:
- 14052
-
-
Field Summary
Fields Modifier and Type Field Description private OutputStream
outputStreamMemo
private Supplier<OutputStream>
outputStreamSupplier
private Handler
prioritizedHandler
private boolean
superCompleted
This variables is set to true as soon as the superconstructor has completed.
-
Constructor Summary
Constructors Constructor Description ReacquiringConsoleHandler(Supplier<OutputStream> outputStreamSupplier, Handler prioritizedHandler)
Construct a newLogging.ReacquiringConsoleHandler
.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
publish(LogRecord record)
void
reacquireOutputStream()
Set output stream to one acquired from calling outputStreamSuppliervoid
setOutputStream(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
-
-
-
-
Field Detail
-
outputStreamSupplier
private final Supplier<OutputStream> outputStreamSupplier
-
prioritizedHandler
private final Handler prioritizedHandler
-
outputStreamMemo
private OutputStream outputStreamMemo
-
superCompleted
private final boolean superCompleted
This variables is set to true as soon as the superconstructor has completed. The superconstructor callssetOutputStream(System.err)
, any subsequent call ofsetOutputStream(OutputStream)
would then flush and closeSystem.err
. To avoid this, we overridesetOutputStream(OutputStream)
to completely ignore all calls from the superconstructor.
-
-
Constructor Detail
-
ReacquiringConsoleHandler
public ReacquiringConsoleHandler(Supplier<OutputStream> outputStreamSupplier, Handler prioritizedHandler)
Construct a newLogging.ReacquiringConsoleHandler
.- Parameters:
outputStreamSupplier
- ASupplier
which will return the desiredOutputStream
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'sHandler#isLoggable(LogRecord)
method.
-
-
Method Detail
-
reacquireOutputStream
public void reacquireOutputStream()
Set output stream to one acquired from calling outputStreamSupplier
-
setOutputStream
public void setOutputStream(OutputStream outputStream)
- Overrides:
setOutputStream
in classStreamHandler
-
publish
public void publish(LogRecord record)
- Overrides:
publish
in classConsoleHandler
-
-