org.slf4j.helpers.MessageFormatter Java Examples

The following examples show how to use org.slf4j.helpers.MessageFormatter. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source Project: storm-dynamic-spout   Author: salesforce   File: TimerManager.java    License: BSD 3-Clause "New" or "Revised" License 7 votes vote down vote up
/**
 * 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;
}
 
Example #2
Source Project: HttpSessionReplacer   Author: AmadeusITGroup   File: JDK14LoggerAdapter.java    License: MIT License 6 votes vote down vote up
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;
}
 
Example #3
Source Project: azure-cosmosdb-java   Author: Azure   File: RntbdReporter.java    License: MIT License 6 votes vote down vote up
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)
            );
        }
    }
 
Example #4
Source Project: plugins   Author: open-osrs   File: WidgetField.java    License: GNU General Public License v3.0 5 votes vote down vote up
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();
}
 
Example #5
Source Project: datax-web   Author: WeiYe-Jing   File: JobLogger.java    License: MIT License 5 votes vote down vote up
/**
 * 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);
}
 
Example #6
Source Project: microservices-platform   Author: zlt2000   File: XxlJobLogger.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * 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);
}
 
Example #7
Source Project: zuihou-admin-boot   Author: zuihou   File: XxlJobLogger.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * 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);
}
 
Example #8
Source Project: PeonyFramwork   Author: xuerong   File: LocalizationMessage.java    License: Apache License 2.0 5 votes vote down vote up
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();
}
 
Example #9
Source Project: snowflake-jdbc   Author: snowflakedb   File: SLF4JLogger.java    License: Apache License 2.0 5 votes vote down vote up
public void error(String msg, Object... arguments)
{
  if (isErrorEnabled())
  {
    FormattingTuple ft = MessageFormatter.arrayFormat(
        msg, evaluateLambdaArgs(arguments));
    this.error(SecretDetector.maskSecrets(ft.getMessage()));
  }
}
 
Example #10
Source Project: xmfcn-spring-cloud   Author: airufei   File: XxlJobLogger.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * 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);
}
 
Example #11
Source Project: slf4j-lambda   Author: kwon37xi   File: LambdaLoggerPlainImpl.java    License: Apache License 2.0 5 votes vote down vote up
@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());
    }
}
 
Example #12
Source Project: o2oa   Author: o2oa   File: Audit.java    License: GNU Affero General Public License v3.0 5 votes vote down vote up
/**
 * 审计日志
 * @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());
	}
}
 
Example #13
Source Project: neoscada   Author: eclipse   File: AuditLogServiceImpl.java    License: Eclipse Public License 1.0 5 votes vote down vote up
@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 );
    }
}
 
Example #14
Source Project: jboot   Author: yangfuhai   File: Slf4jLogger.java    License: Apache License 2.0 5 votes vote down vote up
@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());
    }
}
 
Example #15
Source Project: snowflake-jdbc   Author: snowflakedb   File: SLF4JLogger.java    License: Apache License 2.0 5 votes vote down vote up
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()));
  }
}
 
Example #16
Source Project: jboot   Author: yangfuhai   File: Slf4jLogger.java    License: Apache License 2.0 5 votes vote down vote up
@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());
    }
}
 
Example #17
Source Project: karate   Author: intuit   File: Logger.java    License: MIT License 5 votes vote down vote up
private void formatAndAppend(String format, Object... arguments) {
    if (appender == null) {
        return;
    }
    FormattingTuple tp = MessageFormatter.arrayFormat(format, arguments);
    append(tp.getMessage());
}
 
Example #18
Source Project: component-runtime   Author: Talend   File: StdLogger.java    License: Apache License 2.0 5 votes vote down vote up
@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);
}
 
Example #19
Source Project: component-runtime   Author: Talend   File: StdLogger.java    License: Apache License 2.0 5 votes vote down vote up
@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);
}
 
Example #20
Source Project: component-runtime   Author: Talend   File: StdLogger.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public void debug(final String format, final Object... arguments) {
    if (!debug) {
        return;
    }
    log("DEBUG", MessageFormatter.arrayFormat(format, arguments).getMessage(), null, System.out);
}
 
Example #21
Source Project: component-runtime   Author: Talend   File: StdLogger.java    License: Apache License 2.0 5 votes vote down vote up
@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);
}
 
Example #22
Source Project: yauaa   Author: nielsbasjes   File: AbstractUserAgentAnalyzerTester.java    License: Apache License 2.0 5 votes vote down vote up
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');
        }
    }
}
 
Example #23
Source Project: component-runtime   Author: Talend   File: StdLogger.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public void warn(final String format, final Object... arguments) {
    if (!warn) {
        return;
    }
    log("WARN", MessageFormatter.arrayFormat(format, arguments).getMessage(), null, System.out);
}
 
Example #24
Source Project: component-runtime   Author: Talend   File: StdLogger.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public void error(final String format, final Object arg) {
    if (!error) {
        return;
    }
    log("ERROR", MessageFormatter.format(format, arg).getMessage(), null, System.err);
}
 
Example #25
Source Project: wind-im   Author: WindChat   File: LogUtils.java    License: Apache License 2.0 4 votes vote down vote up
public static void info(org.apache.log4j.Logger logger, String messagePattern, Object object) {
	FormattingTuple format = MessageFormatter.format(messagePattern, object);
	logger.info(format.getMessage());
}
 
Example #26
Source Project: xltsearch   Author: alvanson   File: MessageLogger.java    License: Apache License 2.0 4 votes vote down vote up
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));
    }
}
 
Example #27
Source Project: Bats   Author: lealone   File: Litmus.java    License: Apache License 2.0 4 votes vote down vote up
public boolean fail(String message, Object... args) {
  final String s = message == null
      ? null : MessageFormatter.arrayFormat(message, args).getMessage();
  throw new AssertionError(s);
}
 
Example #28
Source Project: Quicksql   Author: Qihoo360   File: Litmus.java    License: MIT License 4 votes vote down vote up
public boolean fail(String message, Object... args) {
  final String s = message == null
      ? null : MessageFormatter.arrayFormat(message, args).getMessage();
  throw new AssertionError(s);
}
 
Example #29
Source Project: excel-boot   Author: programmeres   File: ExcelBootException.java    License: Artistic License 2.0 4 votes vote down vote up
public ExcelBootException(String format, Object... arguments) {
    super(MessageFormatter.arrayFormat(format, arguments).getMessage());
}
 
Example #30
Source Project: tracing-framework   Author: brownsys   File: Slf4jLoggerWrapper.java    License: BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
/** Format an slf4j message */
public String format(String str, Object... objs) {
    return MessageFormatter.format(str, objs).getMessage();
}