简体   繁体   中英

Mongodb's Java driver keeps logging message, how to disable it?

I am using Mongodb Java Driver 3.4.0-beta, and its 'org.mongodb.driver' keeps logging out messages below:

2017-06-28 10:11:37.893  INFO 11700 --- [localhost:27017] org.mongodb.driver.cluster               : Monitor thread successfully connected to server with description ServerDescription{address=localhost:27017, type=STANDALONE, state=CONNECTED, ok=true, version=ServerVersion{versionList=[3, 4, 1]}, minWireVersion=0, maxWireVersion=5, maxDocumentSize=16777216, roundTripTimeNanos=682055}
2017-06-28 10:11:44.926  INFO 11700 --- [127.0.0.1:27017] org.mongodb.driver.cluster               : 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, 4, 1]}, minWireVersion=0, maxWireVersion=5, maxDocumentSize=16777216, roundTripTimeNanos=661572}
2017-06-28 10:11:47.898  INFO 11700 --- [localhost:27017] org.mongodb.driver.cluster               : Monitor thread successfully connected to server with description ServerDescription{address=localhost:27017, type=STANDALONE, state=CONNECTED, ok=true, version=ServerVersion{versionList=[3, 4, 1]}, minWireVersion=0, maxWireVersion=5, maxDocumentSize=16777216, roundTripTimeNanos=688467}
2017-06-28 10:11:54.931  INFO 11700 --- [127.0.0.1:27017] org.mongodb.driver.cluster               : 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, 4, 1]}, minWireVersion=0, maxWireVersion=5, maxDocumentSize=16777216, roundTripTimeNanos=669573}
2017-06-28 10:11:57.902  INFO 11700 --- [localhost:27017] org.mongodb.driver.cluster               : Monitor thread successfully connected to server with description ServerDescription{address=localhost:27017, type=STANDALONE, state=CONNECTED, ok=true, version=ServerVersion{versionList=[3, 4, 1]}, minWireVersion=0, maxWireVersion=5, maxDocumentSize=16777216, roundTripTimeNanos=688015}
2017-06-28 10:12:04.934  INFO 11700 --- [127.0.0.1:27017] org.mongodb.driver.cluster               : 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, 4, 1]}, minWireVersion=0, maxWireVersion=5, maxDocumentSize=16777216, roundTripTimeNanos=658192}
2017-06-28 10:12:07.905  INFO 11700 --- [localhost:27017] org.mongodb.driver.cluster               : Monitor thread successfully connected to server with description ServerDescription{address=localhost:27017, type=STANDALONE, state=CONNECTED, ok=true, version=ServerVersion{versionList=[3, 4, 1]}, minWireVersion=0, maxWireVersion=5, maxDocumentSize=16777216, roundTripTimeNanos=706180}
2017-06-28 10:12:14.940  INFO 11700 --- [127.0.0.1:27017] org.mongodb.driver.cluster               : 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, 4, 1]}, minWireVersion=0, maxWireVersion=5, maxDocumentSize=16777216, roundTripTimeNanos=660184}
2017-06-28 10:12:17.910  INFO 11700 --- [localhost:27017] org.mongodb.driver.cluster               : Monitor thread successfully connected to server with description ServerDescription{address=localhost:27017, type=STANDALONE, state=CONNECTED, ok=true, version=ServerVersion{versionList=[3, 4, 1]}, minWireVersion=0, maxWireVersion=5, maxDocumentSize=16777216, roundTripTimeNanos=692718}
2017-06-28 10:12:24.945  INFO 11700 --- [127.0.0.1:27017] org.mongodb.driver.cluster               : 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, 4, 1]}, minWireVersion=0, maxWireVersion=5, maxDocumentSize=16777216, roundTripTimeNanos=711120}
2017-06-28 10:12:27.914  INFO 11700 --- [localhost:27017] org.mongodb.driver.cluster               : Monitor thread successfully connected to server with description ServerDescription{address=localhost:27017, type=STANDALONE, state=CONNECTED, ok=true, version=ServerVersion{org/xsd/maven-4.0.0.xsd">

It's useless information for me and too much verbose. I've searched almost every solution in stackoverflow and none of them works for me. One of them is like:

static {
  System.setProperty("DEBUG.MONGO", "false");
  System.setProperty("DB.TRACE", "false");
  LoggerContext context = (LoggerContext) LoggerFactory.getILoggerFactory();
  Logger logger = context.getLogger("org.mongodb.driver.cluster");
  logger.setLevel(Level.OFF);
}

and:

static {
  Logger logger = (Logger) LoggerFactory.getLogger("org.mongodb.driver.cluster");
  logger.setLevel(Level.OFF);
}

By making breakpoints to debug I've figured out that it used logback as Logger implementation and but I had no way to get real logger the driver is using, so I cannot set it's log level. Using Logger logger = (Logger) LoggerFactory.getLogger("org.mongodb.driver.cluster"); actually doesn't work. It just keeps logging out.

I am wondering:

  1. How to avoid those messages?
  2. Why does mongodb driver log it?(it's totally useless infomation)

Don't use beta version then set it's log level:

static {
  Logger logger = (Logger) LoggerFactory.getLogger("org.mongodb.driver.cluster");
  logger.setLevel(Level.WARN);
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM