首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何隐藏java mongodb驱动程序日志?

问如何隐藏java mongodb驱动程序日志?
EN

Stack Overflow用户
提问于 2017-08-11 04:27:06
回答 3查看 2K关注 0票数 0

我使用java mongodb内核。一切都很好,但是。记录信息-.-

代码语言:javascript
复制
[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代码:

代码语言:javascript
复制
 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没有工作:(请帮帮忙,我需要这个。

EN

回答 3

Stack Overflow用户

发布于 2017-08-11 04:33:28

您使用的日志记录系统是什么?如果是logback,您可以将org.mongodb.driver.*的日志记录级别设置为高于INFO。

票数 0
EN

Stack Overflow用户

发布于 2017-08-11 04:33:53

看起来你的日志记录级别是“信息”。将你的日志记录级别设置为更高的级别怎么样

代码语言:javascript
复制
import java.util.logging.Logger;
Logger mongoLogger = Logger.getLogger( "com.mongodb" );
mongoLogger.setLevel(Level.SEVERE); // e.g. or Log.WARNING, etc.

归功于this

票数 0
EN

Stack Overflow用户

发布于 2017-08-11 16:56:43

代码语言:javascript
复制
Logger mongoLogger = Logger.getLogger( "org.mongodb.driver" );
mongoLogger.setLevel(Level.SEVERE);

来源:https://stackoverflow.com/a/29481937/7717350

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/45622903

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档