com.webmethods.caf.faces.util
Class LogUtils

java.lang.Object
  extended by com.webmethods.caf.faces.util.LogUtils

public class LogUtils
extends Object

Utility functions for adding log messages to the Portal/MWS logs as category "JSF"or to other external host logging mechanisms


Field Summary
static int LEVEL_DEBUG
           
static int LEVEL_ERROR
           
static int LEVEL_FATAL
           
static int LEVEL_INFO
           
static int LEVEL_OFF
           
static int LEVEL_TRACE
           
static int LEVEL_WARN
           
 
Constructor Summary
LogUtils()
           
 
Method Summary
protected static void dumpComponent(UIComponent rootComponent, PrintWriter writer, String indent)
          Output the provided UI component as XML content to a print writer.
static void dumpComponentTreeToXMLFile(UIComponent rootComponent, String outFileName)
          Output the provided UI component as XML content to a file .
static FacesContext getFacesContext()
          Retrieve the current FacesContext from this thread
static Throwable getRootCause(Throwable ex)
          Extract the root cause of an exception chain
static String getStackTrace(Throwable t)
          Convert the stack trace associated with the specified exception to String
static boolean isLogLevelEnabled(int logLevel)
          Confirm if the logging level is enabled.
static void log(FacesContext ctx, Class bundleClass, String key, Object[] args)
          Log a localized message from the specified resource bundle using the LEVEL_INFO log level
static void log(FacesContext ctx, Class bundleClass, String key, Object[] args, boolean prependKey, Throwable t)
          Log a localized message from the specified resource bundle using the LEVEL_INFO log level
static void log(FacesContext ctx, String bundleName, String key, Object[] args, boolean prependKey)
          Log a localized message from the specified resource bundle using the LEVEL_INFO log level
static void log(FacesContext ctx, String bundleName, String key, Object[] args, boolean prependKey, Throwable t)
          Log a localized message from the specified resource bundle using the LEVEL_INFO log level
static void log(int logLevel, FacesContext ctx, Class bundleClass, String key)
          Log a localized message from the specified resource bundle using the specified log level
static void log(int logLevel, String message)
          Log a message as text, using the specified log level
static void log(int logLevel, String key, Object[] args)
          Log a localized message from the default resource bundle using the specified log level
static void log(int logLevel, String message, Throwable t)
          Log an exception using the specified log level
static void log(String message)
          Log a message as text, using the LEVEL_INFO log level
static void log(String message, Throwable throwable)
          Log an exception using the LEVEL_ERROR log level
static void log(Throwable throwable)
          Log an exception using the LEVEL_ERROR log level
static void logExternal(String message)
          Log a string to the external host log handler
static void logExternal(String message, Throwable throwable)
          Log an exception to the the external host log handler
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

LEVEL_OFF

public static final int LEVEL_OFF

LEVEL_TRACE

public static final int LEVEL_TRACE
See Also:
Constant Field Values

LEVEL_DEBUG

public static final int LEVEL_DEBUG

LEVEL_INFO

public static final int LEVEL_INFO

LEVEL_WARN

public static final int LEVEL_WARN

LEVEL_ERROR

public static final int LEVEL_ERROR

LEVEL_FATAL

public static final int LEVEL_FATAL
Constructor Detail

LogUtils

public LogUtils()
Method Detail

getFacesContext

public static FacesContext getFacesContext()
Retrieve the current FacesContext from this thread

Returns:
Current FacesContext instance

logExternal

public static void logExternal(String message,
                               Throwable throwable)
Log an exception to the the external host log handler

Parameters:
message - Text message to log
throwable - Throwable exception to log. The root cause exception and stacktrace will be included in the log message text.

logExternal

public static void logExternal(String message)
Log a string to the external host log handler

Parameters:
message - Text message to log

getRootCause

public static Throwable getRootCause(Throwable ex)
Extract the root cause of an exception chain

Parameters:
throwable - The base exception instance

isLogLevelEnabled

public static boolean isLogLevelEnabled(int logLevel)
Confirm if the logging level is enabled.

Parameters:
logLevel - Log level constant defined in LogUtils (e.g. LEVEL_DEBUG, LEVEL_WARN, etc..)
Returns:
boolean - true if the requested level is enabled, false otherwise.

log

public static void log(int logLevel,
                       String message)
Log a message as text, using the specified log level

Parameters:
logLevel - Log level constant defined in LogUtils (e.g. LEVEL_DEBUG, LEVEL_WARN, etc..)
message - The text message to record in the log

log

public static void log(int logLevel,
                       String message,
                       Throwable t)
Log an exception using the specified log level

Parameters:
logLevel - Log level constant defined in LogUtils (e.g. LEVEL_DEBUG, LEVEL_WARN, etc..)
message - The text message to record in the log
throwable - Throwable exception to log. The root cause exception and stacktrace will be included in the log message text.

log

public static void log(Throwable throwable)
Log an exception using the LEVEL_ERROR log level

Parameters:
throwable - Throwable exception to log. The root cause exception and stacktrace will be included in the log message text.

log

public static void log(String message,
                       Throwable throwable)
Log an exception using the LEVEL_ERROR log level

Parameters:
message - The text message to record in the log
throwable - Throwable exception to log. The root cause exception and stacktrace will be included in the log message text.

log

public static void log(String message)
Log a message as text, using the LEVEL_INFO log level

Parameters:
message - The text message to record in the log

log

public static void log(int logLevel,
                       String key,
                       Object[] args)
Log a localized message from the default resource bundle using the specified log level

Parameters:
logLevel - Log level constant defined in LogUtils (e.g. LEVEL_DEBUG, LEVEL_WARN, etc..)
key - Resource bundle lookup key
args - String substitution arguments for the return resource bundle string

log

public static void log(int logLevel,
                       FacesContext ctx,
                       Class bundleClass,
                       String key)
Log a localized message from the specified resource bundle using the specified log level

Parameters:
logLevel - Log level constant defined in LogUtils (e.g. LEVEL_DEBUG, LEVEL_WARN, etc..)
ctx - FacesContext instance to use to determine message locale
bundleClass - Class of the resource bundle
key - Resource bundle lookup key

log

public static void log(FacesContext ctx,
                       Class bundleClass,
                       String key,
                       Object[] args)
Log a localized message from the specified resource bundle using the LEVEL_INFO log level

Parameters:
ctx - FacesContext instance to use to determine message locale
bundleClass - Class of the resource bundle
key - Resource bundle lookup key
args - String substitution arguments for the return resource bundle string

log

public static void log(FacesContext ctx,
                       String bundleName,
                       String key,
                       Object[] args,
                       boolean prependKey)
Log a localized message from the specified resource bundle using the LEVEL_INFO log level

Parameters:
ctx - FacesContext instance to use to determine message locale
bundleName - Resource bundle class name as String
key - Resource bundle lookup key
args - String substitution arguments for the return resource bundle string
prependKey - True to prepend the key to formatted message (for an error message).

log

public static void log(FacesContext ctx,
                       String bundleName,
                       String key,
                       Object[] args,
                       boolean prependKey,
                       Throwable t)
Log a localized message from the specified resource bundle using the LEVEL_INFO log level

Parameters:
ctx - FacesContext instance to use to determine message locale
bundleName - Resource bundle class name as String
key - Resource bundle lookup key
args - String substitution arguments for the return resource bundle string
prependKey - True to prepend the key to formatted message (for an error message).
throwable - Throwable exception to log. The root cause exception and stacktrace will be included in the log message text.

log

public static void log(FacesContext ctx,
                       Class bundleClass,
                       String key,
                       Object[] args,
                       boolean prependKey,
                       Throwable t)
Log a localized message from the specified resource bundle using the LEVEL_INFO log level

Parameters:
ctx - FacesContext instance to use to determine message locale
bundleClass - Resource bundle Class
key - Resource bundle lookup key
args - String substitution arguments for the return resource bundle string
prependKey - True to prepend the key to formatted message (for an error message).
throwable - Throwable exception to log. The root cause exception and stacktrace will be included in the log message text.

getStackTrace

public static String getStackTrace(Throwable t)
Convert the stack trace associated with the specified exception to String

Parameters:
throwable - Throwable exception to extract stack info from
Returns:
The stack trace as a string (including carriage returns)

dumpComponentTreeToXMLFile

public static void dumpComponentTreeToXMLFile(UIComponent rootComponent,
                                              String outFileName)
Output the provided UI component as XML content to a file .

Parameters:
rootComponent - The UI component to write out to the file.
outFileName - The name of the file to use as the destination of this writer. If the file exists then it will be truncated to zero size; otherwise, a new file will be created. The output will be written to the file and is buffered.

dumpComponent

protected static void dumpComponent(UIComponent rootComponent,
                                    PrintWriter writer,
                                    String indent)
Output the provided UI component as XML content to a print writer.

Parameters:
rootComponent - The UI component to write out to the file.
writer - The print writer to output the UI component.
indent - Indent in spaces for the entire content. IE. " "