[JAVA-2203] Remove org.slf4j.impl.StaticLoggerBinder check Created: 03/Jun/16  Updated: 06/Jan/18  Resolved: 06/Jan/18

Status: Closed
Project: Java Driver
Component/s: Monitoring
Affects Version/s: 3.0.0
Fix Version/s: 3.7.0

Type: Improvement Priority: Major - P3
Reporter: Hesham Ahmed Assignee: Jeffrey Yemin
Resolution: Done Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Attachments: Text File Loggers.patch    
Backwards Compatibility: Minor Change

 Description   

com.mongodb.diagnostics.logging.Loggers class checks for the presence of both the slf4j-api and slf4j implementation before enabling slf4j logging. The second check should not be performed since org.slf4j.impl.StaticLoggerBinder might not be accessible in every case (OSGi bundles which want to hide slf4j implementation). And in any case, having SLF4J API without an implementation should be an SLF4J issue which it handles well (displaying warnings etc.). MongoDB Java driver should only check for the presence of SLF4J API, and use it if present. Patch to remove the second test is attached.



 Comments   
Comment by Githook User [ 06/Jan/18 ]

Author:

{'name': 'Jan Peter Stotz', 'username': 'jpstotz', 'email': 'jan-peter.stotz@sit.fraunhofer.de'}

Message: JAVA-2203: Use SLF4J if org.slf4j.Logger class is available. Remove check for org.slf4j.impl.StaticLoggerBinder.
Branch: master
https://github.com/mongodb/mongo-java-driver/commit/9f0cadd8d7b47e39965d4c19b1aea02abe7f40c3

Comment by Jeffrey Yemin [ 04/Jan/18 ]

Changes requested to pull request.

Comment by Hesham Ahmed [ 18/Aug/17 ]

I fail to understand why this is still open. It's a very small change that doesn't affect anything else or cause exceptions. The patch I have attached makes the driver use the correct method of SLF4J as is recommended by SLF4J library developers. If the person has an unused slf4j-api.jar in their classpath without an implementation, they will still get the "No SLF4J providers were found" warning which should be enough to point the users to the right direction.

Comment by Jeffrey Yemin [ 17/Aug/17 ]

According to https://www.slf4j.org/api/org/slf4j/impl/StaticLoggerBinder.html, the static binder mechanism is deprecated as of the 1.8 release of SLF4J. So regardless of OSGi something needs to be done.

Comment by Hesham Ahmed [ 16/Sep/16 ]

In my opinion mandating the slf4j implementation goes against the slf4j design.

Comment by Hesham Ahmed [ 16/Sep/16 ]

SLF4J API is designed to handle missing impl cases. From the SLF4J page:

Note that SLF4J-enabling your library implies the addition of only a single mandatory dependency, namely slf4j-api.jar. If no binding is found on the class path, then SLF4J will default to a no-operation implementation.

Comment by Jeffrey Yemin [ 16/Sep/16 ]

Hi Hesham,

Apologies for not getting back to you sooner. I hope this issue hasn't caused you a lot of trouble.

My concern about removing the check at this point is that there may be some users who, through some indirect dependency, have an unused slf4j-api.jar in their classpath. If we remove the check then those users will no longer get any logging.

Let me know your thoughts on this.

Thanks,
Jeff

Generated at Thu Feb 08 08:56:35 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.