From fec4f20420f4c7e8cafb34b2ec36a0995509363f Mon Sep 17 00:00:00 2001 From: ChomeNS <95471003+ChomeNS@users.noreply.github.com> Date: Sun, 30 Jul 2023 08:21:59 +0700 Subject: [PATCH] fix --- .../chayapak/chomens_bot/plugins/LoggerPlugin.java | 14 ++++++++++++-- .../chomens_bot/util/FileLoggerUtilities.java | 2 +- 2 files changed, 13 insertions(+), 3 deletions(-) diff --git a/src/main/java/land/chipmunk/chayapak/chomens_bot/plugins/LoggerPlugin.java b/src/main/java/land/chipmunk/chayapak/chomens_bot/plugins/LoggerPlugin.java index b2376ce..e4f7fe8 100644 --- a/src/main/java/land/chipmunk/chayapak/chomens_bot/plugins/LoggerPlugin.java +++ b/src/main/java/land/chipmunk/chayapak/chomens_bot/plugins/LoggerPlugin.java @@ -46,8 +46,18 @@ public class LoggerPlugin extends ChatPlugin.Listener { @Override public void disconnected (DisconnectedEvent event) { - final String reason = ComponentUtilities.stringifyAnsi(event.getReason()); - log("Disconnected from " + bot.host + ":" + bot.port + ", reason: " + reason); + final Component reason = event.getReason(); + + final String message = "Disconnected from " + bot.host + ":" + bot.port + ", reason: "; + + final String string = ComponentUtilities.stringify(reason); + + if (logToConsole) { + final String ansi = ComponentUtilities.stringifyAnsi(reason); + + log(message + ansi, false, true); + } + log(message + string, true, false); } }); } diff --git a/src/main/java/land/chipmunk/chayapak/chomens_bot/util/FileLoggerUtilities.java b/src/main/java/land/chipmunk/chayapak/chomens_bot/util/FileLoggerUtilities.java index 8ef653b..2cf2b42 100644 --- a/src/main/java/land/chipmunk/chayapak/chomens_bot/util/FileLoggerUtilities.java +++ b/src/main/java/land/chipmunk/chayapak/chomens_bot/util/FileLoggerUtilities.java @@ -83,7 +83,7 @@ public class FileLoggerUtilities { if (!Files.exists(logPath)) Files.createFile(logPath); - logWriter = Files.newBufferedWriter(logPath, StandardOpenOption.WRITE); + logWriter = Files.newBufferedWriter(logPath, StandardOpenOption.TRUNCATE_EXISTING); logWriter.write(currentLogDate.toString() + '\n'); logWriter.flush(); }