org.springframework.roo.support.logging
Class HandlerUtils

java.lang.Object
  extended by org.springframework.roo.support.logging.HandlerUtils

public abstract class HandlerUtils
extends Object

Utility methods for dealing with Handler objects.

Since:
1.0
Author:
Ben Alex

Constructor Summary
HandlerUtils()
           
 
Method Summary
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 final 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 final 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 Handlers for (required)
fallbackSeverity - to trigger fallback mode (required)
Returns:
the number of DeferredLogHandlers now registered against the Logger (guaranteed to be 1 or above)

registerTargetHandler

public static final 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 [email protected]
Returns:
number of DeferredLogHandler instances detected and updated (may be 0 if none found)

flushAllHandlers

public static final 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 Handlers flushed (may be 0 or above)


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