[JAVA-1123] Use SLF4J instead of Java Util Logging for higher flexibility Created: 26/Feb/14  Updated: 06/Apr/23  Resolved: 18/Mar/14

Status: Closed
Project: Java Driver
Component/s: None
Affects Version/s: 2.11.4
Fix Version/s: 3.0.0

Type: Improvement Priority: Major - P3
Reporter: Alexej Kubarev Assignee: Unassigned
Resolution: Done Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified
Environment:

ALL



 Description   

Currently Mongo Java Driver uses JUL for logging. This causes a few troubles for developers that are using other logger implementations in their apps, specifically because JUL is part of core JDK and is hard to override. Also having multiple different loggers is just causing a structural mess.

If a bridge API, such as SLF4J is used instead, it's possible to allow developers to use any type of logger provider, be it JUL, Log4J, JCL, Logback..

The only thing that Java Driver needs is use SLF4J-API to create logger, the specific API implementation that developer chooses for their apps is going to do the rest of heavy lifting. SLF4J also provides bridges that override other log implementations, but due to the fact that JUL is core JDK - this operation is costy (very!).

Another great thing with SLF4J is that it provides a much more optimised way of using the log statements - with placeholder support, placeholder value is only evaluated if and only if debug is enabled. Traditionally this is not the case and in apps requiring best performance, this can lead to performance improvement.

As the design idea of mongo driver is not to have any 3rd party dependency, it could be possible to either include the tiny SLF4J API directly instead of the driver code or do something to check if SLF4J is present and use that instead.

More Info about SLF4J: http://www.slf4j.org/
How Legacy loggers could be supported: http://www.slf4j.org/legacy.html



 Comments   
Comment by Jeffrey Yemin [ 31/Mar/15 ]

Closing all resolved 3.0.0 issues, as 3.0.0 has been tagged and released.

Comment by Alexej Kubarev [ 19/Mar/14 ]

Sounds like a great solution! Can't wait for 3.0 to use this as we simply cannot get JUL to work properly in our app (most likely to app specifics).

Comment by Jeffrey Yemin [ 18/Mar/14 ]

SLF4J will be used if it's detected on the classpath. Otherwise, the driver will fall back to java.util.logging.

Comment by Githook User [ 18/Mar/14 ]

Author:

{u'username': u'jyemin', u'name': u'Jeff Yemin', u'email': u'jeff.yemin@10gen.com'}

Message: JAVA-1123: Log using SLF4J API if available, otherwise fall back to JUL.
Updated all the former users of JUL logging to use the new Logger interface provided by the driver.
Use Logback when running tests.
Branch: 3.0.x
https://github.com/mongodb/mongo-java-driver/commit/3748341e151cd1f614df651d8beecf7aaa824f8f

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