Enable debug logs for Mongo java driver

I am interested in seeing org.mongodb.driver.protocol.query debug logs. I believe these are going to come from here:- mongo-java-driver/QueryProtocol.java at master · mongodb/mongo-java-driver · GitHub (and they are called when we do collection.find). Doing logging.level.org.mongodb.driver=DEBUG doesn’t seem to help. Is there anything else i need to do? Do i have to go to exact level like logging.level.org.mongodb.driver.protocol.query=DEBUG?

For any server past version 3.0, QueryProtocol, and therefore that logger, is no longer used by the driver. The logger you want is org.mongodb.driver.protocol.command. That said, if org.mongodb.driver isn’t picking that up, something seems wrong in your configuration. Best I can do is point you to Logging, which links to general SLF4J logging info.

Regards,
Jeff

1 Like

@Jeffrey_Yemin :- I believe my configuration is correct, and that is how rest of loggers are enabled , plus this is a very standard way to change log level in any spring application.

@Jeffrey_Yemin :- Logs have started to come now. Before we close this thread, i want one info on protocol.command logs. From what i understand, they log just before query is sent , and just after response is received from database, which essentially means it is capturing the network call time. Am i right?

That’s correct that it is essentially capturing network time (and TLS state machine execution).

I’m glad it’s working now. Do you know what the issue was?

Regards,
Jeff