Skip to content

Commit

Permalink
fix: End logger after flushing file transport (Koenkk#25737)
Browse files Browse the repository at this point in the history
  • Loading branch information
Manuel Treuheit authored and Manuel Treuheit committed Jan 16, 2025
1 parent b21167b commit a27321c
Showing 1 changed file with 2 additions and 3 deletions.
5 changes: 2 additions & 3 deletions lib/util/logger.ts
Original file line number Diff line number Diff line change
Expand Up @@ -244,9 +244,6 @@ class Logger {
// https://github.com/Koenkk/zigbee2mqtt/pull/10905
/* v8 ignore start */
public async end(): Promise<void> {
// 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<void>((resolve) => {
// @ts-expect-error workaround
Expand All @@ -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 */
}
Expand Down

0 comments on commit a27321c

Please sign in to comment.