在logback中可以使用MessageFormat吗?
我看到它使用slf4j slf4j,因为它更快,就像这里说的:出于好奇--为什么日志API不实现printf()-like日志记录方法?
SLF4J使用自己的消息格式实现,这与Java的实现不同。这是合理的事实,SLF4J的实现速度大约快了10倍,但代价是不标准和不灵活。
来自sf4j文档
理想的方法是像这样使用MessageFormat的完整堆栈特性:
Object[] arguments = {
new Integer(7),
new Date(System.currentTimeMillis()),
"a disturbance in the Force"
};
String result = MessageFormat.format(
"At {1,time} on {1,date}, there was {2} on planet {0,number,integer}.",
arguments);
output: At 12:30 PM on Jul 3, 2053, there was a disturbance
in the Force on planet 7.有人吗?
发布于 2013-06-25 23:51:01
我想你回答了你自己的问题..。基本上这是一个性能问题。如果slf4j实现被迫查找和解析参数化..。好吧..。似乎没有人想在日志系统中使用的开销。
发布于 2016-01-13 05:28:01
Log4j 2支持slf4j格式、MessageFormat和String.format语法,以及支持一组printf方法。
https://stackoverflow.com/questions/16679941
复制相似问题