From 6b22ae06457ec44ec22ea39582a02dd4168e397b Mon Sep 17 00:00:00 2001 From: Keuin Date: Sat, 26 Dec 2020 13:15:37 +0800 Subject: fix mongodb driver spamming in the console --- src/main/java/com/keuin/blame/Blame.java | 16 ++++------------ src/main/java/com/keuin/blame/util/DatabaseUtil.java | 7 +++++++ 2 files changed, 11 insertions(+), 12 deletions(-) (limited to 'src/main') 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); + } } -- cgit v1.2.3