From 187f71d6c3dc73252eb9755a1b4e724f2f303968 Mon Sep 17 00:00:00 2001 From: Teriuihi Date: Sun, 28 Apr 2024 21:36:45 +0200 Subject: [PATCH] Implement logging for ChatLogHandler The ChatLogHandler now includes logging for better troubleshooting and understanding of the server state. Logging triggers when chat logging is disabled, when it starts, and also if there's a failure in saving chat messages to the database. --- .../com/alttd/chat/objects/chat_log/ChatLogHandler.java | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/api/src/main/java/com/alttd/chat/objects/chat_log/ChatLogHandler.java b/api/src/main/java/com/alttd/chat/objects/chat_log/ChatLogHandler.java index 9eafa84..d226a36 100644 --- a/api/src/main/java/com/alttd/chat/objects/chat_log/ChatLogHandler.java +++ b/api/src/main/java/com/alttd/chat/objects/chat_log/ChatLogHandler.java @@ -28,8 +28,10 @@ public class ChatLogHandler { private final HashMap> chatLogs = new HashMap<>(); public ChatLogHandler(boolean enableLogging) { - if (!enableLogging) + if (!enableLogging) { + ALogger.info("Logging is not enabled on this server."); return; + } Duration deleteThreshold = Duration.ofDays(Config.CHAT_LOG_DELETE_OLDER_THAN_DAYS); ChatLogQueries.deleteOldMessages(deleteThreshold).thenAccept(success -> { if (success) { @@ -41,6 +43,7 @@ public class ChatLogHandler { executorService = Executors.newSingleThreadScheduledExecutor(); executorService.scheduleAtFixedRate(() -> saveToDatabase(false), Config.CHAT_LOG_SAVE_DELAY_MINUTES, Config.CHAT_LOG_SAVE_DELAY_MINUTES, TimeUnit.MINUTES); + ALogger.info("Logging started!"); } /** @@ -78,6 +81,8 @@ public class ChatLogHandler { booleanCompletableFuture.whenComplete((result, throwable) -> { if (throwable == null && result) { chatLogs.clear(); + } else { + ALogger.error("Failed to save chat messages."); } savingToDatabase(false); while (!chatLogQueue.isEmpty()) {