org.slf4j.helpers.FormattingTuple Java Examples

The following examples show how to use org.slf4j.helpers.FormattingTuple. 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 File: JDK14LoggerAdapter.java    From HttpSessionReplacer with 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 #2
Source File: MessageValueSupplier.java    From slf4android with MIT License 6 votes vote down vote up
@SuppressWarnings("ThrowableResultOfMethodCallIgnored")
@Override
public void append(LogRecord record, StringBuilder builder) {
    FormattingTuple formattingTuple = MessageFormatter.arrayFormat(record.getMessage(), record.getParameters());
    String message = formattingTuple.getMessage();
    Throwable throwable = formattingTuple.getThrowable();
    if (throwable != null) {
        StringWriter writer = new StringWriter(100);
        PrintWriter printWriter = new PrintWriter(writer);
        throwable.printStackTrace(printWriter);
        printWriter.flush();
        printWriter.close();
        writer.flush();
        message += " " + writer.toString();
    }
    builder.append(message);
}
 
Example #3
Source File: SLF4JLogger.java    From snowflake-jdbc with Apache License 2.0 5 votes vote down vote up
public void warn(String msg, Object... arguments)
{
  if (isWarnEnabled())
  {
    FormattingTuple ft = MessageFormatter.arrayFormat(
        msg, evaluateLambdaArgs(arguments));
    this.warn(SecretDetector.maskSecrets(ft.getMessage()));
  }
}
 
Example #4
Source File: MessageLogger.java    From xltsearch with Apache License 2.0 5 votes vote down vote up
private void add(Message.Level level, FormattingTuple tp) {
    if (tp.getThrowable() == null) {
        add(level, tp.getMessage());
    } else {
        add(level, tp.getMessage(), tp.getThrowable());
    }
}
 
Example #5
Source File: SLF4JLogger.java    From snowflake-jdbc with Apache License 2.0 5 votes vote down vote up
public void info(String msg, Object... arguments)
{
  if (isInfoEnabled())
  {
    FormattingTuple ft = MessageFormatter.arrayFormat(
        msg, evaluateLambdaArgs(arguments));
    this.info(SecretDetector.maskSecrets(ft.getMessage()));
  }
}
 
Example #6
Source File: SimpleLogger.java    From JDA with Apache License 2.0 5 votes vote down vote up
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());
}
 
Example #7
Source File: JavaLoggerFacade.java    From eclair with Apache License 2.0 5 votes vote down vote up
@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);
}
 
Example #8
Source File: Slf4jLogger.java    From jboot with Apache License 2.0 5 votes vote down vote up
@Override
public void debug(String format, Object... args) {
    if (isDebugEnabled()) {
        FormattingTuple ft = MessageFormatter.arrayFormat(format, args);
        log.log(null, callerFQCN, LocationAwareLogger.DEBUG_INT, ft.getMessage(), NULL_ARGS, ft.getThrowable());
    }
}
 
Example #9
Source File: XxlJobLogger.java    From zuihou-admin-cloud with 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 #10
Source File: LoggerForMavenLog.java    From deadcode4j with Apache License 2.0 5 votes vote down vote up
@SuppressWarnings("ThrowableResultOfMethodCallIgnored")
private void doWarn(FormattingTuple tuple) {
    if (tuple.getThrowable() == null) {
        log.warn(tuple.getMessage());
    } else {
        log.warn(tuple.getMessage(), tuple.getThrowable());
    }
}
 
Example #11
Source File: XxlJobLogger.java    From xmfcn-spring-cloud with 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 #12
Source File: LocalizationMessage.java    From PeonyFramwork with 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 #13
Source File: Slf4jLogger.java    From jboot with Apache License 2.0 5 votes vote down vote up
@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());
    }
}
 
Example #14
Source File: EventExample.java    From velocity-engine with Apache License 2.0 5 votes vote down vote up
/**
 * This prints the level and formatted message to
 * System.out.
 */
public void formatAndLog(int level, String format, Object... arguments)
{
    if (logOutput)
    {
        FormattingTuple tp = MessageFormatter.arrayFormat(format, arguments);
        log(level, tp.getMessage());
    }
}
 
Example #15
Source File: Slf4jLogger.java    From jboot with Apache License 2.0 5 votes vote down vote up
@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());
    }
}
 
Example #16
Source File: Slf4jSimpleLogger.java    From jboot with 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.error(format, args);
    }
}
 
Example #17
Source File: Logger.java    From karate with 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 File: Slf4jLogger.java    From jboot with 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 #19
Source File: XxlJobLogger.java    From zuihou-admin-boot with 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 #20
Source File: XxlJobLogger.java    From microservices-platform with 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 #21
Source File: LogFXLogger.java    From LogFX with GNU General Public License v3.0 5 votes vote down vote up
private void formatAndLog( LogLevel logLevel, String format, Object... arguments ) {
    if ( !LogFXLogFactory.INSTANCE.isLogLevelEnabled( logLevel ) ) {
        return;
    }

    FormattingTuple tp = MessageFormatter.arrayFormat( format, arguments );
    log( logLevel, tp.getMessage(), tp.getThrowable() );
}
 
Example #22
Source File: XxlJobLogger.java    From xxl-job with GNU General Public License v3.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 #23
Source File: SLF4JLogger.java    From snowflake-jdbc with 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 #24
Source File: MockLogger.java    From velocity-tools with Apache License 2.0 4 votes vote down vote up
public void error(String format, Object[] argArray)
{
    FormattingTuple ft = MessageFormatter.arrayFormat(format, argArray);
    log(LOG_LEVEL_ERROR, ft.getMessage(), ft.getThrowable());
}
 
Example #25
Source File: TestLogger.java    From velocity-engine with Apache License 2.0 4 votes vote down vote up
public void info(String format, Object[] argArray)
{
    FormattingTuple ft = MessageFormatter.arrayFormat(format, argArray);
    log(LOG_LEVEL_INFO, ft.getMessage(), ft.getThrowable());
}
 
Example #26
Source File: TestLogger.java    From velocity-engine with Apache License 2.0 4 votes vote down vote up
public void warn(String format, Object arg1, Object arg2)
{
    FormattingTuple ft = MessageFormatter.format(format, arg1, arg2);
    log(LOG_LEVEL_WARN, ft.getMessage(), ft.getThrowable());
}
 
Example #27
Source File: MockLogger.java    From velocity-tools with Apache License 2.0 4 votes vote down vote up
public void info(String format, Object arg1, Object arg2)
{
    FormattingTuple ft = MessageFormatter.format(format, arg1, arg2);
    log(LOG_LEVEL_INFO, ft.getMessage(), ft.getThrowable());
}
 
Example #28
Source File: MockLogger.java    From velocity-tools with Apache License 2.0 4 votes vote down vote up
public void warn(String format, Object arg1, Object arg2)
{
    FormattingTuple ft = MessageFormatter.format(format, arg1, arg2);
    log(LOG_LEVEL_WARN, ft.getMessage(), ft.getThrowable());
}
 
Example #29
Source File: MockLogger.java    From velocity-tools with Apache License 2.0 4 votes vote down vote up
public void trace(String format, Object[] argArray)
{
    FormattingTuple ft = MessageFormatter.arrayFormat(format, argArray);
    log(LOG_LEVEL_TRACE, ft.getMessage(), ft.getThrowable());
}
 
Example #30
Source File: LoggerImpl.java    From godaddy-logger with MIT License 4 votes vote down vote up
@Override
public void error(Throwable t, String format, Object... args) {
    FormattingTuple ft = MessageFormatter.arrayFormat(format, args);
    root.error(formatMessage(getMessage(ft.getMessage())), t);
}