2015-04-05 6 views
9

Hallo
ich versuche, mongo-java driver.i zu lernen folgte dieser mongodb documentation. Die unten ist mein CodeWie verhindert man die Anmeldung an der Konsole bei Verbindung mit mongodb von Java?

public class JMongoDBCDemo 
{ 
    MongoClient mongoClient; 
    DB db; 
    DBCollection coll; 
    public JMongoDBCDemo() 
    { 
     MongoClient mongoClient = new MongoClient("localhost" , 27017); 
     db = mongoClient.getDB("messenger"); 
     coll = db.getCollection("users"); 
     DBObject myDoc = coll.findOne(); 
     System.out.println(myDoc); 
     mongoClient.close(); 
     System.out.println("Got a collection..."); 
    } 
    public static void main(String[] args){ 
      JMongoDBCDemo mongoDemo = new JMongoDBCDemo(); 
    } 
} 

die unten wird der Ausgang

Apr 05, 2015 12:17:47 PM com.mongodb.diagnostics.logging.JULLogger log 
INFO: Cluster created with settings {hosts=[localhost:27017], mode=SINGLE, requiredClusterType=UNKNOWN, serverSelectionTimeout='30000 ms', maxWaitQueueSize=500} 
Apr 05, 2015 12:17:47 PM 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=localhost:27017, type=UNKNOWN, state=CONNECTING}]}. Waiting for 30000 ms before timing out 
Apr 05, 2015 12:17:47 PM com.mongodb.diagnostics.logging.JULLogger log 
INFO: Opened connection [connectionId{localValue:1, serverValue:3}] to localhost:27017 
Apr 05, 2015 12:17:47 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, 6, 1]}, minWireVersion=0, maxWireVersion=2, maxDocumentSize=16777216, roundTripTimeNanos=389140} 
Apr 05, 2015 12:17:47 PM com.mongodb.diagnostics.logging.JULLogger log 
INFO: Opened connection [connectionId{localValue:2, serverValue:4}] to localhost:27017 
{ "_id" : { "$oid" : "55201cec68fb70b6affba026"} , "name" : "prasad" , "password" : "123456"} //This is my output 
Apr 05, 2015 12:17:47 PM com.mongodb.diagnostics.logging.JULLogger log 
INFO: Closed connection [connectionId{localValue:2, serverValue:4}] to localhost:27017 because the pool has been closed. 
Got a collection... //my output 

nach documentation es wie

{ "_id" : { "$oid" : "55201cec68fb70b6affba026"} , "name" : "prasad" , "password" : "123456"} 
Got a collection... 

drucken soll, kann also jemand mir bitte helfen, diese Protokolle zu verhindern Konsole.

+0

Dies könnte für Sie hilfreich sein - http://Stackoverflow.com/questions/9545341/configure-logging-for-the-mongodb-java-driver – Vishwas

+0

Dieser Doc-Link kann für Sie hilfreich sein: http: // mongodb .github.io/mongo-java-driver/3.0/driver/reference/management/logging/ – jyemin

+0

Irgendeine Idee warum es "Eröffnet Verbindung .." mehr als einmal im Protokoll gibt? Für mich gibt es 3 Einträge, wenn ich versuche, eine Verbindung herzustellen. Bitte helfen Sie. –

Antwort

20

Dank @jyemin von MongoDB official documentation Link

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

Jetzt verwenden, sind keine Protokolle in der Konsole gibt.

+2

Es wäre besser, dies überall dort zu konfigurieren, wo die Hauptprotokollierung konfiguriert ist, und SEVERE ist mit ziemlicher Sicherheit zu restriktiv. – chrylis

+0

Es hat mir geholfen. Danke Prasad. Entwickler –