2017-08-10 91 views
0

我使用java mongodb核心。一切都很好,但。記錄相關信息-.-如何隱藏java mongodb驅動程序日誌?

[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代碼:

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沒有工作:( 請幫幫忙,我需要這個

+0

你是什麼問題?它不清楚.. – Jeyaprakash

+0

我怎麼可以隱藏日誌文本 –

回答

0

什麼是日誌記錄系統,您正在使用?如果您的logback可以設置org.mongodb.driver.*日誌記錄級別比INFO更高。

+0

我不使用日誌記錄,看看java代碼 –

0

看起來你的日誌記錄級別是「信息」。怎麼樣設置你的Loggging水平略高的水平

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

感謝this

+0

沒有工作:/再次看問題內容 –