如何禁用mongoDB Java驱动程序日志记录?

我正在尝试禁用的日志输出mongo-java-driver-3.0.0

在加载mongo驱动程序之前,我曾尝试在应用程序的开头设置这些设置,但没有帮助。

    // Enable MongoDB logging in general

System.setProperty("DEBUG.MONGO", "false");

// Enable DB operation tracing

System.setProperty("DB.TRACE", "false");

我收到这种日志:

11:01:15.406 [pool-1-thread-1] DEBUG org.mongodb.driver.protocol.query - Sending query of namespace susudev.Players on connection [connectionId{localValue:2, serverValue:28}] to server localhost:27017

11:01:15.406 [pool-1-thread-1] DEBUG org.mongodb.driver.protocol.query - Query completed

11:01:25.174 [cluster-ClusterId{value='554dbecb1b554f11e86c3a69', description='null'}-localhost:27017] DEBUG org.mongodb.driver.cluster - Checking status of localhost:27017

11:01:25.177 [cluster-ClusterId{value='554dbecb1b554f11e86c3a69', description='null'}-localhost:27017] DEBUG org.mongodb.driver.cluster - Updating cluster description to {type=STANDALONE, servers=[{address=localhost:27017, type=STANDALONE, roundTripTime=0.6 ms, state=CONNECTED}]

所以我的控制台完全塞满了mongo日志,我什么也看不到。

回答:

所以这解决了这个问题:

import org.slf4j.LoggerFactory;

import ch.qos.logback.classic.Level;

import ch.qos.logback.classic.Logger;

...

static Logger root = (Logger) LoggerFactory

.getLogger(Logger.ROOT_LOGGER_NAME);

static {

root.setLevel(Level.INFO);

}

如果您希望隐藏所有日志,可以将其设置Level为较高Level的值。

以上是 如何禁用mongoDB Java驱动程序日志记录? 的全部内容, 来源链接: utcz.com/qa/421228.html

回到顶部