0
0
mirror of https://hub.spigotmc.org/stash/scm/spigot/spigot.git synced 2024-11-21 20:56:14 +00:00
spigot/CraftBukkit-Patches/0062-Make-debug-logging-togglable.patch
2024-10-23 02:15:00 +11:00

70 lines
2.7 KiB
Diff

From a9bc579f5a64380147b2514fa378df63a399df60 Mon Sep 17 00:00:00 2001
From: Minecrell <dev@minecrell.net>
Date: Sun, 17 Aug 2014 12:42:53 +0200
Subject: [PATCH] Make debug logging togglable.
diff --git a/src/main/java/org/spigotmc/SpigotConfig.java b/src/main/java/org/spigotmc/SpigotConfig.java
index e12a5df127..11a716f919 100644
--- a/src/main/java/org/spigotmc/SpigotConfig.java
+++ b/src/main/java/org/spigotmc/SpigotConfig.java
@@ -18,6 +18,9 @@ import net.minecraft.resources.MinecraftKey;
import net.minecraft.server.MinecraftServer;
import net.minecraft.world.entity.ai.attributes.AttributeRanged;
import net.minecraft.world.entity.ai.attributes.GenericAttributes;
+import org.apache.logging.log4j.LogManager;
+import org.apache.logging.log4j.core.LoggerContext;
+import org.apache.logging.log4j.core.config.Configuration;
import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
import org.bukkit.command.Command;
@@ -356,4 +359,27 @@ public class SpigotConfig
attackDamage = getDouble( "settings.attribute.attackDamage.max", attackDamage );
( (AttributeRanged) GenericAttributes.ATTACK_DAMAGE.value() ).maxValue = attackDamage;
}
+
+ public static boolean debug;
+ private static void debug()
+ {
+ debug = getBoolean( "settings.debug", false );
+
+ if ( debug && !LogManager.getRootLogger().isTraceEnabled() )
+ {
+ // Enable debug logging
+ LoggerContext ctx = (LoggerContext) LogManager.getContext( false );
+ Configuration conf = ctx.getConfiguration();
+ conf.getLoggerConfig( LogManager.ROOT_LOGGER_NAME ).setLevel( org.apache.logging.log4j.Level.ALL );
+ ctx.updateLoggers( conf );
+ }
+
+ if ( LogManager.getRootLogger().isTraceEnabled() )
+ {
+ Bukkit.getLogger().info( "Debug logging is enabled" );
+ } else
+ {
+ Bukkit.getLogger().info( "Debug logging is disabled" );
+ }
+ }
}
diff --git a/src/main/resources/log4j2.xml b/src/main/resources/log4j2.xml
index edbd70b164..0ff3f750fb 100644
--- a/src/main/resources/log4j2.xml
+++ b/src/main/resources/log4j2.xml
@@ -24,10 +24,10 @@
<filters>
<MarkerFilter marker="NETWORK_PACKETS" onMatch="DENY" onMismatch="NEUTRAL" />
</filters>
- <AppenderRef ref="SysOut"/>
+ <AppenderRef ref="SysOut" level="info"/>
<AppenderRef ref="File"/>
- <AppenderRef ref="ServerGuiConsole"/>
- <AppenderRef ref="TerminalConsole"/>
+ <AppenderRef ref="ServerGuiConsole" level="info"/>
+ <AppenderRef ref="TerminalConsole" level="info"/>
</Root>
</Loggers>
</Configuration>
--
2.47.0