我正在使用Mongodb Java Driver 3.4.0-beta及其' org.mongodb.driver'不断记录下面的消息:
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">
对我来说这是无用的信息,而且冗长冗长。我几乎在stackoverflow中搜索了所有解决方案,但没有一个能为我工作。其中一个就像:
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);
}
和
static {
Logger logger = (Logger) LoggerFactory.getLogger("org.mongodb.driver.cluster");
logger.setLevel(Level.OFF);
}
通过设置断点进行调试我发现它使用了logback
作为Logger实现,但我无法获得驱动程序正在使用的真实记录器,所以我无法设置它日志级别。使用Logger logger = (Logger) LoggerFactory.getLogger("org.mongodb.driver.cluster");
实际上并不起作用。它只是一直在退出。
我想知道:
答案 0 :(得分:1)
请勿使用测试版,然后设置日志级别:
static {
Logger logger = (Logger) LoggerFactory.getLogger("org.mongodb.driver.cluster");
logger.setLevel(Level.WARN);
}
答案 1 :(得分:0)
使用这一行
java.util.logging.Logger.getLogger("org.mongodb.driver").setLevel(java.util.logging.Level.SEVERE);