-
Notifications
You must be signed in to change notification settings - Fork 885
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
Logging inside process exit event? #1400
Comments
This is a good bug, the good news is that we can totally support it. The problem is in order for transports to work we need to add an exit handler ourselves... in which we close the worker. We might need to change the logic a bit to make sure pino exit handler is always the last. |
The bad news is that I might not have time to work on it. |
Is this the return of? #1075 (comment) |
Same feature, different implementation. The fix is in https://github.com/mcollina/on-exit-leak-free and we must make sure that the specified handler is always the last. |
I solved it in such way const flushLogs = ({ logger }) =>
new Promise((resolve) => {
const symbol = Object.getOwnPropertySymbols(logger).find(
(key) => String(key) === 'Symbol(pino.stream)',
);
const threadStream = logger[symbol];
if (threadStream) {
threadStream.flushSync();
threadStream.end(resolve);
} else {
resolve(void 0);
}
}); but in my Nest.js code (works well in Koa project) it leads to throw new Error('the worker has exited') |
I debugged this. The fundamental issue is that I'm preparing a significant refactor inside on-exit-leak-free to have some APIs to handle this case. |
Here is the fix: #1474 |
This issue has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs. |
Before migrating to pino, I used this pattern with various loggers:
This works correctly with pino with the defaults:
However, when using a transport (such as pino/file), an error is thrown and the line isn't logged:
I noticed pino.final() in the docs, but it's deprecated, and doesn't seem intended for this anyway.
Is there a way of logging from an exit event, or is this a bug/not possible?
The text was updated successfully, but these errors were encountered: