Java 类org.slf4j.helpers.MessageFormatter 实例源码
项目:ping
文件:I18nMessageConverter.java
@Override
public String convert (ILoggingEvent event) {
val key = event.getMessage();
if (!BUNDLE.containsKey(key)) {
return event.getFormattedMessage();
}
val messagePattern = BUNDLE.getString(key);
val argumentArray = event.getArgumentArray();
return MessageFormatter
.arrayFormat(messagePattern, argumentArray)
.getMessage();
}
项目:storm-dynamic-spout
文件:StormRecorder.java
/**
* Internal utility class to help generate metric keys.
*
* @return in format of: "className.metricPrefix.metricName"
*/
private String generateKey(final MetricDefinition metric, final Object[] parameters) {
final StringBuilder keyBuilder = new StringBuilder();
// Conditionally add key prefix.
if (getMetricPrefix() != null && !getMetricPrefix().isEmpty()) {
keyBuilder
.append(getMetricPrefix())
.append(".");
}
// Our default implementation should include the simple class name in the key
keyBuilder.append(
MessageFormatter.format(metric.getKey(), parameters).getMessage()
);
return keyBuilder.toString();
}
项目:game
文件:CacheEngineImpl.java
@Override
public T unique(String indexName, Object indexValue) {
ConcurrentMap<Object, PK> indexMap = uniqueCacheMap.get(indexName);
if (indexMap == null) {
String message = MessageFormatter
.format("实体[{}]不存在唯一索引[{}]", cacheDefinition.getClz().getSimpleName(), indexName).getMessage();
log.error(message);
return null;
}
PK id = indexMap.get(indexValue);
if (id != null) {
return load(id);
}
Lock lock = getPKLocked(id);
try {
id = indexMap.get(indexValue);
if (id != null) {
return load(id);
}
idLocks.remove(id);
} finally {
lock.unlock();
}
return null;
}
项目:game
文件:CacheManager.java
@SuppressWarnings({ "rawtypes", "unchecked" })
@PostConstruct
void postConstruct() {
init();
cacheThreadCount = cacheThreadCount == 0 ? DEFAULT_CACHE_THREAD_COUNT : cacheThreadCount;
executor = Executors.newScheduledThreadPool(cacheThreadCount,
new CustomizableThreadFactory("Recache-Cache-Thread-"));
for (CacheDefinition<?> definition : cacheDefinitions.values()) {
try {
definition.setEnhanceClz(EnhanceUtil.createEnhanceEntity(definition));
} catch (Exception e) {
String message = MessageFormatter.format("创建[{}]类的增强类出现异常", definition.getClz()).getMessage();
log.error(message, e);
throw new RuntimeException(message, e);
}
CacheEngineImpl cacheEngineImpl = new CacheEngineImpl(accessor, definition, persisterService, executor);
cacheEngines.put(definition.getClz(), cacheEngineImpl);
}
}
项目:game
文件:NioServerBeanDefinitionParser.java
public String checkAndFindFileUrl(Class<?> clz, List<String> dynamicSource) {
String result = null;
for (String absFileNames : dynamicSource) {
File file = new File(absFileNames);
if (StringUtils.stripFilenameExtension(file.getName()).equals(clz.getSimpleName())) {
result = absFileNames;
}
}
if (result == null) {
String message = MessageFormatter.format("无法找到动态Bean[{}]对应的源文件", clz).getMessage();
log.error(message);
throw new RuntimeException(message);
}
dynamicSource.remove(result);
return "file:" + result;
}
项目:game
文件:ExcelReader.java
private Map<Integer, String> getInterestServerRowDetail(Row row, Class<?> clz) {
Map<Integer, String> interestServerRowDetail = new LinkedHashMap<Integer, String>();
Map<Integer, String> serverRowDetail = getServerRowDetail(row);
for (Entry<Integer, String> entry : serverRowDetail.entrySet()) {
if (ReflectionUtils.findField(clz, entry.getValue()) == null) {
if (getDebug().isIgnoreAbsent()) {
continue;
}
String message = MessageFormatter.format("[{}]对应的资源中存在多余的[{}]属性", clz.getName(), entry.getValue())
.getMessage();
log.error(message);
throw new ResourceFormatException(message);
}
interestServerRowDetail.put(entry.getKey(), entry.getValue());
}
return interestServerRowDetail;
}
项目:coordinated-entry
文件:MatchProcessLogServiceImpl.java
public void log(String messageId, Object[] args, boolean status, UUID housingUnitId, UUID projectId,
UUID clientId) {
FormattingTuple tp = null;
try {
tp = MessageFormatter.arrayFormat(env.getProperty(messageId), args);
} catch (Exception e) {
tp = MessageFormatter.arrayFormat("Message foormat tewst {} with tuple {}", new Object[] { "param1" });
}
MatchProcessLogEntity entity = new MatchProcessLogEntity();
entity.setClientId(clientId);
entity.setHousingUnitId(housingUnitId);
entity.setProjectId(projectId);
entity.setStatus(status);
entity.setStatusMessage(tp.getMessage());
entity.setProcessId(this.processId);
logRepository.save(entity);
}
项目:game
文件:Storage.java
/**
* 获取到id对应的值
*
* @param k
* @return
*/
public V getValue(K k, boolean isThrow) {
Assert.notNull(k);
V v = null;
readLock.lock();
try {
v = values.get(k);
if (v == null && isThrow) {
String message = MessageFormatter
.format("无法找到[{}]中id为[{}]对应的资源", resourceDefinition.getClz().getSimpleName(), k).getMessage();
log.error(message);
throw new RuntimeException(message);
}
} finally {
readLock.unlock();
}
return v;
}
项目:game
文件:Storage.java
public List<V> getValues(List<K> ks, boolean isThrow) {
Assert.notNull(ks);
List<V> vs = new ArrayList<V>();
readLock.lock();
try {
for (K k : ks) {
V v = values.get(k);
if (v == null && isThrow) {
String message = MessageFormatter
.format("无法找到[{}]中id为[{}]对应的资源", resourceDefinition.getClz().getSimpleName(), k)
.getMessage();
log.error(message);
throw new RuntimeException(message);
} else {
vs.add(v);
}
}
} finally {
readLock.unlock();
}
return vs;
}
项目:coordinated-entry
文件:MatchProcessLogger.java
public void log(String messageId, Object[] args, boolean status, UUID housingUnitId, UUID projectId,
UUID clientId) {
FormattingTuple tp = null;
try {
tp = MessageFormatter.arrayFormat(env.getProperty(messageId), args);
System.out.println(" Message "+messageId+" test message "+tp.getMessage()+" test");
if(env.getProperty(messageId).isEmpty()) System.out.println("Empty property");
} catch (Exception e) {
System.out.println("Exception message property "+messageId);
tp = MessageFormatter.arrayFormat("Message foormat tewst {} with tuple {}", new Object[] { "param1" });
}
MatchProcessLogEntity entity = new MatchProcessLogEntity();
entity.setClientId(clientId);
entity.setHousingUnitId(housingUnitId);
entity.setProjectId(projectId);
entity.setStatus(status);
entity.setStatusMessage(tp.getMessage());
entity.setProcessId(this.processId);
logRepository.save(entity);
}
项目: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());
}
}
项目:slf4j-lambda
文件:LambdaLoggerPlainImpl.java
@Override
public void doLog(Marker marker, Level level, String format, Object[] arguments, Throwable t) {
if (!LambdaLoggerUtils.isLogLevelEnabled(underlyingLogger, level, marker)) {
return;
}
if (arguments == null) {
logFormatted(marker, level, format, t);
} else {
FormattingTuple formattingTuple = MessageFormatter.arrayFormat(format, arguments, t);
logFormatted(marker, level, formattingTuple.getMessage(), formattingTuple.getThrowable());
}
}
项目: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 );
}
}
项目:neoscada
文件:AuditLogServiceImpl.java
@Override
public void debug ( final String message, final Throwable e, final Object... arguments )
{
if ( Boolean.getBoolean ( PROP_ENABLE_DEBUG ) )
{
log ( Severity.INFORMATION, MessageFormatter.arrayFormat ( message, arguments ).getMessage (), e );
}
}
项目:server-extension-java
文件:LogAdaptor.java
/**
* For formatted messages, first substitute arguments and then log.
*
* @param level
* @param format
* @param arguments a list of 3 ore more arguments
*/
private void formatAndLog(int level, String format, Object... arguments) {
if (!isLevelEnabled(level)) {
return;
}
FormattingTuple tp = MessageFormatter.arrayFormat(format, arguments);
log(level, tp.getMessage(), tp.getThrowable());
}
项目:wayf-cloud
文件:FacadePolicies.java
public static final <T> Single<T> singleOrException(Maybe<T> maybe, int statusCode, String message, Object... args) {
Single<Boolean> isEmpty = maybe.isEmpty();
return isEmpty.flatMap((_isEmpty) -> {
if (_isEmpty) {
FormattingTuple formattedMessage = MessageFormatter.arrayFormat(message, args);
throw new ServiceException(statusCode, formattedMessage.getMessage());
}
return maybe.toSingle();
});
}
项目:wayf-cloud
文件:FacadePolicies.java
public static final <T> Single<T> singleOrException(Observable<T> observable, int statusCode, String message, Object... args) {
Single<Long> count = observable.count();
return count.flatMap((_count) -> {
if (_count != 1) {
FormattingTuple formattedMessage = MessageFormatter.arrayFormat(message, args);
throw new ServiceException(statusCode, formattedMessage.getMessage());
}
return observable.singleOrError();
});
}
项目:game
文件:PersisterService.java
@SuppressWarnings({ "rawtypes", "unchecked" })
private void save(Class clz, Entity entity, PersisterListener listner) {
try {
listner.before();
accessor.save(clz, entity);
listner.success();
} catch (Exception e) {
String message = MessageFormatter
.arrayFormat("保存[{}]类型的实体对象[{}]出现错误", new Object[] { clz.getName(), entity.getId(), e })
.getMessage();
log.error(message, e);
listner.exception();
}
}
项目:game
文件:PersisterService.java
@SuppressWarnings({ "rawtypes", "unchecked" })
private void update(Class clz, Entity entity, PersisterListener listner) {
try {
listner.before();
accessor.update(clz, entity);
listner.success();
} catch (Exception e) {
String message = MessageFormatter
.arrayFormat("更新[{}]类型的实体对象[{}]出现错误", new Object[] { clz.getName(), entity.getId(), e })
.getMessage();
log.error(message, e);
listner.exception();
}
}
项目:game
文件:CacheDefinition.java
public void validate(Class<?> clz) {
try {
clz.getConstructor(new Class[0]);
} catch (Exception e) {
String message = MessageFormatter.format("类[{}]必须存在无参数的构造方法", clz.getName()).getMessage();
log.error(message);
throw new RuntimeException(message);
}
}
项目:little_mitm
文件:ProxyConnectionLogger.java
@Override
public void doLog(int level, String message, Object[] params, Throwable t) {
String formattedMessage = fullMessage(message);
if (params != null && params.length > 0) {
formattedMessage = MessageFormatter.arrayFormat(formattedMessage,
params).getMessage();
}
log.log(null, fqcn, level, formattedMessage, null, t);
}
项目:game
文件:ServiceHandler.java
public IMessageInvoke getMessageInvoke(Class<?> receiveMassage){
IMessageInvoke messageInvoke = messageReceive.get(receiveMassage);
if(messageInvoke == null){
String message = MessageFormatter.format("没有注册[{}]的处理器", receiveMassage).getMessage();
log.error(message);
throw new IllegalArgumentException(message);
}
return messageInvoke;
}
项目:game
文件:StringToClassConverter.java
@Override
public Class<?> convert(String source) {
ClassLoader classLoader = applicationContext.getClassLoader();
Class<?> clz = null;
try {
clz = ClassUtils.resolveClassName(source.trim(), classLoader);
} catch (Exception e) {
String message = MessageFormatter.format("无法将字符串[{}]转换成对应的Class对象", source).getMessage();
log.error(message);
throw new IllegalArgumentException(message);
}
return clz;
}
项目:commons-rules
文件:Suppliers.java
/**
* Formatted supplier. Applies {@link MessageFormatter} to
* be able to pass formatted string with parameters as we did int slf4j.
* Good approach to avoid string concatenation before we really need it
*
* @param string String to be supplied
* @param parameters Formatter parameters
* @return Supplied String
*/
public static Supplier<String> formattedSupplier(final String string, final Object... parameters) {
return new Supplier<String>() {
@Override
public String get() {
return clearPlaceholders(MessageFormatter.arrayFormat(string, parameters).getMessage());
}
@Override
public String toString() {
return get();
}
};
}
项目:easy-logger
文件:EasyLog4jLogger.java
/**
* Log a message at level TRACE according to the specified format and argument.
* This form avoids superfluous object creation when the logger is disabled for level TRACE.
*
* @param format the format string
* @param arg the argument
*/
public void trace(String format, Object arg) {
if (isTraceEnabled()) {
FormattingTuple ft = MessageFormatter.format(format, arg);
logger.log(getCallerClassName(), traceCapable ? Level.TRACE : Level.DEBUG,
ft.getMessage(), ft.getThrowable());
}
}
项目:easy-logger
文件:EasyLog4jLogger.java
/**
* Log a message at level ERROR according to the specified format and arguments.
* This form avoids superfluous object creation when the logger is disabled for the ERROR level.
*
* @param format the format string
* @param argArray an array of arguments
*/
public void error(String format, Object... argArray) {
if (logger.isEnabledFor(Level.ERROR)) {
FormattingTuple ft = MessageFormatter.arrayFormat(format, argArray);
logger.log(getCallerClassName(), Level.ERROR, ft.getMessage(),
ft.getThrowable());
}
}
项目:game
文件:ConfigValue.java
@Override
protected T cache() {
try {
value = conversionService.convert(content, clz);
} catch (Exception e) {
String message = MessageFormatter
.arrayFormat("无法将Id为[{}]的字符串[{}]转换为[{}]对象", new Object[] { id, content, clz }).getMessage();
log.error(message, e);
throw new IllegalArgumentException(message);
}
return value;
}
项目:game
文件:Formula.java
@Override
protected Serializable cache() {
try {
value = MVEL.compileExpression(content, context);
} catch (Exception e) {
String message = MessageFormatter
.arrayFormat("无法将Id为[{}]的字符串[{}]转换为[{}]对象", new Object[] { id, content, clz}).getMessage();
log.error(message, e);
throw new IllegalArgumentException(message);
}
return value;
}
项目:game
文件:Formula.java
public R calculate(Object ctx){
R result = null;
try{
result = MVEL.executeExpression(getValue(), ctx, clz2);
}catch(Exception e){
String message = MessageFormatter
.arrayFormat("无法计算Id[{}], 返回值[{}], 参数[{}]的表达式", new Object[] { id, clz2, ctx}).getMessage();
log.error(message, e);
throw new IllegalArgumentException(message);
}
return result;
}
项目:game
文件:ClassUtils.java
/**
* 此方法是以Class.forName来编写, 添加了日志消息, 并选择是否抛出异常 此方法一般只是获取一般的类对象,
* 但是不能获取到例如数组等类型的Class对象, 如果要获取这样的对象see
* {@link org.springframework.util.ClassUtils}
*
* @param Class的类名
* @param isRuntime
* 是否抛出运行时异常 RuntimeException
* @return 返回获取到的类
*/
public static Class<?> getClassforName(String name, boolean isRuntime) {
Assert.notNull(name, "类名字不能为空");
Class<?> clazz = null;
try {
clazz = Class.forName(name);
} catch (ClassNotFoundException e) {
String message = MessageFormatter.format("无法加载资源类[{}]", name).getMessage();
log.error(message);
if (isRuntime) {
throw new RuntimeException(message, e);
}
}
return clazz;
}
项目:Javacord
文件:JavacordLogger.java
@Override
public final void debug(String format, Object... arguments) {
if (isDebugEnabled()) {
FormattingTuple ft = MessageFormatter.arrayFormat(format, arguments);
LogRecord record = new LogRecord(Level.FINE, ft.getMessage());
record.setThrown(ft.getThrowable());
record.setLoggerName(name);
Logger.getLogger(name).log(record);
}
}
项目:game
文件:ClassUtils.java
/**
* BeanUtils.instantiate(clazz)也可创建对象
*
* @param clz
* @param isRuntime
* @return
*/
public static <E> E newInstance(Class<E> clz, boolean isRuntime) {
E instance = null;
try {
instance = clz.newInstance();
} catch (Exception e) {
String message = MessageFormatter.format("无法创建[{}]对应的无参数构造实例", clz.getName()).getMessage();
log.error(message);
if (isRuntime) {
throw new RuntimeException(message, e);
}
}
return instance;
}
项目:Javacord
文件:JavacordLogger.java
@Override
final public void info(String format, Object arg1, Object arg2) {
FormattingTuple ft = MessageFormatter.format(format, arg1, arg2);
LogRecord record = new LogRecord(Level.INFO, ft.getMessage());
record.setThrown(ft.getThrowable());
record.setLoggerName(name);
Logger.getLogger(name).log(record);
}
项目:Javacord
文件:JavacordLogger.java
@Override
final public void error(String format, Object arg1, Object arg2) {
FormattingTuple ft = MessageFormatter.format(format, arg1, arg2);
LogRecord record = new LogRecord(Level.SEVERE, ft.getMessage());
record.setThrown(ft.getThrowable());
record.setLoggerName(name);
Logger.getLogger(name).log(record);
}
项目:delern
文件:Logger.java
@Override
public void info(final String format, final Object arg1, final Object arg2) {
final FormattingTuple ft = MessageFormatter.format(format, arg1, arg2);
Crashlytics.log(Log.INFO, mTag, ft.getMessage());
if (ft.getThrowable() != null) {
exception(Log.INFO, ft.getThrowable());
}
}
项目:game
文件:Formula.java
@Override
protected Serializable cache() {
try {
value = MVEL.compileExpression(content, context);
} catch (Exception e) {
String message = MessageFormatter
.arrayFormat("无法将Id为[{}]的字符串[{}]转换为[{}]对象", new Object[] { id, content, clz }).getMessage();
log.error(message, e);
throw new IllegalArgumentException(message);
}
return value;
}
项目:game
文件:Formula.java
public R calculate(Object context) {
R result = null;
try {
result = MVEL.executeExpression(getValue(), context, clz2);
} catch (Exception e) {
String message = MessageFormatter
.arrayFormat("无法计算Id[{}], 返回值[{}], 参数[{}]的表达式", new Object[] { id, clz2, context }).getMessage();
log.error(message, e);
throw new IllegalArgumentException(message);
}
return result;
}
项目:game
文件:GlobalPlayerSingleChooser.java
@Override
public void check() {
super.check();
if (resource.getInterest() == 0) {
resource.setInterest(1);
}
if (resource.getInterest() >= resource.getItems().length) {
resource.setInterest(resource.getItems().length);
String message = MessageFormatter
.arrayFormat("选择器资源id为[{}]配置的感兴趣的长度[{}]大于资源条目的长度[{}]",
new Object[] { resource.getId(), resource.getInterest(), resource.getItems().length })
.getMessage();
log.warn(message);
}
}
项目:game
文件:ModuleInfo.java
public static ModuleInfo valueOf(ModuleType module, SubModuleType subModule, String message) {
if (!subModule.getType().equals(module)) {
String logMessage = MessageFormatter.format("模块[{}]必须是父模块[{}]的子模块", module, subModule).getMessage();
log.error(logMessage);
}
ModuleInfo info = new ModuleInfo();
info.module = module.getId();
info.subModule = subModule.getId();
info.message = message;
return info;
}
项目:game
文件:ConfigValue.java
@Override
protected T cache() {
try {
value = conversionService.convert(content, clz);
} catch (Exception e) {
String message = MessageFormatter
.arrayFormat("无法将Id为[{}]的字符串[{}]转换为[{}]对象", new Object[] { id, content, clz }).getMessage();
log.error(message, e);
throw new IllegalArgumentException(message);
}
return value;
}