vaibhav
vaibhav

Reputation: 4103

MongoDB java driver Logging the queries

Using mongodb java driver:

         <dependency>
            <groupId>org.mongodb</groupId>
            <artifactId>mongo-java-driver</artifactId>
            <version>3.2.2</version>
        </dependency>

We are using logback.xml file for logging and I want to log all the queries that are fired to Mongo. I added:

<logger name="org.mongodb" level="INFO"></logger>

which did not solve the problem, so then I did

<logger name="log4j.logger.org.mongodb.driver" level="INFO"></logger>

but that did not help either.

Can someone please guide me. Or tell me if there is another way I can log the queries to Mongo in /var/log/mongodb/mongo.log that can also help.

Upvotes: 4

Views: 3469

Answers (1)

THelper
THelper

Reputation: 15619

Since you are using Logback (and a xml configuration file) you need to set the log level for org.mongodb.driver. Setting it for log4j.logger.org.mongodb.driver will only work when you are configuring log4j via a properties file.

Additionally you need to set the logging level to DEBUG, so in your case

<logger name="org.mongodb.driver" level="DEBUG"></logger>

should to the trick.

Upvotes: 3

Related Questions