Search code examples
javaeclipsemongodbloggingmongodb-java

Disable Console Logging from MongoDB in Eclipse


I'm using a Mongo Database to store information from my Java program. I'm using Eclipse and MongoDB 3.0 The problem I am having is that whenever my program has any interaction with Mongo it fills the console with red text from JULLogger.

I do not currently have any code to set the logger level, as all examples I have found on here or elsewhere online have given the error:

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

   "The method getLogger(String) is undefined for the type Logger"

Here is the output:

    Dec 16, 2015 8:49:58 AM com.mongodb.diagnostics.logging.JULLogger log
    INFO: Cluster created with settings {hosts=[127.0.0.1:27017],     
    mode=SINGLE, requiredClusterType=UNKNOWN, serverSelectionTimeout='30000 ms', maxWaitQueueSize=500}
    Dec 16, 2015 8:49:58 AM com.mongodb.diagnostics.logging.JULLogger log
    INFO: No server chosen by ReadPreferenceServerSelector{readPreference=primary} from cluster description  
    ClusterDescription{type=UNKNOWN, connectionMode=SINGLE, all=[ServerDescription{address=127.0.0.1:27017, 
    type=UNKNOWN, state=CONNECTING}]}. Waiting for 30000 ms before timing out
    Dec 16, 2015 8:49:58 AM com.mongodb.diagnostics.logging.JULLogger log
    INFO: Opened connection [connectionId{localValue:1, serverValue:117}] to 127.0.0.1:27017
    Dec 16, 2015 8:49:58 AM com.mongodb.diagnostics.logging.JULLogger log
    INFO: Monitor thread successfully connected to server with description 
    ServerDescription{address=127.0.0.1:27017, type=STANDALONE, 
    state=CONNECTED, ok=true, version=ServerVersion{versionList=[3, 0, 7]}, 
    minWireVersion=0, maxWireVersion=3, electionId=null,    
    maxDocumentSize=16777216, roundTripTimeNanos=587005}
    Dec 16, 2015 8:49:58 AM com.mongodb.diagnostics.logging.JULLogger log
    INFO: Opened connection [connectionId{localValue:2, serverValue:118}] to 127.0.0.1:27017
    Document{{_id=567045259311932a6406b4e2, time=16:51:48, data=[31C, 38C, 20C]}}
    Dec 16, 2015 8:49:58 AM com.mongodb.diagnostics.logging.JULLogger log
    INFO: Closed connection [connectionId{localValue:2, serverValue:118}] to        
    127.0.0.1:27017 because the pool has been closed.

Could anyone advise me on how to remove all the Mongo logs from my console?


Solution

  • Thank you very much Ross for your suggestion:

    java.util.logging.Logger.getLogger("org.mongodb.driver").setLevel(java.util.log‌​ging.Level.SEVERE);

    In fact the correct code was this, so only a minor change:

    java.util.logging.Logger.getLogger("org.mongodb.driver").setLevel(Level.SEVERE);

    I can confirm that I am not longer receiving any logs from mongo within the console at runtime.