Disable java mongoDB application console logging

 Posted On  | Yashwant Chavan 

Mongodb Java driver display the logging messages while performing different operations likes connection, insert , update and delete etc. It used popular SLF4J API. If you want to disable the logging mechanism, refer below solution.

Sep 21, 2016 7:34:31 PM com.mongodb.diagnostics.logging.JULLogger log
INFO: Cluster created with settings {hosts=[localhost:27017], mode=SINGLE, requiredClusterType=UNKNOWN, serverSelectionTimeout='30000 ms', maxWaitQueueSize=500}
Sep 21, 2016 7:34:31 PM com.mongodb.diagnostics.logging.JULLogger log
INFO: Opened connection [connectionId{localValue:1, serverValue:44}] to localhost:27017
Sep 21, 2016 7:34:31 PM com.mongodb.diagnostics.logging.JULLogger log
INFO: Monitor thread successfully connected to server with description ServerDescription{address=localhost:27017, type=STANDALONE, state=CONNECTED, ok=true, version=ServerVersion{versionList=[2, 2, 2]}, minWireVersion=0, maxWireVersion=0, maxDocumentSize=16777216, roundTripTimeNanos=1082902}
Sep 21, 2016 7:34:31 PM com.mongodb.diagnostics.logging.JULLogger log
INFO: Opened connection [connectionId{localValue:2, serverValue:45}] to localhost:27017
Sep 21, 2016 7:34:32 PM com.mongodb.diagnostics.logging.JULLogger log
INFO: Closed connection [connectionId{localValue:2, serverValue:45}] to localhost:27017 because the pool has been closed.
Sep 21, 2016 7:34:32 PM com.mongodb.diagnostics.logging.JULLogger log
INFO: Cluster created with settings {hosts=[localhost:27017], mode=SINGLE, requiredClusterType=UNKNOWN, serverSelectionTimeout='30000 ms', maxWaitQueueSize=500}
Sep 21, 2016 7:34:32 PM com.mongodb.diagnostics.logging.JULLogger log
INFO: No server chosen by ReadPreferenceServerSelector{readPreference=primary} from cluster description ClusterDescription{type=UNKNOWN, connectionMode=SINGLE, serverDescriptions=[ServerDescription{address=localhost:27017, type=UNKNOWN, state=CONNECTING}]}. Waiting for 30000 ms before timing out
Sep 21, 2016 7:34:32 PM com.mongodb.diagnostics.logging.JULLogger log
INFO: Opened connection [connectionId{localValue:3, serverValue:46}] to localhost:27017
Sep 21, 2016 7:34:32 PM com.mongodb.diagnostics.logging.JULLogger log
INFO: Monitor thread successfully connected to server with description ServerDescription{address=localhost:27017, type=STANDALONE, state=CONNECTED, ok=true, version=ServerVersion{versionList=[2, 2, 2]}, minWireVersion=0, maxWireVersion=0, maxDocumentSize=16777216, roundTripTimeNanos=463818}
Sep 21, 2016 7:34:32 PM com.mongodb.diagnostics.logging.JULLogger log
.....
.....
.....
.....
.....
.....

Meta Data:- Document{{type=image, upload_date=Thu Sep 01 00:00:00 IST 2016, content_type=image/jpg}}
Sep 21, 2016 7:34:33 PM com.mongodb.diagnostics.logging.JULLogger log
INFO: Closed connection [connectionId{localValue:16, serverValue:59}] to localhost:27017 because the pool has been closed.

Solution

By default, logging is enabled via the popular SLF4J API. The use of SLF4J is optional; the driver will use SLF4J if the driver detects the presence of SLF4J in the classpath. Otherwise, the driver will fall back to JUL (java.util.logging).

Logger mongoLogger = Logger.getLogger( "org.mongodb.driver" );
mongoLogger.setLevel(Level.SEVERE);


© technicalkeeda.com 2017

 |  Find us on Google+ |  Rss Feed

Loaded in 0.0273 seconds.