org.slf4j.helpers.MessageFormatter源码实例Demo

类org.slf4j.helpers.MessageFormatter源码实例Demo

下面列出了org.slf4j.helpers.MessageFormatter 类实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

源代码1 项目: storm-dynamic-spout   文件: TimerManager.java
/**
 * Stop a timer based upon a provided key.
 *
 * @param key key for timer
 * @return time elapsed in millis
 */
long stop(final String key) {
    if (key == null || key.isEmpty()) {
        throw new IllegalArgumentException(
            "Timer key cannot be null or empty."
        );
    }
    if (!startValuesMs.containsKey(key)) {
        throw new IllegalStateException(
            MessageFormatter.format("The timer key {} does not exist in this instance of {}", key, getClass().toString()).getMessage()
        );
    }

    // This gets the value and then removes it, so we could in theory start this key again with a fresh timer
    final long startTimeMs = startValuesMs.remove(key);
    final long stopTimeMs = getClock().millis();

    return stopTimeMs - startTimeMs;
}
 
源代码2 项目: HttpSessionReplacer   文件: JDK14LoggerAdapter.java
private LogRecord eventToRecord(LoggingEvent event, Level julLevel) {
    String format = event.getMessage();
    Object[] arguments = event.getArgumentArray();
    FormattingTuple ft = MessageFormatter.arrayFormat(format, arguments);
    if (ft.getThrowable() != null && event.getThrowable() != null) {
        throw new IllegalArgumentException("both last element in argument array and last argument are of type Throwable");
    }

    Throwable t = event.getThrowable();
    if (ft.getThrowable() != null) {
        t = ft.getThrowable();
        throw new IllegalStateException("fix above code");
    }

    LogRecord record = new LogRecord(julLevel, ft.getMessage());
    record.setLoggerName(event.getLoggerName());
    record.setMillis(event.getTimeStamp());
    record.setSourceClassName(EventConstants.NA_SUBST);
    record.setSourceMethodName(EventConstants.NA_SUBST);

    record.setThrown(t);
    return record;
}
 
源代码3 项目: azure-cosmosdb-java   文件: RntbdReporter.java
private static void doReportIssue(Logger logger, Object subject, String format, Object[] arguments) {

        FormattingTuple formattingTuple = MessageFormatter.arrayFormat(format, arguments);
        StackTraceElement[] stackTrace = new Exception().getStackTrace();
        Throwable throwable = formattingTuple.getThrowable();

        if (throwable == null) {
            logger.error("Report this {} issue to ensure it is addressed:\n[{}]\n[{}]\n[{}]",
                codeSource, subject, stackTrace[2], formattingTuple.getMessage()
            );
        } else {
            logger.error("Report this {} issue to ensure it is addressed:\n[{}]\n[{}]\n[{}{}]",
                codeSource, subject, stackTrace[2], formattingTuple.getMessage(),
                ExceptionUtils.getStackTrace(throwable)
            );
        }
    }
 
源代码4 项目: plugins   文件: WidgetField.java
Object getValue(Widget widget)
{
	Object value = getter.apply(widget);
	// These types are handled by the JTable automatically
	if (value instanceof Boolean || value instanceof Number || value instanceof String)
	{
		return value;
	}
	return MessageFormatter.format("{}", value).getMessage();
}
 
源代码5 项目: datax-web   文件: JobLogger.java
/**
 * 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);
}
 
源代码6 项目: microservices-platform   文件: XxlJobLogger.java
/**
 * 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);
}
 
源代码7 项目: zuihou-admin-boot   文件: XxlJobLogger.java
/**
 * 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);
}
 
源代码8 项目: PeonyFramwork   文件: LocalizationMessage.java
public static String getText(String key,Object... args){
    String localization = threadLocalization.get();
    if(localization == null){
        log.warn("localization is not in threadLocalization,check it !");
        localization = DefaultLocalization;
    }
    Properties properties = messages.get(localization);
    if(properties == null){
        properties = messages.get(DefaultLocalization);
    }
    FormattingTuple formattingTuple = MessageFormatter.arrayFormat(properties.getProperty(key),args);
    return formattingTuple.getMessage();
}
 
源代码9 项目: snowflake-jdbc   文件: SLF4JLogger.java
public void error(String msg, Object... arguments)
{
  if (isErrorEnabled())
  {
    FormattingTuple ft = MessageFormatter.arrayFormat(
        msg, evaluateLambdaArgs(arguments));
    this.error(SecretDetector.maskSecrets(ft.getMessage()));
  }
}
 
源代码10 项目: xmfcn-spring-cloud   文件: XxlJobLogger.java
/**
 * 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);
}
 
源代码11 项目: slf4j-lambda   文件: LambdaLoggerPlainImpl.java
@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());
    }
}
 
源代码12 项目: o2oa   文件: Audit.java
/**
 * 审计日志
 * @param message
 * @param os
 * @throws Exception
 */
public void log1(String message, Object... os){
	try {
		if (Config.logLevel().audit().enable()) {
			Date end = new Date();
			long elapsed = end.getTime() - start.getTime();
			PrintStream stream = (PrintStream) Config.resource(Config.RESOURCE_AUDITLOGPRINTSTREAM);
			stream.printf("%tF %tT,,,%d,,,%s,,,%s,,,%s,,,%s,,,%s,,,%s%n", end, end, elapsed, this.person,
					this.remoteAddress, this.uri, this.userAgent, this.className,
					MessageFormatter.arrayFormat(Objects.toString(message, ""), os).getMessage());
		}
	} catch (Exception e) {
		System.out.println("审计日志打印异常"+e.getMessage());
	}
}
 
源代码13 项目: neoscada   文件: AuditLogServiceImpl.java
@Override
public void debug ( final String message, final Object... arguments )
{
    if ( Boolean.getBoolean ( PROP_ENABLE_DEBUG ) )
    {
        log ( Severity.INFORMATION, MessageFormatter.arrayFormat ( message, arguments ).getMessage (), null );
    }
}
 
源代码14 项目: jboot   文件: Slf4jLogger.java
@Override
public void trace(String format, Object... args) {
    if (isTraceEnabled()) {
        FormattingTuple ft = MessageFormatter.arrayFormat(format, args);
        log.log(null, callerFQCN, LocationAwareLogger.TRACE_INT, ft.getMessage(), NULL_ARGS, ft.getThrowable());
    }
}
 
源代码15 项目: snowflake-jdbc   文件: SLF4JLogger.java
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()));
  }
}
 
源代码16 项目: jboot   文件: Slf4jLogger.java
@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());
    }
}
 
源代码17 项目: karate   文件: Logger.java
private void formatAndAppend(String format, Object... arguments) {
    if (appender == null) {
        return;
    }
    FormattingTuple tp = MessageFormatter.arrayFormat(format, arguments);
    append(tp.getMessage());
}
 
源代码18 项目: component-runtime   文件: StdLogger.java
@Override
public void trace(final String format, final Object arg1, final Object arg2) {
    if (!trace) {
        return;
    }
    log("TRACE", MessageFormatter.format(format, arg1, arg1).getMessage(), null, System.out);
}
 
源代码19 项目: component-runtime   文件: StdLogger.java
@Override
public void debug(final String format, final Object arg1, final Object arg2) {
    if (!debug) {
        return;
    }
    log("DEBUG", MessageFormatter.format(format, arg1, arg1).getMessage(), null, System.out);
}
 
源代码20 项目: component-runtime   文件: StdLogger.java
@Override
public void debug(final String format, final Object... arguments) {
    if (!debug) {
        return;
    }
    log("DEBUG", MessageFormatter.arrayFormat(format, arguments).getMessage(), null, System.out);
}
 
源代码21 项目: component-runtime   文件: StdLogger.java
@Override
public void info(final String format, final Object arg1, final Object arg2) {
    if (!info) {
        return;
    }
    log("INFO", MessageFormatter.format(format, arg1, arg1).getMessage(), null, System.out);
}
 
源代码22 项目: yauaa   文件: AbstractUserAgentAnalyzerTester.java
private void logWarn(StringBuilder errorMessageReceiver, String format, Object... args) {
    if (LOG.isWarnEnabled()) {
        final String message = MessageFormatter.arrayFormat(format, args).getMessage();
        LOG.warn(message, args);
        if (errorMessageReceiver != null) {
            errorMessageReceiver.append(message).append('\n');
        }
    }
}
 
源代码23 项目: component-runtime   文件: StdLogger.java
@Override
public void warn(final String format, final Object... arguments) {
    if (!warn) {
        return;
    }
    log("WARN", MessageFormatter.arrayFormat(format, arguments).getMessage(), null, System.out);
}
 
源代码24 项目: component-runtime   文件: StdLogger.java
@Override
public void error(final String format, final Object arg) {
    if (!error) {
        return;
    }
    log("ERROR", MessageFormatter.format(format, arg).getMessage(), null, System.err);
}
 
源代码25 项目: wind-im   文件: LogUtils.java
public static void info(org.apache.log4j.Logger logger, String messagePattern, Object object) {
	FormattingTuple format = MessageFormatter.format(messagePattern, object);
	logger.info(format.getMessage());
}
 
源代码26 项目: xltsearch   文件: MessageLogger.java
private void log(Message.Level level, String format, Object... arguments) {
    level = relevel(level);
    if (level.compareTo(logLevel.get()) >= 0) {
        add(level, MessageFormatter.arrayFormat(format, arguments));
    }
}
 
源代码27 项目: Bats   文件: Litmus.java
public boolean fail(String message, Object... args) {
  final String s = message == null
      ? null : MessageFormatter.arrayFormat(message, args).getMessage();
  throw new AssertionError(s);
}
 
源代码28 项目: Quicksql   文件: Litmus.java
public boolean fail(String message, Object... args) {
  final String s = message == null
      ? null : MessageFormatter.arrayFormat(message, args).getMessage();
  throw new AssertionError(s);
}
 
源代码29 项目: excel-boot   文件: ExcelBootException.java
public ExcelBootException(String format, Object... arguments) {
    super(MessageFormatter.arrayFormat(format, arguments).getMessage());
}
 
源代码30 项目: tracing-framework   文件: Slf4jLoggerWrapper.java
/** Format an slf4j message */
public String format(String str, Object... objs) {
    return MessageFormatter.format(str, objs).getMessage();
}