2017-08-10 93 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

没有工作:/再次看问题内容 –