Is it possible to log all MongoDB queries in my Spring Boot app? I tried this:
logging.level.org.springframework.data.document.mongodb=INFO
log4j.category.org.springframework.data.document.mongodb=INFO
But it didn't work.
The actual queries are logged by the MongoTemplate instance at the DEBUG level.
Setting the log level for org.springframework.data.mongodb.core.MongoTemplate
to DEBUG
will therefore enable the query logging.
For example, just add this line to your application.propertiese file:
logging.level.org.springframework.data.mongodb.core.MongoTemplate=DEBUG
Of course, you can also change the log level using any of the externalized configuration options that Spring Boot provides.
The log will be :
2018-11-26 19:23:16.574 DEBUG 15668 --- [nio-8081-exec-2]
o.s.data.mongodb.core.MongoTemplate : find using query: { "status" : "ACTIVE", "item._id" : { "$oid" : "5bfbcde45ac3366ad70cdb9f" } } fields: Document{{}}
If using spring boot reactive mongodb, set logging.level.org.springframework.data.mongodb.core.ReactiveMongoTemplate=DEBUG
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With