From b30c452e61256210bb94b7c7192a774d6e3a46ae Mon Sep 17 00:00:00 2001 From: Manuel Treuheit Date: Thu, 16 Jan 2025 16:41:42 +0100 Subject: [PATCH] fix: End logger after flushing file transport (#25737) --- lib/util/logger.ts | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/lib/util/logger.ts b/lib/util/logger.ts index dbcc6df11c..522e2d459d 100644 --- a/lib/util/logger.ts +++ b/lib/util/logger.ts @@ -244,9 +244,6 @@ class Logger { // https://github.com/Koenkk/zigbee2mqtt/pull/10905 /* v8 ignore start */ public async end(): Promise { - // Only flush the file transport, don't end logger itself as log() might still be called - // causing a UnhandledPromiseRejection (`Error: write after end`). Flushing the file transport - // ensures the log files are written before stopping. if (this.fileTransport) { await new Promise((resolve) => { // @ts-expect-error workaround @@ -260,6 +257,8 @@ class Logger { this.fileTransport.end(); }); } + // Ensure all logs are written before exiting so ending has to happen after the file transport is flushed + void this.logger.end(); } /* v8 ignore stop */ }