0

i use java mongodb core. everything is okay but. logging infos -.-

[23:17:33] Connecting to MongoDB...
[main] INFO org.mongodb.driver.cluster - Cluster created with settings {hosts=[localhost:27017], mode=SINGLE, requiredClusterType=UNKNOWN, serverSelectionTimeout='30000 ms', maxWaitQueueSize=500}
[main] INFO org.mongodb.driver.cluster - 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
[cluster-ClusterId{value='598cbf5e4abca723f8603d80', description='null'}-localhost:27017] INFO org.mongodb.driver.cluster - Exception in monitor thread while connecting to server localhost:27017

Java codes:

 public class MongoDB {
        public MongoClient client = null;
        public Map<String, MongoDatabase> databaseTracker = new HashMap<String, MongoDatabase>();

        public MongoDB(String host, int port) {
            try {
                this.client = new MongoClient( "localhost" , 27017 );
                MongoDatabase database = this.client.getDatabase("Main");

                System.out.println(Arrays.toString(this.getDatabaseNames().toArray()));
            } catch(Exception e){
                System.out.println("MongoDB Connection Error");
            }
        }

        public List<String> getDatabaseNames(){
            List<String> dbs = new ArrayList<String>();
            MongoCursor<String> dbsCursor = this.client.listDatabaseNames().iterator();
            while(dbsCursor.hasNext()) {
                dbs.add(dbsCursor.next());
            }
            return dbs;
        }

        public ServerAddress address() {
            if(this.client != null) {
                return this.client.getAddress();
            }
            return null;
        }
    }

Level.SEVERE didn't work :( Please help, i need this.

4J41
  • 5,005
  • 1
  • 29
  • 41
Emre Şenyuva
  • 11
  • 1
  • 4

3 Answers3

0

What is the logging system you are using? If logback you can set the logging level of org.mongodb.driver.* to be higher than INFO.

0

Looks Your logging level is "Info". What about setting your Loggging level to somewhat higher level

import java.util.logging.Logger;
Logger mongoLogger = Logger.getLogger( "com.mongodb" );
mongoLogger.setLevel(Level.SEVERE); // e.g. or Log.WARNING, etc.

Credit to this

Yohannes Gebremariam
  • 2,225
  • 3
  • 17
  • 23
0
Logger mongoLogger = Logger.getLogger( "org.mongodb.driver" );
mongoLogger.setLevel(Level.SEVERE);

Source: https://stackoverflow.com/a/29481937/7717350

mgyongyosi
  • 2,557
  • 2
  • 13
  • 20