Log MongoDB queries with Spring Boot

后端 未结 3 1042
小鲜肉
小鲜肉 2020-12-30 08:31

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.or         


        
3条回答
  •  爱一瞬间的悲伤
    2020-12-30 08:37

    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{{}}

提交回复
热议问题