简体   繁体   English

MongoDB java 驱动程序记录查询

[英]MongoDB java driver Logging the queries

Using mongodb java driver:使用 mongodb java 驱动程序:

         <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.我们正在使用 logback.xml 文件进行日志记录,我想记录所有触发到 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.或者告诉我是否有另一种方法可以在 /var/log/mongodb/mongo.log 中记录对 Mongo 的查询,这也有帮助。

Since you are using Logback (and a xml configuration file) you need to set the log level for org.mongodb.driver .由于您使用的是 Logback(和一个 xml 配置文件),您需要为org.mongodb.driver设置日志级别。 Setting it for log4j.logger.org.mongodb.driver will only work when you are configuring log4j via a properties file.将它设置为log4j.logger.org.mongodb.driver仅当您通过属性文件配置 log4j 时才有效。

Additionally you need to set the logging level to DEBUG , so in your case此外,您需要将日志记录级别设置为DEBUG ,因此在您的情况下

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

should to the trick.应该诀窍。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM