org.springframework.shell.support.logging
Class DeferredLogHandler
java.lang.Object
java.util.logging.Handler
org.springframework.shell.support.logging.DeferredLogHandler
public class DeferredLogHandler
- extends Handler
Defers the publication of JDK 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.
- Since:
- 1.0
Methods inherited from class java.util.logging.Handler |
getEncoding, getErrorManager, getFilter, getFormatter, getLevel, isLoggable, reportError, setEncoding, setErrorManager, setFilter, setFormatter, setLevel |
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
DeferredLogHandler
public DeferredLogHandler(Handler fallbackHandler,
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.
- Parameters:
fallbackHandler
- to publish events to (mandatory)fallbackPushLevel
- the level which will trigger an event publication (mandatory)
close
public void close()
throws SecurityException
- Specified by:
close
in class Handler
- Throws:
SecurityException
flush
public void flush()
- Specified by:
flush
in class Handler
publish
public void publish(LogRecord record)
- Stores the log record internally.
- Specified by:
publish
in class Handler
getTargetHandler
public Handler getTargetHandler()
- Returns:
- the target
Handler
, or null if there is no target Handler
defined so far
setTargetHandler
public void setTargetHandler(Handler targetHandler)