-
-
Notifications
You must be signed in to change notification settings - Fork 1.7k
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
Flush logger before exiting process #10905
Conversation
3baa15e
to
4d6a9ad
Compare
lib/controller.ts
Outdated
// Workaround for https://github.com/winstonjs/winston/issues/1629 | ||
await new Promise<void>((resolve, reject) => { | ||
logger.winston.on('finish', () => { | ||
setTimeout(() => resolve(), 1000); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If I understand correctly, this will always increase the shutdown sequence by 1 second, could this be decreased?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That is my understanding as well. Possibly it could be decreased but since winston writing to file is async there's no real safe value. The shorter the timeout the more likely that the logs won't be written to disk.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I tried a few different options that wouldn't add unnecessary delay to shutdown but unfortunately wasn't able to get anything else to work
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I just checked, setTimeout(() => resolve(), 10);
also fixes it, could you also test this?
598ea23
to
bcf09cc
Compare
bcf09cc
to
7dde5a0
Compare
nice solution, thanks! |
I am using the
file
logger without theconsole
logger and if Z2M is unable to start then nothing is logged becauseprocess.exit(1)
is calling and WInston doesn't flush async logs when this happens (see winstonjs/winston#1629).With console logging enabled:
With file logging: