下面列出了org.slf4j.helpers.MessageFormatter#format ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
public static void info(org.apache.log4j.Logger logger, String messagePattern, Object object) {
FormattingTuple format = MessageFormatter.format(messagePattern, object);
logger.info(format.getMessage());
}
public static void info(org.apache.log4j.Logger logger, String messagePattern, Object object) {
FormattingTuple format = MessageFormatter.format(messagePattern, object);
logger.info(format.getMessage());
}
public ErrorPacketImpl errorPacket(int error, String s, Object o) {
FormattingTuple ft = MessageFormatter.format(s, o);
logger.error(ft.getMessage(), ft.getThrowable());
return getErrorPacket(ft.getMessage(), error);
}
/**
* Log a message at the WARN level according to the specified format and
* arguments.
*
* <p>
* This form avoids superfluous object creation when the logger is disabled
* for the WARN level.
* </p>
*
* @param format
* the format string
* @param arg1
* the first argument
* @param arg2
* the second argument
*/
@Override
public void warn(String format, Object arg1, Object arg2) {
if (logger.isEnabledFor(Level.WARN)) {
FormattingTuple ft = MessageFormatter.format(format, arg1, arg2);
logger.log(FQCN, Level.WARN, ft.getMessage(), ft.getThrowable());
}
}
/**
* Log a message at level FINE according to the specified format and
* arguments.
*
* <p>
* This form avoids superfluous object creation when the logger is disabled
* for the FINE level.
* </p>
*
* @param format
* the format string
* @param arg1
* the first argument
* @param arg2
* the second argument
*/
@Override
public void debug(String format, Object arg1, Object arg2) {
if (logger.isLoggable(Level.FINE)) {
FormattingTuple ft = MessageFormatter.format(format, arg1, arg2);
log(SELF, Level.FINE, ft.getMessage(), ft.getThrowable());
}
}
/**
* Delegates to the {@link Log#trace(java.lang.Object)} method of the underlying
* {@link Log} instance.
*
* <p>
* However, this form avoids superfluous object creation when the logger is disabled
* for level TRACE.
* </p>
*
* @param format
* the format string
* @param arg
* the argument
*/
@Override
public void trace(String format, Object arg) {
if (log.isTraceEnabled()) {
FormattingTuple ft = MessageFormatter.format(format, arg);
log.trace(ft.getMessage(), ft.getThrowable());
}
}
/**
* Delegates to the {@link Log#trace(java.lang.Object)} method of the underlying
* {@link Log} instance.
*
* <p>
* However, this form avoids superfluous object creation when the logger is disabled
* for level TRACE.
* </p>
*
* @param format
* the format string
* @param arg1
* the first argument
* @param arg2
* the second argument
*/
@Override
public void trace(String format, Object arg1, Object arg2) {
if (log.isTraceEnabled()) {
FormattingTuple ft = MessageFormatter.format(format, arg1, arg2);
log.trace(ft.getMessage(), ft.getThrowable());
}
}
/**
* Log a message at the WARN level according to the specified format and
* argument.
*
* <p>
* This form avoids superfluous object creation when the logger is disabled
* for the WARN level.
* </p>
*
* @param format
* the format string
* @param arg
* the argument
*/
@Override
public void warn(String format, Object arg) {
if (logger.isEnabledFor(Level.WARN)) {
FormattingTuple ft = MessageFormatter.format(format, arg);
logger.log(FQCN, Level.WARN, ft.getMessage(), ft.getThrowable());
}
}
/**
* Delegates to the {@link Log#debug(java.lang.Object)} method of the underlying
* {@link Log} instance.
*
* <p>
* However, this form avoids superfluous object creation when the logger is disabled
* for level DEBUG.
* </p>
*
* @param format
* the format string
* @param arg1
* the first argument
* @param arg2
* the second argument
*/
@Override
public void debug(String format, Object arg1, Object arg2) {
if (log.isDebugEnabled()) {
FormattingTuple ft = MessageFormatter.format(format, arg1, arg2);
log.debug(ft.getMessage(), ft.getThrowable());
}
}
/**
* Delegates to the {@link Log#info(java.lang.Object)} method of the underlying
* {@link Log} instance.
*
* <p>
* However, this form avoids superfluous object creation when the logger is disabled
* for level INFO.
* </p>
*
* @param format
* the format string
* @param arg
* the argument
*/
@Override
public void info(String format, Object arg) {
if (log.isInfoEnabled()) {
FormattingTuple ft = MessageFormatter.format(format, arg);
log.info(ft.getMessage(), ft.getThrowable());
}
}
/**
* Log a message at the ERROR level according to the specified format and
* argument.
*
* <p>
* This form avoids superfluous object creation when the logger is disabled
* for the ERROR level.
* </p>
*
* @param format
* the format string
* @param arg
* the argument
*/
@Override
public void error(String format, Object arg) {
if (logger.isEnabledFor(Level.ERROR)) {
FormattingTuple ft = MessageFormatter.format(format, arg);
logger.log(FQCN, Level.ERROR, ft.getMessage(), ft.getThrowable());
}
}
/**
* Delegates to the {@link Log#warn(java.lang.Object)} method of the underlying
* {@link Log} instance.
*
* <p>
* However, this form avoids superfluous object creation when the logger is disabled
* for level WARN.
* </p>
*
* @param format
* the format string
* @param arg
* the argument
*/
@Override
public void warn(String format, Object arg) {
if (log.isWarnEnabled()) {
FormattingTuple ft = MessageFormatter.format(format, arg);
log.warn(ft.getMessage(), ft.getThrowable());
}
}
/**
* Delegates to the {@link Log#warn(java.lang.Object)} method of the underlying
* {@link Log} instance.
*
* <p>
* However, this form avoids superfluous object creation when the logger is disabled
* for level WARN.
* </p>
*
* @param format
* the format string
* @param arg1
* the first argument
* @param arg2
* the second argument
*/
@Override
public void warn(String format, Object arg1, Object arg2) {
if (log.isWarnEnabled()) {
FormattingTuple ft = MessageFormatter.format(format, arg1, arg2);
log.warn(ft.getMessage(), ft.getThrowable());
}
}
/**
* Log a message at level INFO according to the specified format and argument.
*
* <p>
* This form avoids superfluous object creation when the logger is disabled
* for the INFO level.
* </p>
*
* @param format
* the format string
* @param arg
* the argument
*/
@Override
public void info(String format, Object arg) {
if (logger.isInfoEnabled()) {
FormattingTuple ft = MessageFormatter.format(format, arg);
logger.log(FQCN, Level.INFO, ft.getMessage(), ft.getThrowable());
}
}
/**
* Delegates to the {@link Log#error(java.lang.Object)} method of the underlying
* {@link Log} instance.
*
* <p>
* However, this form avoids superfluous object creation when the logger is disabled
* for level ERROR.
* </p>
*
* @param format
* the format string
* @param arg1
* the first argument
* @param arg2
* the second argument
*/
@Override
public void error(String format, Object arg1, Object arg2) {
if (log.isErrorEnabled()) {
FormattingTuple ft = MessageFormatter.format(format, arg1, arg2);
log.error(ft.getMessage(), ft.getThrowable());
}
}
/**
* For formatted messages, first substitute arguments and then log.
*
* @param level
* @param format
* @param arg1
* @param arg2
*/
private void formatAndLog(int level, String format, Object arg1, Object arg2) {
if (!isLevelEnabled(level)) {
return;
}
FormattingTuple tp = MessageFormatter.format(format, arg1, arg2);
log(level, tp.getMessage(), tp.getThrowable());
}
/**
* Log a message at the INFO level according to the specified format and
* arguments.
*
* <p>
* This form avoids superfluous object creation when the logger is disabled
* for the INFO level.
* </p>
*
* @param format
* the format string
* @param arg1
* the first argument
* @param arg2
* the second argument
*/
@Override
public void info(String format, Object arg1, Object arg2) {
if (logger.isInfoEnabled()) {
FormattingTuple ft = MessageFormatter.format(format, arg1, arg2);
logger.log(FQCN, Level.INFO, ft.getMessage(), ft.getThrowable());
}
}
/**
* Log a message at level TRACE according to the specified format and
* arguments.
*
* <p>
* This form avoids superfluous object creation when the logger is disabled
* for the TRACE level.
* </p>
*
* @param format
* the format string
* @param arg1
* the first argument
* @param arg2
* the second argument
*/
@Override
public void trace(String format, Object arg1, Object arg2) {
if (isTraceEnabled()) {
FormattingTuple ft = MessageFormatter.format(format, arg1, arg2);
logger.log(FQCN, traceCapable ? Level.TRACE : Level.DEBUG, ft.getMessage(), ft.getThrowable());
}
}
/**
* Log a message at level INFO according to the specified format and argument.
*
* <p>
* This form avoids superfluous object creation when the logger is disabled
* for the INFO level.
* </p>
*
* @param format
* the format string
* @param arg
* the argument
*/
@Override
public void info(String format, Object arg) {
if (logger.isLoggable(Level.INFO)) {
FormattingTuple ft = MessageFormatter.format(format, arg);
log(SELF, Level.INFO, ft.getMessage(), ft.getThrowable());
}
}
/**
* Log a message at level DEBUG according to the specified format and
* arguments.
*
* <p>
* This form avoids superfluous object creation when the logger is disabled
* for the DEBUG level.
* </p>
*
* @param format
* the format string
* @param arg1
* the first argument
* @param arg2
* the second argument
*/
@Override
public void debug(String format, Object arg1, Object arg2) {
if (logger.isDebugEnabled()) {
FormattingTuple ft = MessageFormatter.format(format, arg1, arg2);
logger.log(FQCN, Level.DEBUG, ft.getMessage(), ft.getThrowable());
}
}