Separate Logger cleanup in shutdown hook for standalone environment

This commit is contained in:
Xujiayao 2026-01-12 17:18:36 +08:00
parent ce3edaa7db
commit 3959291cd2
2 changed files with 9 additions and 1 deletions

View file

@ -1,6 +1,7 @@
package com.xujiayao.discord_mc_chat.standalone;
import com.xujiayao.discord_mc_chat.DMCC;
import com.xujiayao.discord_mc_chat.utils.logging.impl.LoggerImpl;
/**
* The entry point for Standalone environment.
@ -16,7 +17,12 @@ public class StandaloneDMCC {
*/
public static void main(String[] args) {
// Register shutdown hook for standalone mode
Runtime.getRuntime().addShutdownHook(new Thread(DMCC::shutdown, "DMCC-ShutdownHook"));
Runtime.getRuntime().addShutdownHook(new Thread(() -> {
DMCC.shutdown();
// Logger cleanup
LoggerImpl.shutdown();
}, "DMCC-ShutdownHook"));
// Initialize DMCC, block until initialization is complete
if (DMCC.init()) {

View file

@ -102,6 +102,8 @@ public class LoggerImpl implements Logger {
/**
* Closes the file writer if it was initialized and uninstalls AnsiConsole.
* <p>
* Only Standalone environment requires this cleanup.
*/
public static void shutdown() {
if (fileWriter != null) {