From e84d82315cef95858aad5932e61a1237ee070a7b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alexander=20S=C3=B6derberg?= Date: Mon, 13 Jul 2020 20:39:52 +0200 Subject: [PATCH] Add log4j config (this might work :p) --- Bukkit/build.gradle | 9 ++++++- Core/build.gradle | 5 +++- .../core/configuration/Config.java | 11 ++++---- .../java/com/plotsquared/core/plot/Plot.java | 25 ++++++++----------- .../com/plotsquared/core/plot/PlotArea.java | 13 +++++----- Core/src/main/resources/log4j.xml | 13 ++++++++++ 6 files changed, 48 insertions(+), 28 deletions(-) create mode 100644 Core/src/main/resources/log4j.xml diff --git a/Bukkit/build.gradle b/Bukkit/build.gradle index d28377f6a..53ad254f7 100644 --- a/Bukkit/build.gradle +++ b/Bukkit/build.gradle @@ -37,7 +37,10 @@ dependencies { implementation("net.alpenblock:BungeePerms:4.0-dev-106") compile("se.hyperver.hyperverse:Core:0.6.0-SNAPSHOT"){ transitive = false } compile('com.sk89q:squirrelid:1.0.0-SNAPSHOT'){ transitive = false } - compile("org.slf4j:slf4j-jdk14:2.0.0-alpha1") + // logging + implementation('org.apache.logging.log4j:log4j-slf4j-impl:2.13.3') + implementation('org.apache.logging.log4j:log4j-core:2.13.3') + implementation('org.apache.logging.log4j:log4j-api:2.13.3') } sourceCompatibility = 1.8 @@ -97,12 +100,16 @@ shadowJar { include(dependency("org.khelekore:prtree:1.7.0-SNAPSHOT")) include(dependency("com.sk89q:squirrelid:1.0.0-SNAPSHOT")) include(dependency("org.slf4j:slf4j-jdk14:2.0.0-alpha1")) + include(dependency('org.apache.logging.log4j:log4j-slf4j-impl:2.13.3')) + include(dependency('org.apache.logging.log4j:log4j-core:2.13.3')) + include(dependency('org.apache.logging.log4j:log4j-api:2.13.3')) } relocate('net.kyori.text', 'com.plotsquared.formatting.text') relocate("io.papermc.lib", "com.plotsquared.bukkit.paperlib") relocate("org.bstats", "com.plotsquared.metrics") relocate('com.sk89q.squirrelid', 'com.plotsquared.squirrelid') relocate('org.khelekore.prtree', 'com.plotsquared.prtree') + relocate('org.apache.logging.log4j', 'com.plotsquared.logging') archiveFileName = "${project.name}-${parent.version}.jar" destinationDirectory = file "../target" } diff --git a/Core/build.gradle b/Core/build.gradle index 206568547..0f3e54412 100644 --- a/Core/build.gradle +++ b/Core/build.gradle @@ -18,7 +18,10 @@ dependencies { implementation("org.jetbrains.kotlin:kotlin-stdlib:1.3.72") implementation("org.jetbrains:annotations:19.0.0") implementation("org.khelekore:prtree:1.7.0-SNAPSHOT") - implementation("org.slf4j:slf4j-api:2.0.0-alpha1") + // logging + implementation('org.apache.logging.log4j:log4j-slf4j-impl:2.13.3') + implementation('org.apache.logging.log4j:log4j-core:2.13.3') + implementation('org.apache.logging.log4j:log4j-api:2.13.3') } sourceCompatibility = 1.8 diff --git a/Core/src/main/java/com/plotsquared/core/configuration/Config.java b/Core/src/main/java/com/plotsquared/core/configuration/Config.java index 402ee7cd9..139e0dffd 100644 --- a/Core/src/main/java/com/plotsquared/core/configuration/Config.java +++ b/Core/src/main/java/com/plotsquared/core/configuration/Config.java @@ -99,8 +99,8 @@ public class Config { field.set(instance, value); return; } catch (final Throwable e) { - logger.atDebug().addArgument(key).addArgument(value).addArgument(root.getSimpleName()) - .setCause(e).log("Invalid configuration value '{}: {}' in {}"); + logger.debug("Invalid configuration value '{}: {}' in {}", key, value, root.getSimpleName()); + e.printStackTrace(); } } } @@ -289,9 +289,10 @@ public class Config { Field field = instance.getClass().getField(toFieldName(split[split.length - 1])); setAccessible(field); return field; - } catch (Throwable e) { - logger.atDebug().addArgument(StringMan.join(split, ".")).setCause(e) - .addArgument(toNodeName(instance.getClass().getSimpleName())).log("Invalid config field: {} for {}"); + } catch (final Throwable e) { + logger.debug("Invalid config field: {} for {}", + StringMan.join(split, "."), toNodeName(instance.getClass().getSimpleName())); + e.printStackTrace(); return null; } } diff --git a/Core/src/main/java/com/plotsquared/core/plot/Plot.java b/Core/src/main/java/com/plotsquared/core/plot/Plot.java index bccf03232..621c9ee6f 100644 --- a/Core/src/main/java/com/plotsquared/core/plot/Plot.java +++ b/Core/src/main/java/com/plotsquared/core/plot/Plot.java @@ -1735,8 +1735,8 @@ public class Plot { public boolean claim(@NotNull final PlotPlayer player, boolean teleport, String schematic) { if (!canClaim(player)) { - logger.atDebug().addArgument(player.getName()).addArgument(this.getId().toCommaSeparatedString()) - .log("Player {} attempted to claim plot {}, but was not allowed"); + logger.debug("Player {} attempted to claim plot {}, but was not allowed", + player.getName(), this.getId().toCommaSeparatedString()); return false; } return claim(player, teleport, schematic, true); @@ -1835,8 +1835,8 @@ public class Plot { }); return true; } - logger.atInfo().addArgument(this.getId().toCommaSeparatedString()) - .addArgument(this.area.toString()).log("Failed to add plot {} to plot area {}"); + logger.info("Failed to add plot {} to plot area {}", + this.getId().toCommaSeparatedString(), this.area.toString()); return false; } @@ -1934,12 +1934,12 @@ public class Plot { */ public boolean moveData(Plot plot, Runnable whenDone) { if (!this.hasOwner()) { - logger.atDebug().addArgument(plot).log("{} is unowned (single)"); + logger.debug("{} is unowned (single)", plot); TaskManager.runTask(whenDone); return false; } if (plot.hasOwner()) { - logger.atDebug().addArgument(plot).log("{} is unowned (multi)"); + logger.debug("{} is unowned (multi)", plot); TaskManager.runTask(whenDone); return false; } @@ -2647,7 +2647,7 @@ public class Plot { tmp = this.area.getPlotAbs(this.id.getRelative(Direction.NORTH)); if (!tmp.getMerged(Direction.SOUTH)) { // invalid merge - logger.atDebug().addArgument(this).log("Fixing invalid merge: {}"); + logger.debug("Fixing invalid merge: {}", this); if (tmp.isOwnerAbs(this.getOwnerAbs())) { tmp.getSettings().setMerged(Direction.SOUTH, true); DBFunc.setMerged(tmp, tmp.getSettings().getMerged()); @@ -2664,7 +2664,7 @@ public class Plot { assert tmp != null; if (!tmp.getMerged(Direction.WEST)) { // invalid merge - logger.atDebug().addArgument(this).log("Fixing invalid merge: {}"); + logger.debug("Fixing invalid merge: {}", this); if (tmp.isOwnerAbs(this.getOwnerAbs())) { tmp.getSettings().setMerged(Direction.WEST, true); DBFunc.setMerged(tmp, tmp.getSettings().getMerged()); @@ -2681,7 +2681,7 @@ public class Plot { assert tmp != null; if (!tmp.getMerged(Direction.NORTH)) { // invalid merge - logger.atDebug().addArgument(this).log("Fixing invalid merge: {}"); + logger.debug("Fixing invalid merge: {}", this); if (tmp.isOwnerAbs(this.getOwnerAbs())) { tmp.getSettings().setMerged(Direction.NORTH, true); DBFunc.setMerged(tmp, tmp.getSettings().getMerged()); @@ -2697,7 +2697,7 @@ public class Plot { tmp = this.area.getPlotAbs(this.id.getRelative(Direction.WEST)); if (!tmp.getMerged(Direction.EAST)) { // invalid merge - logger.atDebug().addArgument(this).log("Fixing invalid merge: {}"); + logger.debug("Fixing invalid merge: {}", this); if (tmp.isOwnerAbs(this.getOwnerAbs())) { tmp.getSettings().setMerged(Direction.EAST, true); DBFunc.setMerged(tmp, tmp.getSettings().getMerged()); @@ -2712,10 +2712,7 @@ public class Plot { Plot current; while ((current = frontier.poll()) != null) { if (!current.hasOwner() || current.settings == null) { - // Invalid plot - // merged onto unclaimed plot - logger.atDebug().addArgument(current).addArgument(current.getOwnerAbs()) - .log("Ignoring invalid merged plot: {} | {}"); + logger.debug("Ignoring invalid merged plot: {} | {}", current, current.getOwnerAbs()); continue; } tmpSet.add(current); diff --git a/Core/src/main/java/com/plotsquared/core/plot/PlotArea.java b/Core/src/main/java/com/plotsquared/core/plot/PlotArea.java index 64fc305b6..e74e51d2c 100644 --- a/Core/src/main/java/com/plotsquared/core/plot/PlotArea.java +++ b/Core/src/main/java/com/plotsquared/core/plot/PlotArea.java @@ -1063,13 +1063,12 @@ public abstract class PlotArea { try { flags.add(flagInstance.parse(split[1])); } catch (final FlagParseException e) { - logger.atWarn() - .addArgument(e.getFlag().getName()) - .addArgument(e.getValue()) - .addArgument(e.getErrorMessage()) - .setCause(e) - .log("Failed to parse default flag with key '{}' and value '{}'. " - + "Reason: {}. This flag will not be added as a default flag."); + logger.warn("Failed to parse default flag with key '{}' and value '{}'. " + + "Reason: {}. This flag will not be added as a default flag.", + e.getFlag().getName(), + e.getValue(), + e.getErrorMessage()); + e.printStackTrace(); } } } diff --git a/Core/src/main/resources/log4j.xml b/Core/src/main/resources/log4j.xml new file mode 100644 index 000000000..b450c1eca --- /dev/null +++ b/Core/src/main/resources/log4j.xml @@ -0,0 +1,13 @@ + + + + + + + + + + + + +