当前位置:  开发笔记 > 编程语言 > 正文

在Eclipse中从MongoDB禁用控制台日志记录

如何解决《在Eclipse中从MongoDB禁用控制台日志记录》经验,为你挑选了1个好方法。

我正在使用Mongo数据库存储Java程序中的信息。我正在使用Eclipse和MongoDB 3.0,我遇到的问题是,只要我的程序与Mongo有任何交互,它就会用JULLogger中的红色文本填充控制台。

我目前没有任何代码可以设置记录器级别,因为我在此处或在线其他地方找到的所有示例都给出了错误:

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

   "The method getLogger(String) is undefined for the type Logger"

这是输出:

    Dec 16, 2015 8:49:58 AM com.mongodb.diagnostics.logging.JULLogger log
    INFO: Cluster created with settings {hosts=[127.0.0.1:27017],     
    mode=SINGLE, requiredClusterType=UNKNOWN, serverSelectionTimeout='30000 ms', maxWaitQueueSize=500}
    Dec 16, 2015 8:49:58 AM 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=127.0.0.1:27017, 
    type=UNKNOWN, state=CONNECTING}]}. Waiting for 30000 ms before timing out
    Dec 16, 2015 8:49:58 AM com.mongodb.diagnostics.logging.JULLogger log
    INFO: Opened connection [connectionId{localValue:1, serverValue:117}] to 127.0.0.1:27017
    Dec 16, 2015 8:49:58 AM com.mongodb.diagnostics.logging.JULLogger log
    INFO: Monitor thread successfully connected to server with description 
    ServerDescription{address=127.0.0.1:27017, type=STANDALONE, 
    state=CONNECTED, ok=true, version=ServerVersion{versionList=[3, 0, 7]}, 
    minWireVersion=0, maxWireVersion=3, electionId=null,    
    maxDocumentSize=16777216, roundTripTimeNanos=587005}
    Dec 16, 2015 8:49:58 AM com.mongodb.diagnostics.logging.JULLogger log
    INFO: Opened connection [connectionId{localValue:2, serverValue:118}] to 127.0.0.1:27017
    Document{{_id=567045259311932a6406b4e2, time=16:51:48, data=[31C, 38C, 20C]}}
    Dec 16, 2015 8:49:58 AM com.mongodb.diagnostics.logging.JULLogger log
    INFO: Closed connection [connectionId{localValue:2, serverValue:118}] to        
    127.0.0.1:27017 because the pool has been closed.

谁能建议我如何从控制台中删除所有Mongo日志?



1> Douglas Stea..:

非常感谢Ross的建议:

java.util.logging.Logger.getLogger("org.mongodb.driver").setLevel(java.util.log??ging.Level.SEVERE);

实际上,正确的代码是这样,因此只做了很小的更改:

java.util.logging.Logger.getLogger("org.mongodb.driver").setLevel(Level.SEVERE);

我可以确认我不再在运行时从控制台内的mongo接收任何日志。

推荐阅读
LEEstarmmmmm
这个屌丝很懒,什么也没留下!
DevBox开发工具箱 | 专业的在线开发工具网站    京公网安备 11010802040832号  |  京ICP备19059560号-6
Copyright © 1998 - 2020 DevBox.CN. All Rights Reserved devBox.cn 开发工具箱 版权所有