为 MongoDB Java 驱动程序配置日志记录 [英] Configure logging for the MongoDB Java driver

查看:33
本文介绍了为 MongoDB Java 驱动程序配置日志记录的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我可以配置 MongoDB Java 驱动程序以输出有用的(用于调试)消息,最好使用标准日志记录框架之一吗?我的主要兴趣是查看发出的每个查询、收到的数据量和花费的时间,以及任何错误代码.

Can I configure the MongoDB Java driver to output useful (for debugging) messages, ideally using one of the standard logging frameworks? I'd mainly be interested in seeing each query that goes out, how much data was received and how long it took, as well as any error codes.

推荐答案

您需要在加载任何 MongoDB Java 驱动程序类之前设置几个系统属性:

You need to set a couple of system properties before loading any of the MongoDB Java driver classes:

// Enable MongoDB logging in general
System.setProperty("DEBUG.MONGO", "true");

// Enable DB operation tracing
System.setProperty("DB.TRACE", "true");

执行此操作后,驱动程序将使用标准 Java 日志记录框架 记录消息.

After doing that the driver will use the standard Java logging framework to log messages.

不幸的是,据我从 Java 驱动程序代码中可以看出,日志记录的粒度并不是那么好 - 例如,您不能有选择地记录对特定集合的操作.

Unfortunately, as far as I can tell from the Java driver code, the logging granularity is not all that fine - for example you cannot selectively log operations on a specific collection.

这篇关于为 MongoDB Java 驱动程序配置日志记录的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆