出于好奇 - 为什么不记录API实现printf() - 就像记录方法一样? [英] Out of curiosity -- why don't logging APIs implement printf()-like logging methods?

查看:110
本文介绍了出于好奇 - 为什么不记录API实现printf() - 就像记录方法一样?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

无论是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 是使用<解析的字符串code>格式化。相反,他们坚持 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。请参见 http://www.slf4j.org/apidocs/org/slf4j/Logger。 HTML 。这是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.

编辑:

slf4j文档解释了为什么它不使用标准格式JDK:

The slf4j documentation explains why it doesn't use the standard formatting from the JDK:


SLF4J使用自己的消息格式化实现,它与Java平台的
不同。这是合理的,因为
SLF4J的实施速度提高了约10倍,但成本为非标准且不太灵活的

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.

这篇关于出于好奇 - 为什么不记录API实现printf() - 就像记录方法一样?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆