public class DeferredLogHandler
extends java.util.logging.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(java.util.logging.Handler fallbackHandler,
java.util.logging.Level fallbackPushLevel)
Creates an instance that will publish all recorded
LogRecord instances to the specified fallback
Handler if an event of the specified Level is received. |
Modifier and Type | Method and Description |
---|---|
void |
close() |
void |
flush() |
java.util.logging.Handler |
getTargetHandler() |
void |
publish(java.util.logging.LogRecord record)
Stores the log record internally.
|
void |
setTargetHandler(java.util.logging.Handler targetHandler) |
public DeferredLogHandler(java.util.logging.Handler fallbackHandler, java.util.logging.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 java.lang.SecurityException
close
in class java.util.logging.Handler
java.lang.SecurityException
public void flush()
flush
in class java.util.logging.Handler
public void publish(java.util.logging.LogRecord record)
publish
in class java.util.logging.Handler
public java.util.logging.Handler getTargetHandler()
Handler
, or null if there is no target Handler
defined so farpublic void setTargetHandler(java.util.logging.Handler targetHandler)