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.
There are no versions of the MongoDB Java driver using log4j by default.
Using the MongoDB JDBC connectivity, it's easier to place a query with the database, introduce updates to the database, and call upon stored processes.
The MongoDB Driver mongodb-driver-sync is the synchronous Java driver containing only the generic MongoCollection interface that complies with a new cross-driver CRUD specification. It does not include the legacy API (e.g. DBCollection ).
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");
After doing that the driver will use the standard Java logging framework to log messages.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With