diff options
author | Keuin <[email protected]> | 2020-12-26 13:17:08 +0800 |
---|---|---|
committer | Keuin <[email protected]> | 2020-12-26 13:17:08 +0800 |
commit | 9ce008141191b67cc00f871299891dbd874aff1f (patch) | |
tree | 6a1584133f4b4eba3ef54e7fad8f65050b84d7a9 /src | |
parent | 55715b8b3fc8705e6eecbf835c8d441d3503fa7d (diff) |
fix mongodb driver spamming in the console
Diffstat (limited to 'src')
-rw-r--r-- | src/main/java/com/keuin/blame/Blame.java | 16 | ||||
-rw-r--r-- | src/main/java/com/keuin/blame/util/DatabaseUtil.java | 7 |
2 files changed, 11 insertions, 12 deletions
diff --git a/src/main/java/com/keuin/blame/Blame.java b/src/main/java/com/keuin/blame/Blame.java index 744d920..2bf93ca 100644 --- a/src/main/java/com/keuin/blame/Blame.java +++ b/src/main/java/com/keuin/blame/Blame.java @@ -7,6 +7,7 @@ import com.keuin.blame.command.BlameBlockCommand; import com.keuin.blame.command.BlameLimitCommand; import com.keuin.blame.config.BlameConfig; import com.keuin.blame.lookup.LookupManager; +import com.keuin.blame.util.DatabaseUtil; import com.keuin.blame.util.PrintUtil; import com.mojang.brigadier.CommandDispatcher; import com.mojang.brigadier.arguments.IntegerArgumentType; @@ -18,20 +19,16 @@ import net.fabricmc.fabric.api.event.player.*; import net.minecraft.server.MinecraftServer; import net.minecraft.server.command.CommandManager; import net.minecraft.server.command.ServerCommandSource; -import org.apache.logging.log4j.core.LoggerContext; -import org.slf4j.LoggerFactory; import java.io.File; import java.io.IOException; import java.io.Reader; import java.nio.charset.StandardCharsets; import java.nio.file.Files; -import java.util.logging.Level; -import java.util.logging.Logger; public class Blame implements ModInitializer { - private static final Logger logger = Logger.getLogger(Blame.class.getName()); + private static final java.util.logging.Logger logger = java.util.logging.Logger.getLogger(Blame.class.getName()); public static BlameConfig config; @@ -55,12 +52,7 @@ public class Blame implements ModInitializer { return true; } - private static void disableMongoSpamming() { - Logger mongoLogger = Logger.getLogger("org.mongodb.driver"); - mongoLogger.setLevel(Level.SEVERE); - ((LoggerContext) LoggerFactory.getILoggerFactory()).getLogger("org.mongodb.driver") - .setLevel(org.apache.logging.log4j.Level.ERROR); - } + private static void upgradeOldLogEntries() { // try (final MongoClient mongoClient = MongoClients.create(DatabaseUtil.CLIENT_SETTINGS)) { @@ -97,7 +89,7 @@ public class Blame implements ModInitializer { if (!loadConfig()) return; - disableMongoSpamming(); + DatabaseUtil.disableMongoSpamming(); // hook disable event ServerLifecycleEvents.SERVER_STOPPING.register(new ServerLifecycleEvents.ServerStopping() { diff --git a/src/main/java/com/keuin/blame/util/DatabaseUtil.java b/src/main/java/com/keuin/blame/util/DatabaseUtil.java index 45ea98a..dc5cca2 100644 --- a/src/main/java/com/keuin/blame/util/DatabaseUtil.java +++ b/src/main/java/com/keuin/blame/util/DatabaseUtil.java @@ -1,5 +1,7 @@ package com.keuin.blame.util; +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; @@ -10,6 +12,7 @@ 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 static org.bson.codecs.configuration.CodecRegistries.fromProviders; @@ -34,4 +37,8 @@ public class DatabaseUtil { // db.log.createIndex({ timestamp_millis: -1 }) // db.log.createIndex({ timestamp_millis: -1, object_id: "hashed" }) // db.log.createIndex({ timestamp_millis: -1, subject_id: "hashed" }) + + public static void disableMongoSpamming() { + ((LoggerContext) LoggerFactory.getILoggerFactory()).getLogger("org.mongodb.driver").setLevel(Level.ERROR); + } } |