org.apache.oozie.util
Class XLog

java.lang.Object
  extended by org.apache.oozie.util.XLog
All Implemented Interfaces:
org.apache.commons.logging.Log

public class XLog
extends Object
implements org.apache.commons.logging.Log

The XLog class extends the functionality of the Apache common-logging Log interface.

It provides common prefix support, message templating with variable parameters and selective tee logging to multiple logs.

It provides also the LogFactory functionality.


Nested Class Summary
static class XLog.Info
          LogInfo stores contextual information to create log prefixes.
static class XLog.Level
           
 
Field Summary
static int OPS
          Mask for tee logging to the OPS log.
static int STD
          Mask for logging to the standard log.
 
Constructor Summary
XLog(org.apache.commons.logging.Log log)
          Create a XLog with no prefix.
XLog(org.apache.commons.logging.Log log, String prefix)
          Create a XLog with a common prefix.
 
Method Summary
 void debug(int loggerMask, String msgTemplate, Object... params)
          Tee Log a debug message Exception to the common log and specified Logs.
 void debug(Object o)
          Log a debug message to the common Log.
 void debug(Object o, Throwable throwable)
          Log a debug message and Exception to the common Log.
 void debug(String msgTemplate, Object... params)
          Log a debug message Exception to the common Log.
 void error(int loggerMask, String msgTemplate, Object... params)
          Tee Log a error message Exception to the common log and specified Logs.
 void error(Object o)
          Log a error message to the common Log.
 void error(Object o, Throwable throwable)
          Log a error message and Exception to the common Log.
 void error(String msgTemplate, Object... params)
          Log a error message Exception to the common Log.
 void fatal(int loggerMask, String msgTemplate, Object... params)
          Tee Log a fatal message Exception to the common log and specified Logs.
 void fatal(Object o)
          Log a fatal message to the common Log.
 void fatal(Object o, Throwable throwable)
          Log a fatal message and Exception to the common Log.
 void fatal(String msgTemplate, Object... params)
          Log a fatal message Exception to the common Log.
static String format(String msgTemplate, Object... params)
          Utility method that does uses the StringFormat to format the message template using the provided parameters.
static Throwable getCause(Object... params)
          Utility method that extracts the Throwable, if present, from the parameters.
static XLog getLog(Class clazz)
          Return the named logger configured with the XLog.Info prefix.
static XLog getLog(Class clazz, boolean prefix)
          Return the named logger.
static XLog getLog(String name)
          Return the named logger configured with the XLog.Info prefix.
static XLog getLog(String name, boolean prefix)
          Return the named logger.
 String getMsgPrefix()
          Return the common prefix.
 void info(int loggerMask, String msgTemplate, Object... params)
          Tee Log a info message Exception to the common log and specified Logs.
 void info(Object o)
          Log a info message to the common Log.
 void info(Object o, Throwable throwable)
          Log a info message and Exception to the common Log.
 void info(String msgTemplate, Object... params)
          Log a info message Exception to the common Log.
 boolean isDebugEnabled()
          Return if debug logging is enabled.
 boolean isErrorEnabled()
          Return if error logging is enabled.
 boolean isFatalEnabled()
          Return if fatal logging is enabled.
 boolean isInfoEnabled()
          Return if info logging is enabled.
 boolean isTraceEnabled()
          Return if trace logging is enabled.
 boolean isWarnEnabled()
          Return if warn logging is enabled.
static XLog resetPrefix(XLog log)
          Reset the logger prefix
 void setMsgPrefix(String prefix)
          Set the common prefix.
 void trace(int loggerMask, String msgTemplate, Object... params)
          Tee Log a trace message Exception to the common log and specified Logs.
 void trace(Object o)
          Log a trace message to the common Log.
 void trace(Object o, Throwable throwable)
          Log a trace message and Exception to the common Log.
 void trace(String msgTemplate, Object... params)
          Log a trace message Exception to the common Log.
 void warn(int loggerMask, String msgTemplate, Object... params)
          Tee Log a warn message Exception to the common log and specified Logs.
 void warn(Object o)
          Log a warn message to the common Log.
 void warn(Object o, Throwable throwable)
          Log a warn message and Exception to the common Log.
 void warn(String msgTemplate, Object... params)
          Log a warn message Exception to the common Log.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

STD

public static final int STD
Mask for logging to the standard log.

See Also:
Constant Field Values

OPS

public static final int OPS
Mask for tee logging to the OPS log.

See Also:
Constant Field Values
Constructor Detail

XLog

public XLog(org.apache.commons.logging.Log log)
Create a XLog with no prefix.

Parameters:
log - Log instance to use for logging.

XLog

public XLog(org.apache.commons.logging.Log log,
            String prefix)
Create a XLog with a common prefix.

The prefix will be prepended to all log messages.

Parameters:
log - Log instance to use for logging.
prefix - common prefix to use for all log messages.
Method Detail

getLog

public static XLog getLog(String name)
Return the named logger configured with the XLog.Info prefix.

Parameters:
name - logger name.
Returns:
the named logger configured with the XLog.Info prefix.

getLog

public static XLog getLog(Class clazz)
Return the named logger configured with the XLog.Info prefix.

Parameters:
clazz - from which the logger name will be derived.
Returns:
the named logger configured with the XLog.Info prefix.

getLog

public static XLog getLog(String name,
                          boolean prefix)
Return the named logger.

Parameters:
name - logger name.
prefix - indicates if the XLog.Info prefix has to be used or not.
Returns:
the named logger.

getLog

public static XLog getLog(Class clazz,
                          boolean prefix)
Return the named logger.

Parameters:
clazz - from which the logger name will be derived.
prefix - indicates if the XLog.Info prefix has to be used or not.
Returns:
the named logger.

resetPrefix

public static XLog resetPrefix(XLog log)
Reset the logger prefix

Parameters:
log - the named logger
Returns:
the named logger with reset prefix

getMsgPrefix

public String getMsgPrefix()
Return the common prefix.

Returns:
the common prefix.

setMsgPrefix

public void setMsgPrefix(String prefix)
Set the common prefix.

Parameters:
prefix - the common prefix to set.

debug

public void debug(Object o)
Log a debug message to the common Log.

Specified by:
debug in interface org.apache.commons.logging.Log
Parameters:
o - message.

debug

public void debug(Object o,
                  Throwable throwable)
Log a debug message and Exception to the common Log.

Specified by:
debug in interface org.apache.commons.logging.Log
Parameters:
o - message.
throwable - exception.

error

public void error(Object o)
Log a error message to the common Log.

Specified by:
error in interface org.apache.commons.logging.Log
Parameters:
o - message.

error

public void error(Object o,
                  Throwable throwable)
Log a error message and Exception to the common Log.

Specified by:
error in interface org.apache.commons.logging.Log
Parameters:
o - message.
throwable - exception.

fatal

public void fatal(Object o)
Log a fatal message to the common Log.

Specified by:
fatal in interface org.apache.commons.logging.Log
Parameters:
o - message.

fatal

public void fatal(Object o,
                  Throwable throwable)
Log a fatal message and Exception to the common Log.

Specified by:
fatal in interface org.apache.commons.logging.Log
Parameters:
o - message.
throwable - exception.

info

public void info(Object o)
Log a info message to the common Log.

Specified by:
info in interface org.apache.commons.logging.Log
Parameters:
o - message.

info

public void info(Object o,
                 Throwable throwable)
Log a info message and Exception to the common Log.

Specified by:
info in interface org.apache.commons.logging.Log
Parameters:
o - message.
throwable - exception.

trace

public void trace(Object o)
Log a trace message to the common Log.

Specified by:
trace in interface org.apache.commons.logging.Log
Parameters:
o - message.

trace

public void trace(Object o,
                  Throwable throwable)
Log a trace message and Exception to the common Log.

Specified by:
trace in interface org.apache.commons.logging.Log
Parameters:
o - message.
throwable - exception.

warn

public void warn(Object o)
Log a warn message to the common Log.

Specified by:
warn in interface org.apache.commons.logging.Log
Parameters:
o - message.

warn

public void warn(Object o,
                 Throwable throwable)
Log a warn message and Exception to the common Log.

Specified by:
warn in interface org.apache.commons.logging.Log
Parameters:
o - message.
throwable - exception.

isDebugEnabled

public boolean isDebugEnabled()
Return if debug logging is enabled.

Specified by:
isDebugEnabled in interface org.apache.commons.logging.Log
Returns:
true if debug logging is enable, false if not.

isErrorEnabled

public boolean isErrorEnabled()
Return if error logging is enabled.

Specified by:
isErrorEnabled in interface org.apache.commons.logging.Log
Returns:
true if error logging is enable, false if not.

isFatalEnabled

public boolean isFatalEnabled()
Return if fatal logging is enabled.

Specified by:
isFatalEnabled in interface org.apache.commons.logging.Log
Returns:
true if fatal logging is enable, false if not.

isInfoEnabled

public boolean isInfoEnabled()
Return if info logging is enabled.

Specified by:
isInfoEnabled in interface org.apache.commons.logging.Log
Returns:
true if info logging is enable, false if not.

isTraceEnabled

public boolean isTraceEnabled()
Return if trace logging is enabled.

Specified by:
isTraceEnabled in interface org.apache.commons.logging.Log
Returns:
true if trace logging is enable, false if not.

isWarnEnabled

public boolean isWarnEnabled()
Return if warn logging is enabled.

Specified by:
isWarnEnabled in interface org.apache.commons.logging.Log
Returns:
true if warn logging is enable, false if not.

fatal

public void fatal(String msgTemplate,
                  Object... params)
Log a fatal message Exception to the common Log.

Parameters:
msgTemplate - message template.
params - parameters for the message template. If the last parameter is an exception it is logged as such.

error

public void error(String msgTemplate,
                  Object... params)
Log a error message Exception to the common Log.

Parameters:
msgTemplate - message template.
params - parameters for the message template. If the last parameter is an exception it is logged as such.

info

public void info(String msgTemplate,
                 Object... params)
Log a info message Exception to the common Log.

Parameters:
msgTemplate - message template.
params - parameters for the message template. If the last parameter is an exception it is logged as such.

warn

public void warn(String msgTemplate,
                 Object... params)
Log a warn message Exception to the common Log.

Parameters:
msgTemplate - message template.
params - parameters for the message template. If the last parameter is an exception it is logged as such.

debug

public void debug(String msgTemplate,
                  Object... params)
Log a debug message Exception to the common Log.

Parameters:
msgTemplate - message template.
params - parameters for the message template. If the last parameter is an exception it is logged as such.

trace

public void trace(String msgTemplate,
                  Object... params)
Log a trace message Exception to the common Log.

Parameters:
msgTemplate - message template.
params - parameters for the message template. If the last parameter is an exception it is logged as such.

fatal

public void fatal(int loggerMask,
                  String msgTemplate,
                  Object... params)
Tee Log a fatal message Exception to the common log and specified Logs.

Parameters:
loggerMask - log mask, it is a bit mask, possible values are APP and OPS.
msgTemplate - message template.
params - parameters for the message template.

error

public void error(int loggerMask,
                  String msgTemplate,
                  Object... params)
Tee Log a error message Exception to the common log and specified Logs.

Parameters:
loggerMask - log mask, it is a bit mask, possible values are APP and OPS.
msgTemplate - message template.
params - parameters for the message template.

info

public void info(int loggerMask,
                 String msgTemplate,
                 Object... params)
Tee Log a info message Exception to the common log and specified Logs.

Parameters:
loggerMask - log mask, it is a bit mask, possible values are APP and OPS.
msgTemplate - message template.
params - parameters for the message template.

warn

public void warn(int loggerMask,
                 String msgTemplate,
                 Object... params)
Tee Log a warn message Exception to the common log and specified Logs.

Parameters:
loggerMask - log mask, it is a bit mask, possible values are APP and OPS.
msgTemplate - message template.
params - parameters for the message template.

debug

public void debug(int loggerMask,
                  String msgTemplate,
                  Object... params)
Tee Log a debug message Exception to the common log and specified Logs.

Parameters:
loggerMask - log mask, it is a bit mask, possible values are APP and OPS.
msgTemplate - message template.
params - parameters for the message template.

trace

public void trace(int loggerMask,
                  String msgTemplate,
                  Object... params)
Tee Log a trace message Exception to the common log and specified Logs.

Parameters:
loggerMask - log mask, it is a bit mask, possible values are APP and OPS.
msgTemplate - message template.
params - parameters for the message template.

format

public static String format(String msgTemplate,
                            Object... params)
Utility method that does uses the StringFormat to format the message template using the provided parameters.

In addition to the StringFormat syntax for message templates, it supports {E} for ENTER.

The last parameter is ignored for the formatting if it is an Exception.

Parameters:
msgTemplate - message template.
params - paramaters to use in the template. If the last parameter is an Exception, it is ignored.
Returns:
formatted message.

getCause

public static Throwable getCause(Object... params)
Utility method that extracts the Throwable, if present, from the parameters.

Parameters:
params - parameters.
Returns:
a Throwable instance if it is the last parameter, null otherwise.


Copyright © 2013 Apache Software Foundation. All Rights Reserved.