本文介绍了使用Spring Boot记录MongoDB查询的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否可以在Spring Boot应用程序中记录所有MongoDB查询?我试过了:

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

但这没用.

推荐答案

实际查询由 DEBUG 级别的 MongoTemplate 实例记录.

The actual queries are logged by the MongoTemplate instance at the DEBUG level.

因此,将org.springframework.data.mongodb.core.MongoTemplate的日志级别设置为DEBUG将启用查询日志记录.

Setting the log level for org.springframework.data.mongodb.core.MongoTemplate to DEBUG will therefore enable the query logging.

例如,只需将以下行添加到application.propertiese文件中:

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.

日志将是:

这篇关于使用Spring Boot记录MongoDB查询的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-24 12:43