How to disable mongoDB java driver logging?

2019-01-19 11:06发布

I am trying to disable log outputs of mongo-java-driver-3.0.0.

I have tried to set those in the beginning of my application, before loading the mongo drivers, but it didn't help.

    // Enable MongoDB logging in general
    System.setProperty("DEBUG.MONGO", "false");

    // Enable DB operation tracing
    System.setProperty("DB.TRACE", "false");  

I am getting this kind of logs:

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}]

So my console is completely packed with mongo logs and I cant read anything.

9条回答
看我几分像从前
2楼-- · 2019-01-19 11:34

In my case, MongoDB driver 3.5.0, SLF4j+Log4j12, it's been sufficient adding:

log4j.logger.org.mongodb.driver=OFF

in my Log4j .properties configuration file.

查看更多
爷的心禁止访问
3楼-- · 2019-01-19 11:36

So this solved this issue:

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);
}

You may set the Level to a higher Level if you wish to hide all the logs.

查看更多
Ridiculous、
4楼-- · 2019-01-19 11:37

use the below import

import java.util.logging.Logger;

use the below in code.

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

查看更多
登录 后发表回答