public class XLog extends Object implements org.apache.commons.logging.Log
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.
Modifier and Type | Class and Description |
---|---|
static class |
XLog.Info
LogInfo stores contextual information to create log prefixes. |
static class |
XLog.Level |
Modifier and Type | Field and Description |
---|---|
static String |
INSTRUMENTATION_LOG_NAME |
static int |
OPS
Mask for tee logging to the OPS log.
|
static int |
STD
Mask for logging to the standard log.
|
Constructor and Description |
---|
XLog(org.apache.commons.logging.Log log)
Create a
XLog with no prefix. |
Modifier and Type | Method and Description |
---|---|
void |
debug(int loggerMask,
String msgTemplate,
Object... params)
Tee Log a debug message
Exception to the common log and specified Log s. |
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 Log s. |
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 Log s. |
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.
|
static XLog |
getLog(String name)
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 Log s. |
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 Log s. |
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 Log s. |
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 . |
public static final String INSTRUMENTATION_LOG_NAME
public static final int STD
public static final int OPS
public XLog(org.apache.commons.logging.Log log)
XLog
with no prefix.log
- Log instance to use for logging.public static XLog getLog(String name)
name
- logger name.public static XLog getLog(Class clazz)
clazz
- from which the logger name will be derived.public static XLog resetPrefix(XLog log)
log
- the named loggerpublic String getMsgPrefix()
public void setMsgPrefix(String prefix)
prefix
- the common prefix to set.public void debug(Object o)
Log
.debug
in interface org.apache.commons.logging.Log
o
- message.public void debug(Object o, Throwable throwable)
Exception
to the common Log
.debug
in interface org.apache.commons.logging.Log
o
- message.throwable
- exception.public void error(Object o)
Log
.error
in interface org.apache.commons.logging.Log
o
- message.public void error(Object o, Throwable throwable)
Exception
to the common Log
.error
in interface org.apache.commons.logging.Log
o
- message.throwable
- exception.public void fatal(Object o)
Log
.fatal
in interface org.apache.commons.logging.Log
o
- message.public void fatal(Object o, Throwable throwable)
Exception
to the common Log
.fatal
in interface org.apache.commons.logging.Log
o
- message.throwable
- exception.public void info(Object o)
Log
.info
in interface org.apache.commons.logging.Log
o
- message.public void info(Object o, Throwable throwable)
Exception
to the common Log
.info
in interface org.apache.commons.logging.Log
o
- message.throwable
- exception.public void trace(Object o)
Log
.trace
in interface org.apache.commons.logging.Log
o
- message.public void trace(Object o, Throwable throwable)
Exception
to the common Log
.trace
in interface org.apache.commons.logging.Log
o
- message.throwable
- exception.public void warn(Object o)
Log
.warn
in interface org.apache.commons.logging.Log
o
- message.public void warn(Object o, Throwable throwable)
Exception
to the common Log
.warn
in interface org.apache.commons.logging.Log
o
- message.throwable
- exception.public boolean isDebugEnabled()
isDebugEnabled
in interface org.apache.commons.logging.Log
true
if debug logging is enable, false
if not.public boolean isErrorEnabled()
isErrorEnabled
in interface org.apache.commons.logging.Log
true
if error logging is enable, false
if not.public boolean isFatalEnabled()
isFatalEnabled
in interface org.apache.commons.logging.Log
true
if fatal logging is enable, false
if not.public boolean isInfoEnabled()
isInfoEnabled
in interface org.apache.commons.logging.Log
true
if info logging is enable, false
if not.public boolean isTraceEnabled()
isTraceEnabled
in interface org.apache.commons.logging.Log
true
if trace logging is enable, false
if not.public boolean isWarnEnabled()
isWarnEnabled
in interface org.apache.commons.logging.Log
true
if warn logging is enable, false
if not.public void fatal(String msgTemplate, Object... params)
Exception
to the common Log
.msgTemplate
- message template.params
- parameters for the message template. If the last parameter is an exception it is logged as such.public void error(String msgTemplate, Object... params)
Exception
to the common Log
.msgTemplate
- message template.params
- parameters for the message template. If the last parameter is an exception it is logged as such.public void info(String msgTemplate, Object... params)
Exception
to the common Log
.msgTemplate
- message template.params
- parameters for the message template. If the last parameter is an exception it is logged as such.public void warn(String msgTemplate, Object... params)
Exception
to the common Log
.msgTemplate
- message template.params
- parameters for the message template. If the last parameter is an exception it is logged as such.public void debug(String msgTemplate, Object... params)
Exception
to the common Log
.msgTemplate
- message template.params
- parameters for the message template. If the last parameter is an exception it is logged as such.public void trace(String msgTemplate, Object... params)
Exception
to the common Log
.msgTemplate
- message template.params
- parameters for the message template. If the last parameter is an exception it is logged as such.public void fatal(int loggerMask, String msgTemplate, Object... params)
Exception
to the common log and specified Log
s.loggerMask
- log mask, it is a bit mask, possible values are APP
and OPS
.msgTemplate
- message template.params
- parameters for the message template.public void error(int loggerMask, String msgTemplate, Object... params)
Exception
to the common log and specified Log
s.loggerMask
- log mask, it is a bit mask, possible values are APP
and OPS
.msgTemplate
- message template.params
- parameters for the message template.public void info(int loggerMask, String msgTemplate, Object... params)
Exception
to the common log and specified Log
s.loggerMask
- log mask, it is a bit mask, possible values are APP
and OPS
.msgTemplate
- message template.params
- parameters for the message template.public void warn(int loggerMask, String msgTemplate, Object... params)
Exception
to the common log and specified Log
s.loggerMask
- log mask, it is a bit mask, possible values are APP
and OPS
.msgTemplate
- message template.params
- parameters for the message template.public void debug(int loggerMask, String msgTemplate, Object... params)
Exception
to the common log and specified Log
s.loggerMask
- log mask, it is a bit mask, possible values are APP
and OPS
.msgTemplate
- message template.params
- parameters for the message template.public void trace(int loggerMask, String msgTemplate, Object... params)
Exception
to the common log and specified Log
s.loggerMask
- log mask, it is a bit mask, possible values are APP
and OPS
.msgTemplate
- message template.params
- parameters for the message template.public static String format(String msgTemplate, Object... params)
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.
msgTemplate
- message template.params
- paramaters to use in the template. If the last parameter is an Exception, it is ignored.Copyright © 2018 Apache Software Foundation. All rights reserved.