From 6a2fc4b282c17cd8341df22ff0efcdbfeca42c20 Mon Sep 17 00:00:00 2001 From: Minecrell 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 b1f48f26..9ed40e49 100644 --- a/src/main/java/org/spigotmc/SpigotConfig.java +++ b/src/main/java/org/spigotmc/SpigotConfig.java @@ -19,6 +19,9 @@ import net.minecraft.server.GenericAttributes; import net.minecraft.server.MinecraftKey; import net.minecraft.server.MinecraftServer; import net.minecraft.server.StatisticList; +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; @@ -351,4 +354,27 @@ public class SpigotConfig attackDamage = getDouble( "settings.attribute.attackDamage.max", attackDamage ); ( (AttributeRanged) GenericAttributes.ATTACK_DAMAGE ).b = 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 4a5ca1eb..5cee8f00 100644 --- a/src/main/resources/log4j2.xml +++ b/src/main/resources/log4j2.xml @@ -19,9 +19,9 @@ - + - + -- 2.17.1