英文:
`com.sun.org.slf4j.internal.Logger` in JDK and wrong usage
问题
当处理XMLSignature的生成和验证时,我不得不进行调试,并遇到了奇怪的日志记录行为(我会称之为错误,但也许我没有完整的图片)。
日志记录器访问方法com.sun.org.slf4j.internal.LoggerFactory#getLogger
是JDK的一部分,用于内部获取日志记录器实例 - 在JDK 12中经过了检查。
该日志记录器例如被org.jcp.xml.dsig.internal.dom.DOMReference
和其他不同的与XMLSignature相关的类使用。
返回的日志记录器是com.sun.org.slf4j.internal.Logger
的一个实例,这是一个简单的包装器,将每个调用委托给java.util.logging.Logger
的一个实例。
我的第一个观察
从slf4j中已知的占位符{}
在日志消息中被使用,我认为,作者希望应该执行某种参数替换。
来自org.jcp.xml.dsig.internal.dom.DOMReference
的示例
LOG.debug("Reference object uri = {}", uri);
由于日志记录器是一个简单的包装器,不执行任何处理,所以这不会被替换。
我的日志消息是未替换的日志字符串。
更新
日志记录器根本不执行任何操作:
public void debug(String s, Throwable e) {
impl.log(java.util.logging.Level.FINE, s, e);
}
public void debug(String s, Object... o) {
impl.log(java.util.logging.Level.FINE, s, o);
}
问题:这是一个错误还是我忘记打开了“某些东西”?
我的第二个观察
在com.sun.org.slf4j.internal.Logger
中,调试日志级别被映射为FINE,而跟踪日志级别也被映射为FINE。我本来希望跟踪级别被映射为最细级,但那无关紧要,因为根本不使用跟踪级别。
我最后的观察
他们为什么在包名中使用slf4j?这非常令人困惑。
英文:
When dealing with XMLSignature generation and verification I had to debug and came across strange logging behavior (I would call it bugs, but maybe I don't have the full picture).
The logger access method com.sun.org.slf4j.internal.LoggerFactory#getLogger
is part of the jdk and is used internally to obtain a logger instance - checked with jdk12.
That logger is used for example by org.jcp.xml.dsig.internal.dom.DOMReference
and other different XMLSignature related classes.
The returned logger is an instance of com.sun.org.slf4j.internal.Logger
and that is a simple
wrapper that delegates every call to an instance of java.util.logging.Logger
.
My first observation
The placeholder {}
known from slf4j is used in log massage and I think, the author expected some sort of parameter replacement should be done.
Example from org.jcp.xml.dsig.internal.dom.DOMReference
LOG.debug("Reference object uri = {}", uri);
Since the logger is a simple wrapper and doesn't do any processing, this isn't replaced.
My log message is the unreplaced log string.
Update
The logger doesn't do anything at all:
public void debug(String s, Throwable e) {
impl.log(java.util.logging.Level.FINE, s, e);
}
public void debug(String s, Object... o) {
impl.log(java.util.logging.Level.FINE, s, o);
}
Question: Is this a bug or did I forget to turn on "something"?
My second observation
In com.sun.org.slf4j.internal.Logger
debug log level is mapped to fine and trace log level is mapped to fine as well. I would have expected that trace level is mapped to finest,
but that doesn't matter, because trace isn't used anyway.
My last observation
Why did they use slf4j in the package name? This is very confusing.
专注分享java语言的经验与见解,让所有开发者获益!
评论