Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix: End logger after ensuring flushing file transport is done #25737 #25851

Open
wants to merge 1 commit into
base: dev
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading