From 463df35a442f6c3c7c182a6685cf4980f6886dc8 Mon Sep 17 00:00:00 2001 From: xHyroM Date: Wed, 30 Aug 2023 18:27:22 +0200 Subject: [PATCH] fix: log debug output only if debug is enabled --- .../dependencies/DependencyManagerImpl.java | 18 ++++++++++++++---- .../lighteco/common/task/UserSaveTask.java | 6 ++---- 2 files changed, 16 insertions(+), 8 deletions(-) diff --git a/common/src/main/java/dev/xhyrom/lighteco/common/dependencies/DependencyManagerImpl.java b/common/src/main/java/dev/xhyrom/lighteco/common/dependencies/DependencyManagerImpl.java index 737a1f9..f6b9346 100644 --- a/common/src/main/java/dev/xhyrom/lighteco/common/dependencies/DependencyManagerImpl.java +++ b/common/src/main/java/dev/xhyrom/lighteco/common/dependencies/DependencyManagerImpl.java @@ -2,6 +2,7 @@ package dev.xhyrom.lighteco.common.dependencies; import com.google.common.collect.ImmutableSet; import com.google.common.io.MoreFiles; +import dev.xhyrom.lighteco.common.config.Config; import dev.xhyrom.lighteco.common.dependencies.relocation.Relocation; import dev.xhyrom.lighteco.common.dependencies.relocation.RelocationHandler; import dev.xhyrom.lighteco.common.plugin.LightEcoPlugin; @@ -24,6 +25,7 @@ public class DependencyManagerImpl implements DependencyManager { private final EnumMap loaded = new EnumMap<>(Dependency.class); private final Map, IsolatedClassLoader> loaders = new HashMap<>(); + private final Config config; private final PluginLogger logger; private final DependencyRegistry registry; private final Path cacheDirectory; @@ -31,6 +33,7 @@ public class DependencyManagerImpl implements DependencyManager { private @MonotonicNonNull RelocationHandler relocationHandler; public DependencyManagerImpl(LightEcoPlugin plugin) { + this.config = plugin.getConfig(); this.logger = plugin.getBootstrap().getLogger(); this.registry = new DependencyRegistry(); this.cacheDirectory = setupCacheDirectory(plugin); @@ -48,7 +51,9 @@ public class DependencyManagerImpl implements DependencyManager { @Override public void loadDependencies(Set dependencies) { CountDownLatch latch = new CountDownLatch(dependencies.size()); - this.logger.info("Loading dependencies: " + dependencies); + + if (this.config.debug) + this.logger.info("Loading dependencies: " + dependencies); for (Dependency dependency : dependencies) { if (this.loaded.containsKey(dependency)) { @@ -57,14 +62,18 @@ public class DependencyManagerImpl implements DependencyManager { } CompletableFuture.runAsync(() -> { - System.out.println("Loading dependency " + dependency); + if (this.config.debug) + this.logger.info("Loading dependency " + dependency); + try { loadDependency(dependency); } catch (Exception e) { throw new RuntimeException("Failed to load dependency " + dependency, e); } finally { latch.countDown(); - System.out.println("Loaded dependency " + dependency); + + if (this.config.debug) + this.logger.info("Loaded dependency " + dependency); } }); } @@ -72,7 +81,8 @@ public class DependencyManagerImpl implements DependencyManager { try { latch.await(); - this.logger.info("Loaded dependencies: " + dependencies); + if (this.config.debug) + this.logger.info("Loaded dependencies: " + dependencies); } catch (InterruptedException e) { throw new RuntimeException(e); } diff --git a/common/src/main/java/dev/xhyrom/lighteco/common/task/UserSaveTask.java b/common/src/main/java/dev/xhyrom/lighteco/common/task/UserSaveTask.java index 59f29d4..b0b6968 100644 --- a/common/src/main/java/dev/xhyrom/lighteco/common/task/UserSaveTask.java +++ b/common/src/main/java/dev/xhyrom/lighteco/common/task/UserSaveTask.java @@ -14,14 +14,12 @@ public class UserSaveTask implements Runnable { @Override public void run() { - if (this.plugin.getConfig().debug) - this.plugin.getBootstrap().getLogger().info("Saving users in task"); - User[] users = this.plugin.getUserManager().values().stream() .filter(User::isDirty) .toArray(User[]::new); - System.out.println("Saving " + users.length + " users"); + if (this.plugin.getConfig().debug) + this.plugin.getBootstrap().getLogger().info("Saving %s users in task", users.length); if (users.length == 0) { return;