4

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.

Peter
  • 4,752
  • 2
  • 20
  • 32
  • 1
    SLF4J is not just a simple wrapper. The `debug(String, Object)` method is supposed to substitute the first `{}` with the string value of the object, before forwarding to the underlying logger implementation. --- Are you saying your log file has the exact text `Reference object uri = {}` and that the `uri` parameter was ignored? – Andreas Apr 08 '20 at 10:15
  • @Andreas: Updated answer. I don't see where this replacement happens and if it's just the first parameter that is replaced, the log messages `LOG.debug("Reference [{}] is valid: {}", ref.getURI(), refValid);` in `org.jcp.xml.dsig.internal.dom.DOMXMLSignature` won't work, would it? – Peter Apr 08 '20 at 10:28
  • 2
    `java.uitl.logging.Logger` use `java.util.logging.Formatter` to format the messages, which use `java.text.MessageFormat` for formatting. So the log message should be "Reference object uri = {0}". – samabcde Apr 08 '20 at 14:07
  • 1
    @Peter The `debug()` method has overloads for multiple arguments too, e.g. [`debug​(String format, Object... arguments)`](http://www.slf4j.org/apidocs/org/slf4j/Logger.html#debug(java.lang.String,java.lang.Object...)). --- As for the `{}` substitution, that is something SLF4J defines and implements, not the underlying logging implementation. See the [SLF4J FAQ](http://www.slf4j.org/faq.html#logging_performance) for more detail. – Andreas Apr 08 '20 at 20:55
  • 1
    Of course, that's the real SLF4J, but it appears that `com.sun.org.slf4j.internal.Logger` is not a rebranded SLF4J, but a fake thin wrapper, *misleading* the programmer who wrote that code into using SLF4J substitution instead of JUL substitution (as [mentioned by samabcde](https://stackoverflow.com/questions/61098092/com-sun-org-slf4j-internal-logger-in-jdk-and-wrong-usage?noredirect=1#comment108098094_61098092)), so your original thought is correct: **It is a bug**. – Andreas Apr 08 '20 at 21:02
  • 2
    I'm having huge problems with com.sun.org.slf4j conflicting with org.slf4j IntelliJ seems determined to use this faulty library instead of the real one, and I have no idea how to fix it. – user1751825 Feb 09 '21 at 00:30

0 Answers0