org.springframework.shell.support.logging

## Class HandlerUtils

- java.lang.Object
- - org.springframework.shell.support.logging.HandlerUtils

-     public abstract class HandlerUtils
      extends Object

  Utility methods for dealing with `Handler` objects.
  Since:
    1.0

- - ### Constructor Summary

    Constructors
    Constructor and Description
    `HandlerUtils()`

  - ### Method Summary

    Methods
    Modifier and Type | Method and Description
    --- | ---
    `static int` | `flushAllHandlers(Logger logger)` Forces all `Handler` instances registered in the presented `Logger` to be flushed.
    `static Logger` | `getLogger(Class<?> clazz)` Obtains a `Logger` that guarantees to set the `Level` to `Level.FINE` if it is part of org.springframework.roo.
    `static int` | `registerTargetHandler(Logger logger, Handler target)` Registers the presented target `Handler` against any `DeferredLogHandler` encountered in the presented `Logger`.
    `static int` | `wrapWithDeferredLogHandler(Logger logger, Level fallbackSeverity)` Replaces each `Handler` defined against the presented `Logger` with `DeferredLogHandler`.

    - ### Methods inherited from class java.lang.Object

      `clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

- - ### Constructor Detail

    - #### HandlerUtils

          public HandlerUtils()

  - ### Method Detail

    - #### getLogger

          public static Logger getLogger(Class<?> clazz)

      Obtains a `Logger` that guarantees to set the `Level` to `Level.FINE` if it is part of org.springframework.roo. Unfortunately this is needed due to a regression in JDK 1.6.0_18 as per issue ROO-539.
      Parameters:
        `clazz` - to retrieve the logger for (required)
      Returns:
        the logger, which will at least of `Level.FINE` if no level was specified

    - #### wrapWithDeferredLogHandler

          public static int wrapWithDeferredLogHandler(Logger logger,
                                       Level fallbackSeverity)

      Replaces each `Handler` defined against the presented `Logger` with `DeferredLogHandler`.

      This is useful for ensuring any `Handler` defaults defined by the user are preserved and treated as the `DeferredLogHandler` "fallback" `Handler` if the indicated severity `Level` is encountered.

      This method will create a `ConsoleHandler` if the presented `Logger` has no current `Handler`.

      Parameters:
        `logger` - to introspect and replace the `Handler`s for (required)
        `fallbackSeverity` - to trigger fallback mode (required)
      Returns:
        the number of `DeferredLogHandler`s now registered against the `Logger` (guaranteed to be 1 or above)

    - #### registerTargetHandler

          public static int registerTargetHandler(Logger logger,
                                  Handler target)

      Registers the presented target `Handler` against any `DeferredLogHandler` encountered in the presented `Logger`.

      Generally this method is used on `Logger` instances that have previously been presented to the `wrapWithDeferredLogHandler(Logger, Level)` method.

      The method will return a count of how many `DeferredLogHandler` instances it detected. Note that no attempt is made to distinguish between instances already possessing the intended target `Handler` or those already possessing any target `Handler` at all. This method always overwrites the target `Handler` and the returned count represents how many overwrites took place.

      Parameters:
        `logger` - to introspect for `DeferredLogHandler` instances (required)
        `target` - to set as the target `Handler`
      Returns:
        number of `DeferredLogHandler` instances detected and updated (may be 0 if none found)

    - #### flushAllHandlers

          public static int flushAllHandlers(Logger logger)

      Forces all `Handler` instances registered in the presented `Logger` to be flushed.
      Parameters:
        `logger` - to flush (required)
      Returns:
        the number of `Handler`s flushed (may be 0 or above)