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

查看:79
本文介绍了配置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天全站免登陆