如何禁用mongoDB java驱动日志记录? [英] How to disable mongoDB java driver logging?

查看:116
本文介绍了如何禁用mongoDB java驱动日志记录?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

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

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

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

我收到这种日志:

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日志,我无法阅读任何内容。

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

推荐答案

所以这解决了这个问题:

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

您可以设置等级更高等级

这篇关于如何禁用mongoDB java驱动日志记录?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆