1
0
Fork 0
mirror of https://github.com/xHyroM/lighteco.git synced 2024-11-25 00:01:05 +01:00

fix: log debug output only if debug is enabled

This commit is contained in:
Jozef Steinhübl 2023-08-30 18:27:22 +02:00
parent e38c5977ec
commit 463df35a44
2 changed files with 16 additions and 8 deletions

View file

@ -2,6 +2,7 @@ package dev.xhyrom.lighteco.common.dependencies;
import com.google.common.collect.ImmutableSet; import com.google.common.collect.ImmutableSet;
import com.google.common.io.MoreFiles; 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.Relocation;
import dev.xhyrom.lighteco.common.dependencies.relocation.RelocationHandler; import dev.xhyrom.lighteco.common.dependencies.relocation.RelocationHandler;
import dev.xhyrom.lighteco.common.plugin.LightEcoPlugin; import dev.xhyrom.lighteco.common.plugin.LightEcoPlugin;
@ -24,6 +25,7 @@ public class DependencyManagerImpl implements DependencyManager {
private final EnumMap<Dependency, Path> loaded = new EnumMap<>(Dependency.class); private final EnumMap<Dependency, Path> loaded = new EnumMap<>(Dependency.class);
private final Map<ImmutableSet<Dependency>, IsolatedClassLoader> loaders = new HashMap<>(); private final Map<ImmutableSet<Dependency>, IsolatedClassLoader> loaders = new HashMap<>();
private final Config config;
private final PluginLogger logger; private final PluginLogger logger;
private final DependencyRegistry registry; private final DependencyRegistry registry;
private final Path cacheDirectory; private final Path cacheDirectory;
@ -31,6 +33,7 @@ public class DependencyManagerImpl implements DependencyManager {
private @MonotonicNonNull RelocationHandler relocationHandler; private @MonotonicNonNull RelocationHandler relocationHandler;
public DependencyManagerImpl(LightEcoPlugin plugin) { public DependencyManagerImpl(LightEcoPlugin plugin) {
this.config = plugin.getConfig();
this.logger = plugin.getBootstrap().getLogger(); this.logger = plugin.getBootstrap().getLogger();
this.registry = new DependencyRegistry(); this.registry = new DependencyRegistry();
this.cacheDirectory = setupCacheDirectory(plugin); this.cacheDirectory = setupCacheDirectory(plugin);
@ -48,7 +51,9 @@ public class DependencyManagerImpl implements DependencyManager {
@Override @Override
public void loadDependencies(Set<Dependency> dependencies) { public void loadDependencies(Set<Dependency> dependencies) {
CountDownLatch latch = new CountDownLatch(dependencies.size()); 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) { for (Dependency dependency : dependencies) {
if (this.loaded.containsKey(dependency)) { if (this.loaded.containsKey(dependency)) {
@ -57,14 +62,18 @@ public class DependencyManagerImpl implements DependencyManager {
} }
CompletableFuture.runAsync(() -> { CompletableFuture.runAsync(() -> {
System.out.println("Loading dependency " + dependency); if (this.config.debug)
this.logger.info("Loading dependency " + dependency);
try { try {
loadDependency(dependency); loadDependency(dependency);
} catch (Exception e) { } catch (Exception e) {
throw new RuntimeException("Failed to load dependency " + dependency, e); throw new RuntimeException("Failed to load dependency " + dependency, e);
} finally { } finally {
latch.countDown(); 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 { try {
latch.await(); latch.await();
this.logger.info("Loaded dependencies: " + dependencies); if (this.config.debug)
this.logger.info("Loaded dependencies: " + dependencies);
} catch (InterruptedException e) { } catch (InterruptedException e) {
throw new RuntimeException(e); throw new RuntimeException(e);
} }

View file

@ -14,14 +14,12 @@ public class UserSaveTask implements Runnable {
@Override @Override
public void run() { public void run() {
if (this.plugin.getConfig().debug)
this.plugin.getBootstrap().getLogger().info("Saving users in task");
User[] users = this.plugin.getUserManager().values().stream() User[] users = this.plugin.getUserManager().values().stream()
.filter(User::isDirty) .filter(User::isDirty)
.toArray(User[]::new); .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) { if (users.length == 0) {
return; return;