1
0
Fork 0
mirror of https://github.com/xHyroM/lighteco.git synced 2024-11-10 01:18:07 +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.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<Dependency, Path> loaded = new EnumMap<>(Dependency.class);
private final Map<ImmutableSet<Dependency>, 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,6 +51,8 @@ public class DependencyManagerImpl implements DependencyManager {
@Override
public void loadDependencies(Set<Dependency> dependencies) {
CountDownLatch latch = new CountDownLatch(dependencies.size());
if (this.config.debug)
this.logger.info("Loading dependencies: " + dependencies);
for (Dependency dependency : dependencies) {
@ -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,6 +81,7 @@ public class DependencyManagerImpl implements DependencyManager {
try {
latch.await();
if (this.config.debug)
this.logger.info("Loaded dependencies: " + dependencies);
} catch (InterruptedException e) {
throw new RuntimeException(e);

View file

@ -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;