下面列出了org.slf4j.helpers.MessageFormatter#arrayFormat ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
@Override
public void error(String format, Object... args) {
if (isErrorEnabled()) {
FormattingTuple ft = MessageFormatter.arrayFormat(format, args);
JbootExceptionHolder.hold(ft.getMessage(), ft.getThrowable());
log.log(null, callerFQCN, LocationAwareLogger.ERROR_INT, ft.getMessage(), NULL_ARGS, ft.getThrowable());
}
}
/**
* append log with pattern
*
* @param appendLogPattern like "aaa {} bbb {} ccc"
* @param appendLogArguments like "111, true"
*/
public static void log(String appendLogPattern, Object... appendLogArguments) {
FormattingTuple ft = MessageFormatter.arrayFormat(appendLogPattern, appendLogArguments);
String appendLog = ft.getMessage();
/*appendLog = appendLogPattern;
if (appendLogArguments!=null && appendLogArguments.length>0) {
appendLog = MessageFormat.format(appendLogPattern, appendLogArguments);
}*/
StackTraceElement callInfo = new Throwable().getStackTrace()[1];
logDetail(callInfo, appendLog);
}
@Override
public void error(String format, Object... args) {
if (isErrorEnabled()) {
FormattingTuple ft = MessageFormatter.arrayFormat(format, args);
JbootExceptionHolder.hold(ft.getMessage(), ft.getThrowable());
log.error(format, args);
}
}
/**
* append log with pattern
*
* @param appendLogPattern like "aaa {} bbb {} ccc"
* @param appendLogArguments like "111, true"
*/
public static void log(String appendLogPattern, Object... appendLogArguments) {
FormattingTuple ft = MessageFormatter.arrayFormat(appendLogPattern, appendLogArguments);
String appendLog = ft.getMessage();
/*appendLog = appendLogPattern;
if (appendLogArguments!=null && appendLogArguments.length>0) {
appendLog = MessageFormat.format(appendLogPattern, appendLogArguments);
}*/
StackTraceElement callInfo = new Throwable().getStackTrace()[1];
logDetail(callInfo, appendLog);
}
public void error(String msg, Object... arguments)
{
if (isErrorEnabled())
{
FormattingTuple ft = MessageFormatter.arrayFormat(
msg, evaluateLambdaArgs(arguments));
this.error(SecretDetector.maskSecrets(ft.getMessage()));
}
}
@Override
public void doLog(Marker marker, Level level, String format, Supplier<?>[] argSuppliers, Throwable t) {
if (!LambdaLoggerUtils.isLogLevelEnabled(underlyingLogger, level, marker)) {
return;
}
if (argSuppliers == null) {
logFormatted(marker, level, format, t);
} else {
FormattingTuple formattingTuple = MessageFormatter.arrayFormat(format, argSuppliersToArgs(argSuppliers), t);
logFormatted(marker, level, formattingTuple.getMessage(), formattingTuple.getThrowable());
}
}
@Override
public void info(String format, Object... args) {
if (isInfoEnabled()) {
FormattingTuple ft = MessageFormatter.arrayFormat(format, args);
log.log(null, callerFQCN, LocationAwareLogger.INFO_INT, ft.getMessage(), NULL_ARGS, ft.getThrowable());
}
}
public void debug(String msg, Object... arguments)
{
// use this as format example for JDK14Logger.
if (isDebugEnabled())
{
FormattingTuple ft = MessageFormatter.arrayFormat(
msg, evaluateLambdaArgs(arguments));
this.debug(SecretDetector.maskSecrets(ft.getMessage()));
}
}
@Override
public void warn(String format, Object... args) {
if (isWarnEnabled()) {
FormattingTuple ft = MessageFormatter.arrayFormat(format, args);
log.log(null, callerFQCN, LocationAwareLogger.WARN_INT, ft.getMessage(), NULL_ARGS, ft.getThrowable());
}
}
public void trace(String msg, Object... arguments)
{
if (isTraceEnabled())
{
FormattingTuple ft = MessageFormatter.arrayFormat(
msg, evaluateLambdaArgs(arguments));
this.trace(SecretDetector.maskSecrets(ft.getMessage()));
}
}
@Override
public void log(LogLevel level, String format, Object... arguments) {
FormattingTuple formattingTuple = MessageFormatter.arrayFormat(format, arguments);
String message = formattingTuple.getMessage();
Throwable throwable = formattingTuple.getThrowable();
logger.log(LEVELS.get(level), message, throwable);
}
public static void dbDebugLog(Logger logger, long startTime, Object result, String sql, Object... objects) {
String messagePattern = sql.replace("?", "{}");
FormattingTuple format = MessageFormatter.arrayFormat(messagePattern, objects);
logger.debug("[openzaly-db] cost:{}ms result:{} sql:{}", System.currentTimeMillis() - startTime, result,
format.getMessage());
}
public static void info(org.apache.log4j.Logger logger, String messagePattern, Object... objects) {
FormattingTuple format = MessageFormatter.arrayFormat(messagePattern, objects);
logger.info(format.getMessage());
}
/**
* Log a message at level WARNING according to the specified format and
* arguments.
*
* <p>
* This form avoids superfluous object creation when the logger is disabled
* for the WARNING level.
* </p>
*
* @param format
* the format string
* @param argArray
* an array of arguments
*/
@Override
public void warn(String format, Object... argArray) {
if (logger.isLoggable(Level.WARNING)) {
FormattingTuple ft = MessageFormatter.arrayFormat(format, argArray);
log(SELF, Level.WARNING, 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 arguments a list of 3 or more arguments
*/
@Override
public void trace(String format, Object... arguments) {
if (log.isTraceEnabled()) {
FormattingTuple ft = MessageFormatter.arrayFormat(format, arguments);
log.trace(ft.getMessage(), ft.getThrowable());
}
}
/**
* Log a message at level WARN 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 argArray
* an array of arguments
*/
@Override
public void warn(String format, Object... argArray) {
if (logger.isEnabledFor(Level.WARN)) {
FormattingTuple ft = MessageFormatter.arrayFormat(format, argArray);
logger.log(FQCN, Level.WARN, ft.getMessage(), ft.getThrowable());
}
}
/**
* Log a message at level INFO 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 argArray
* an array of arguments
*/
@Override
public void info(String format, Object... argArray) {
if (logger.isInfoEnabled()) {
FormattingTuple ft = MessageFormatter.arrayFormat(format, argArray);
logger.log(FQCN, Level.INFO, ft.getMessage(), ft.getThrowable());
}
}
/**
* Log a message at level SEVERE according to the specified format and
* arguments.
*
* <p>
* This form avoids superfluous object creation when the logger is disabled
* for the SEVERE level.
* </p>
*
* @param format
* the format string
* @param arguments
* an array of arguments
*/
@Override
public void error(String format, Object... arguments) {
if (logger.isLoggable(Level.SEVERE)) {
FormattingTuple ft = MessageFormatter.arrayFormat(format, arguments);
log(SELF, Level.SEVERE, 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 arguments a list of 3 or more arguments
*/
@Override
public void debug(String format, Object... arguments) {
if (log.isDebugEnabled()) {
FormattingTuple ft = MessageFormatter.arrayFormat(format, arguments);
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 arguments a list of 3 or more arguments
*/
@Override
public void info(String format, Object... arguments) {
if (log.isInfoEnabled()) {
FormattingTuple ft = MessageFormatter.arrayFormat(format, arguments);
log.info(ft.getMessage(), ft.getThrowable());
}
}