diff options
author | Keuin <[email protected]> | 2020-12-26 13:15:37 +0800 |
---|---|---|
committer | Keuin <[email protected]> | 2020-12-26 13:15:37 +0800 |
commit | 6b22ae06457ec44ec22ea39582a02dd4168e397b (patch) | |
tree | 53dcc78a7fbba4ebf15ccec21f46ded7e973de91 | |
parent | 61cd5ad0670203e10b1e5b019a6e84aadeed6433 (diff) |
fix mongodb driver spamming in the console
-rw-r--r-- | build.gradle | 6 | ||||
-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 |
3 files changed, 16 insertions, 13 deletions
diff --git a/build.gradle b/build.gradle index 0b12a78..e1e5c68 100644 --- a/build.gradle +++ b/build.gradle @@ -14,11 +14,15 @@ dependencies { implementation 'junit:junit:4.12' implementation 'org.mongodb:mongo-java-driver:3.12.7' + implementation 'org.apache.logging.log4j:log4j-api:2.14.0' + implementation 'org.apache.logging.log4j:log4j-core:2.14.0' implementation 'ch.qos.logback:logback-classic:1.2.3' + include 'org.mongodb:mongo-java-driver:3.12.7' + include 'org.apache.logging.log4j:log4j-api:2.14.0' + include 'org.apache.logging.log4j:log4j-core:2.14.0' include 'ch.qos.logback:logback-classic:1.2.3' - // To change the versions see the gradle.properties file minecraft "com.mojang:minecraft:${project.minecraft_version}" mappings "net.fabricmc:yarn:${project.yarn_mappings}:v2" 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); + } } |