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 File: TimerManager.java From storm-dynamic-spout with BSD 3-Clause "New" or "Revised" License | 7 votes |
/** * 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 File: RntbdReporter.java From azure-cosmosdb-java with MIT License | 6 votes |
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 #3
Source File: JDK14LoggerAdapter.java From HttpSessionReplacer with MIT License | 6 votes |
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 #4
Source File: Slf4jLogger.java From jboot with Apache License 2.0 | 5 votes |
@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 #5
Source File: JobLogger.java From datax-web with MIT License | 5 votes |
/** * 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 File: AbstractUserAgentAnalyzerTester.java From yauaa with Apache License 2.0 | 5 votes |
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 #7
Source File: XxlJobLogger.java From microservices-platform with Apache License 2.0 | 5 votes |
/** * 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 File: XxlJobLogger.java From zuihou-admin-boot with Apache License 2.0 | 5 votes |
/** * 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 #9
Source File: StdLogger.java From component-runtime with Apache License 2.0 | 5 votes |
@Override public void error(final String format, final Object arg) { if (!error) { return; } log("ERROR", MessageFormatter.format(format, arg).getMessage(), null, System.err); }
Example #10
Source File: StdLogger.java From component-runtime with Apache License 2.0 | 5 votes |
@Override public void warn(final String format, final Object... arguments) { if (!warn) { return; } log("WARN", MessageFormatter.arrayFormat(format, arguments).getMessage(), null, System.out); }
Example #11
Source File: StdLogger.java From component-runtime with Apache License 2.0 | 5 votes |
@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 #12
Source File: LocalizationMessage.java From PeonyFramwork with Apache License 2.0 | 5 votes |
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: StdLogger.java From component-runtime with Apache License 2.0 | 5 votes |
@Override public void debug(final String format, final Object... arguments) { if (!debug) { return; } log("DEBUG", MessageFormatter.arrayFormat(format, arguments).getMessage(), null, System.out); }
Example #14
Source File: SLF4JLogger.java From snowflake-jdbc with Apache License 2.0 | 5 votes |
public void error(String msg, Object... arguments) { if (isErrorEnabled()) { FormattingTuple ft = MessageFormatter.arrayFormat( msg, evaluateLambdaArgs(arguments)); this.error(SecretDetector.maskSecrets(ft.getMessage())); } }
Example #15
Source File: XxlJobLogger.java From xmfcn-spring-cloud with Apache License 2.0 | 5 votes |
/** * 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 #16
Source File: StdLogger.java From component-runtime with Apache License 2.0 | 5 votes |
@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 #17
Source File: StdLogger.java From component-runtime with Apache License 2.0 | 5 votes |
@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 #18
Source File: Logger.java From karate with MIT License | 5 votes |
private void formatAndAppend(String format, Object... arguments) { if (appender == null) { return; } FormattingTuple tp = MessageFormatter.arrayFormat(format, arguments); append(tp.getMessage()); }
Example #19
Source File: Slf4jLogger.java From jboot with Apache License 2.0 | 5 votes |
@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 #20
Source File: SLF4JLogger.java From snowflake-jdbc with Apache License 2.0 | 5 votes |
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 #21
Source File: LambdaLoggerPlainImpl.java From slf4j-lambda with Apache License 2.0 | 5 votes |
@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 #22
Source File: Audit.java From o2oa with GNU Affero General Public License v3.0 | 5 votes |
/** * 审计日志 * @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 #23
Source File: AuditLogServiceImpl.java From neoscada with Eclipse Public License 1.0 | 5 votes |
@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 #24
Source File: WidgetField.java From plugins with GNU General Public License v3.0 | 5 votes |
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 #25
Source File: RunningException.java From o2oa with GNU Affero General Public License v3.0 | 4 votes |
private static String format(String message, Object... os) { return MessageFormatter.arrayFormat(message, os).getMessage(); }
Example #26
Source File: Litmus.java From Quicksql with MIT License | 4 votes |
public boolean fail(String message, Object... args) { final String s = message == null ? null : MessageFormatter.arrayFormat(message, args).getMessage(); throw new AssertionError(s); }
Example #27
Source File: ClassCompiler.java From jweb-cms with GNU Affero General Public License v3.0 | 4 votes |
private String format(String field, Object... args) { return MessageFormatter.arrayFormat(field, args).getMessage(); }
Example #28
Source File: Litmus.java From Bats with Apache License 2.0 | 4 votes |
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 File: MessageLogger.java From xltsearch with Apache License 2.0 | 4 votes |
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 #30
Source File: HiveMetadataUtils.java From dremio-oss with Apache License 2.0 | 4 votes |
public static List<DatasetSplit> getDatasetSplits(TableMetadata tableMetadata, MetadataAccumulator metadataAccumulator, PartitionMetadata partitionMetadata, StatsEstimationParameters statsParams) { // This should be checked prior to entry. if (!partitionMetadata.getInputSplitBatchIterator().hasNext()) { throw UserException .dataReadError() .message("Splits expected but not available for table: '{}', partition: '{}'", tableMetadata.getTable().getTableName(), getPartitionValueLogString(partitionMetadata.getPartition())) .build(logger); } final List<InputSplit> inputSplits = partitionMetadata.getInputSplitBatchIterator().next(); if (logger.isTraceEnabled()) { if (partitionMetadata.getPartitionValues().isEmpty()) { logger.trace("Getting {} datasetSplits for default partition", inputSplits.size()); } else { logger.trace("Getting {} datasetSplits for hive partition '{}'", inputSplits.size(), getPartitionValueLogString(partitionMetadata.getPartition())); } } if (inputSplits.isEmpty()) { /** * Not possible. * currentHivePartitionMetadata.getInputSplitBatchIterator().hasNext() means inputSplits * exist. */ throw new RuntimeException( MessageFormatter.format("Table '{}', partition '{}', Splits expected but not available for table.", tableMetadata.getTable().getTableName(), getPartitionValueLogString(partitionMetadata.getPartition())) .getMessage()); } final List<DatasetSplit> datasetSplits = new ArrayList<>(inputSplits.size()); final List<Long> inputSplitSizes = getInputSplitSizes( partitionMetadata.getDatasetSplitBuildConf().getJob(), tableMetadata.getTable().getTableName(), inputSplits); final long totalSizeOfInputSplits = inputSplitSizes.stream().mapToLong(Long::longValue).sum(); final int estimatedRecordSize = tableMetadata.getBatchSchema().estimateRecordSize(statsParams.getListSizeEstimate(), statsParams.getVarFieldSizeEstimate()); metadataAccumulator.accumulateTotalBytesToScanFactor(totalSizeOfInputSplits); for (int i = 0; i < inputSplits.size(); i++) { final InputSplit inputSplit = inputSplits.get(i); final long inputSplitLength = inputSplitSizes.get(i); final long splitEstimatedRecords = findRowCountInSplit( statsParams, partitionMetadata.getDatasetSplitBuildConf().getMetastoreStats(), inputSplitLength / (double) totalSizeOfInputSplits, inputSplitLength, partitionMetadata.getDatasetSplitBuildConf().getFormat(), estimatedRecordSize); metadataAccumulator.accumulateTotalEstimatedRecords(splitEstimatedRecords); try { datasetSplits.add( DatasetSplit.of( Arrays.stream(inputSplit.getLocations()) .map((input) -> DatasetSplitAffinity.of(input, inputSplitLength)) .collect(ImmutableList.toImmutableList()), inputSplitSizes.get(i), splitEstimatedRecords, os -> os.write(buildHiveSplitXAttr(partitionMetadata.getPartitionId(), inputSplit).toByteArray()))); } catch (IOException e) { throw new RuntimeException(e); } } return datasetSplits; }