From aa90c4c8a2be23e890ce1cac4a5980dce5163c4a Mon Sep 17 00:00:00 2001 From: Keuin Date: Tue, 29 Dec 2020 13:58:30 +0800 Subject: Improved the disable of mongo driver spamming. Improve compatibility and reduce plugin size. --- src/main/java/com/keuin/blame/util/DatabaseUtil.java | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) (limited to 'src/main/java/com/keuin/blame') diff --git a/src/main/java/com/keuin/blame/util/DatabaseUtil.java b/src/main/java/com/keuin/blame/util/DatabaseUtil.java index dc5cca2..d68bc4d 100644 --- a/src/main/java/com/keuin/blame/util/DatabaseUtil.java +++ b/src/main/java/com/keuin/blame/util/DatabaseUtil.java @@ -1,7 +1,8 @@ package com.keuin.blame.util; -import ch.qos.logback.classic.Level; -import ch.qos.logback.classic.LoggerContext; +//import ch.qos.logback.classic.Level; +//import ch.qos.logback.classic.LoggerContext; + import com.keuin.blame.Blame; import com.keuin.blame.config.MongoConfig; import com.keuin.blame.data.enums.codec.ActionTypeCodec; @@ -12,7 +13,9 @@ import com.mongodb.MongoClientSettings; import org.bson.codecs.configuration.CodecRegistries; import org.bson.codecs.configuration.CodecRegistry; import org.bson.codecs.pojo.PojoCodecProvider; -import org.slf4j.LoggerFactory; + +import java.util.logging.Level; +import java.util.logging.Logger; import static org.bson.codecs.configuration.CodecRegistries.fromProviders; @@ -39,6 +42,11 @@ public class DatabaseUtil { // db.log.createIndex({ timestamp_millis: -1, subject_id: "hashed" }) public static void disableMongoSpamming() { - ((LoggerContext) LoggerFactory.getILoggerFactory()).getLogger("org.mongodb.driver").setLevel(Level.ERROR); +// ((LoggerContext) LoggerFactory.getILoggerFactory()).getLogger("org.mongodb.driver").setLevel(Level.ERROR); + String[] mongoDrivers = new String[] {"org.mongodb", "org.mongodb.driver", "org.mongodb.driver.cluster", "org.mongodb.driver.connection"}; + for (String driverName : mongoDrivers) { + Logger mongoLogger = Logger.getLogger(driverName); + mongoLogger.setLevel(Level.OFF); // Plz be silent, my boy. + } } } -- cgit v1.2.3