Class DeferredLogHandler

  extended by java.util.logging.Handler
      extended by

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.

Ben Alex

Constructor Summary
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.
Method Summary
 void close()
 void flush()
 Handler getTargetHandler()
 void publish(LogRecord record)
          Stores the log record internally.
 void setTargetHandler(Handler targetHandler)
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

Constructor Detail


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.

fallbackHandler - to publish events to (mandatory)
fallbackPushLevel - the level which will trigger an event publication (mandatory)
Method Detail


public void close()
           throws SecurityException
Specified by:
close in class Handler


public void flush()
Specified by:
flush in class Handler


public void publish(LogRecord record)
Stores the log record internally.

Specified by:
publish in class Handler


public Handler getTargetHandler()
the target Handler, or null if there is no target Handler defined so far


public void setTargetHandler(Handler targetHandler)

Copyright © 2009-2010 VMware, Inc. All Rights Reserved.