JENKINS-50970 SLF4J logging not working in Swarm client by basil · Pull Request #98 · jenkinsci/swarm-plugin (original) (raw)

Problem

When the Swarm Client starts, the following message gets printed:

SLF4J: Failed to load class "org.slf4j.impl.StaticLoggerBinder"
SLF4J: Defaulting to no-operation (NOP) loger implementation

Note that this doesn't prevent java.util.logging logs from getting printed.

Evaluation

Both Swarm and Remoting use java.util.logging and import neither SLF4J nor Jakarta Commons Logging (JCL), so I wondered SLF4J was in the picture at all here. I asked myself: should we remove SLF4J? Then I realized that we depend on commons-httpclient, which itself depends on JCL:

+- commons-httpclient:commons-httpclient:jar:3.1:compile
|  \- commons-logging:commons-logging:jar:1.0.4:compile

So SLF4J isn't completely useless; we can use it to bridge the log statements made by commons-httpclient to the java.util.logging stream already used by Swarm and Remoting. But right now SLF4J doesn't have any backend configured, hence the warning.

Solution

Add an SLF4J backend. Of the many available choices, it made the most sense to use the java.util.logging backend. The vast majority of log statements are already made to java.util.logging directly by Swarm and Remoting. This change just adds the log statements made by commons-httpclient (through JCL) to this stream.

Bonus

Bumped the version of maven-shade-plugin while I was here.

Testing

Ran the Swarm client with a verbose java.util.logging configuration. Ensured that the error had disappeared and that JCL log statements from commons-httpclient were making it into the FINE level logs via SLF4J.