Configure logging for the MongoDB Java driver
You need to set a couple of system properties before loading any of the MongoDB Java driver classes:
// Enable MongoDB logging in generalSystem.setProperty("DEBUG.MONGO", "true");// Enable DB operation tracingSystem.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.
Another way to do set MongoDB's log level:
import java.util.logging.Logger;Logger mongoLogger = Logger.getLogger( "com.mongodb" );mongoLogger.setLevel(Level.SEVERE); // e.g. or Log.WARNING, etc.
You don't have to do this before using any of the driver classes, you can set/change log levels at any time.