public class DeferredLogHandler extends Handler
LogRecord
instances until a target Handler
is registered.
This class is useful if a target Handler
cannot be instantiated before LogRecord
instances are being
published. This may be the case if the target Handler
requires the establishment of complex publication
infrastructure such as a GUI, message queue, IoC container and the establishment of that infrastructure may produce
log messages that should ultimately be delivered to the target Handler
.
In recognition that sometimes the target Handler
may never be registered (perhaps due to failures configuring
its supporting infrastructure), this class supports a fallback mode. When in fallback mode, a fallback Handler
will receive all previous and future LogRecord
instances. Fallback mode is automatically triggered if a
LogRecord
is published at the fallback Level
. Fallback mode is also triggered if the flush()
or close()
method is involved and the target Handler
has never been registered.
Constructor and Description |
---|
DeferredLogHandler(Handler fallbackHandler,
Level fallbackPushLevel)
|
Modifier and Type | Method and Description |
---|---|
void |
close() |
void |
flush() |
Handler |
getTargetHandler() |
void |
publish(LogRecord record)
Stores the log record internally.
|
void |
setTargetHandler(Handler targetHandler) |
getEncoding, getErrorManager, getFilter, getFormatter, getLevel, isLoggable, reportError, setEncoding, setErrorManager, setFilter, setFormatter, setLevel
public DeferredLogHandler(Handler fallbackHandler, Level fallbackPushLevel)
LogRecord
instances to the specified fallback
Handler
if an event of the specified Level
is received.fallbackHandler
- to publish events to (mandatory)fallbackPushLevel
- the level which will trigger an event publication (mandatory)public void close() throws SecurityException
close
in class Handler
SecurityException
public void publish(LogRecord record)
public Handler getTargetHandler()
public void setTargetHandler(Handler targetHandler)