From 6ad6550f5d0cfe034cff5ba6e618cc96f8f7bfa8 Mon Sep 17 00:00:00 2001 From: Minecon724 Date: Thu, 2 Jan 2025 12:54:08 +0100 Subject: [PATCH] Fix logging in updater --- .../eu/m724/tweaks/updater/UpdateChecker.java | 19 ++++++++++--------- .../m724/tweaks/updater/UpdaterManager.java | 2 +- 2 files changed, 11 insertions(+), 10 deletions(-) diff --git a/src/main/java/eu/m724/tweaks/updater/UpdateChecker.java b/src/main/java/eu/m724/tweaks/updater/UpdateChecker.java index 2687e32..03dfd1f 100644 --- a/src/main/java/eu/m724/tweaks/updater/UpdateChecker.java +++ b/src/main/java/eu/m724/tweaks/updater/UpdateChecker.java @@ -1,5 +1,5 @@ /* - * Copyright (C) 2024 Minecon724 + * Copyright (C) 2025 Minecon724 * Tweaks724 is licensed under the GNU General Public License. See the LICENSE.md file * in the project root for the full license text. */ @@ -19,26 +19,28 @@ import java.util.HashSet; import java.util.Objects; import java.util.Set; import java.util.concurrent.CompletionException; +import java.util.logging.Logger; import java.util.stream.Collectors; public class UpdateChecker extends BukkitRunnable { + private final Logger logger; private final Set resources; static final Set availableUpdates = new HashSet<>(); static LocalTime lastChecked = null; - UpdateChecker(Set resources) { + UpdateChecker(Logger logger, Set resources) { + this.logger = logger; this.resources = resources; // TODO make a copy? } private void checkAll() { - //logger.info("Checking for updates"); + DebugLogger.fine("Checking for updates"); lastChecked = LocalTime.now(ZoneOffset.UTC); availableUpdates.clear(); for (VersionedResource versionedResource : Set.copyOf(resources)) { String pluginName = versionedResource.resource().plugin().getName(); - //logger.info(versionedResource.resource().resourceId() + " " + versionedResource.resource().plugin().getName()); int page = versionedResource.running() != null ? versionedResource.running().page() : 1; try { @@ -46,14 +48,13 @@ public class UpdateChecker extends BukkitRunnable { if (!versionedResource.equals(newResource)) { resources.remove(versionedResource); if (newResource.running() == null) { - DebugLogger.info("Unable to find installed version of %s".formatted(pluginName)); + logger.warning("Unable to find installed version of %s".formatted(pluginName)); if (versionedResource.running() != null) { - DebugLogger.info("Did you downgrade %s? If so, clear cache".formatted(pluginName)); + logger.warning("Did you downgrade %s? If so, clear cache".formatted(pluginName)); } } else { if (!newResource.running().equals(newResource.latest())) { availableUpdates.add(newResource); - //logger.info("Update available for %s. %d -> %d".formatted(pluginName, newResource.running().updateId(), newResource.latest().updateId())); } } resources.add(newResource); @@ -67,11 +68,11 @@ public class UpdateChecker extends BukkitRunnable { private void alert() { int n = availableUpdates.size(); if (n == 0) return; - DebugLogger.info(Language.getString("updateAvailableNotice", n)); + logger.info(Language.getString("updateAvailableNotice", n)); availableUpdates.stream() .map(u -> "- %s (%s -> %s)".formatted(u.resource().name(), u.running().label(), u.latest().label())) - .forEach(DebugLogger::info); + .forEach(logger::info); } @Override diff --git a/src/main/java/eu/m724/tweaks/updater/UpdaterManager.java b/src/main/java/eu/m724/tweaks/updater/UpdaterManager.java index f62bd19..b540a23 100644 --- a/src/main/java/eu/m724/tweaks/updater/UpdaterManager.java +++ b/src/main/java/eu/m724/tweaks/updater/UpdaterManager.java @@ -60,7 +60,7 @@ public class UpdaterManager { )).collect(Collectors.toSet()); - new UpdateChecker(versionedResources) + new UpdateChecker(plugin.getLogger(), versionedResources) .runTaskTimerAsynchronously(plugin, 600, 12 * 3600 * 20); updatesCommand.setExecutor(new UpdaterCommands());