java 如何在Minecraft Spigot插件中禁用MongoDB日志?

laximzn5  于 2023-01-01  发布在  Java
关注(0)|答案(1)|浏览(143)

我试图从MongoDB中隐藏Level.INFO日志,因为它占用了我控制台中太多的空间(实际上它占用了我大约50行cmd)。
这是代码,我尝试:

Logger logger = Logger.getLogger("org.mongodb.driver");
logger.setLevel(Level.OFF);

和我的pom.xml依赖项:

<dependencies>
    <dependency>
        <groupId>org.spigotmc</groupId>
        <artifactId>spigot-api</artifactId>
        <version>1.16.5-R0.1-SNAPSHOT</version>
        <scope>provided</scope>
    </dependency>
    <dependency>
        <groupId>org.mongodb</groupId>
        <artifactId>mongodb-driver-sync</artifactId>
        <version>4.8.1</version>
    </dependency>
    <dependency>
        <groupId>javax.json</groupId>
        <artifactId>javax.json-api</artifactId>
        <version>1.1.4</version>
        <scope>compile</scope>
    </dependency>
    <dependency>
        <groupId>org.glassfish</groupId>
        <artifactId>javax.json</artifactId>
        <version>1.1.4</version>
        <scope>compile</scope>
    </dependency>
    <dependency>
        <groupId>org.slf4j</groupId>
        <artifactId>slf4j-jdk14</artifactId>
        <version>2.0.6</version>
    </dependency>
    <dependency>
        <groupId>org.slf4j</groupId>
        <artifactId>slf4j-api</artifactId>
        <version>2.0.6</version>
    </dependency>
</dependencies>
ivqmmu1c

ivqmmu1c1#

所以,你需要这个:

LoggerContext loggerContext = (LoggerContext) LoggerFactory.getILoggerFactory();
Logger rootLogger = loggerContext.getLogger("org.mongodb.driver");
rootLogger.setLevel(Level.OFF);

以下是所需的导入:

import ch.qos.logback.classic.Level;
import ch.qos.logback.classic.LoggerContext;
import org.slf4j.LoggerFactory;

下面是一行代码:

((LoggerContext) LoggerFactory.getILoggerFactory()).getLogger("org.mongodb.driver").setLevel(Level.ERROR);

它将所有日志设置为仅错误。

相关问题