gpt4 book ai didi

java - 在 Eclipse 中禁用来自 MongoDB 的控制台日志记录

转载 作者:可可西里 更新时间:2023-11-01 09:58:57 24 4
gpt4 key购买 nike

我正在使用 Mongo 数据库来存储来 self 的 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 日志?

最佳答案

非常感谢罗斯的建议:

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 接收任何日志。

关于java - 在 Eclipse 中禁用来自 MongoDB 的控制台日志记录,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34307617/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com