问题描述
无论是java.util.logging,commons-logging,log4j,还是最新的slf4j和logback,这些API都没有提出方法,例如:
Whether it be java.util.logging, commons-logging, log4j, and even the most recent slf4j and logback, none of these APIs propose methods such as, say:
void debug(String format, Object... args);
其中 format
是使用格式化。相反,他们坚持 MessageFormat
。
where format
is a string parsed using Formatter
. Instead, they stick with MessageFormat
.
我明白它会与现有的原型冲突,所以为什么不 debugf()
之类的,但为什么没有任何这样的方法, Formatter
和Java 1.5一样旧?
I understand that it would conflict with existing prototypes, so why not debugf()
or the like, but why aren't there any such methods given that Formatter
is as old as Java 1.5?
出于性能原因,向后兼容性......?
Is it for performance reasons, backwards compatibility... ?
(注意,我真的谈论 Formatter
,即包括占位符,例如%s
,% 02x
等)
(note, I am really talking about Formatter
, ie including placeholders such as %s
, %02x
etc)
推荐答案
slf4j。请参见。这是slf4j优于log4j的主要优势之一(对我而言)。它无需在任何地方都需要 isDebugEnabled()
。
slf4j does. See http://www.slf4j.org/apidocs/org/slf4j/Logger.html. It's one of the main advantages (to me) of slf4j over log4j. It avoids the need for isDebugEnabled()
everywhere.
编辑:
解释了为什么它不使用标准格式JDK:
The slf4j documentation explains why it doesn't use the standard formatting from the JDK:
这篇关于出于好奇 - 为什么不记录API实现printf() - 就像记录方法一样?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!