gpt4 book ai didi

java - LogBack 使用 MessageFormat

转载 作者:行者123 更新时间:2023-11-29 09:02:14 26 4
gpt4 key购买 nike

是否可以在 logback 中使用 MessageFormat?

我看到它使用 slf4j MessageFormatter,因为它更快,如这里所述: Out of curiosity -- why don't logging APIs implement printf()-like logging methods?

SLF4J uses its own message formatting implementation which differs from that of the Java platform. This is justified by the fact that SLF4J's implementation performs about 10 times faster but at the cost of being non-standard and less flexible.

From sf4j Documentation

ideia 是像这样使用 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.

有人吗?

最佳答案

我想您已经回答了您自己的问题...基本上这是一个性能问题。如果 slf4j 实现被迫查找和解析参数化……那么……似乎没有人希望在日志系统中拥有的开销。

关于java - LogBack 使用 MessageFormat,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16679941/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com