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

Automatically flush the logs on exit in Node v14+ #1091

Merged
merged 6 commits into from
Aug 20, 2021

Conversation

mcollina
Copy link
Member

This PR removes the main developer experience hurdle in using asynchronous logging: the use of pino.final().
Thanks to on-exit-leak-free we can automatically flush on exit without leaking event emitter listeners (in most cases).
This uses the same mechanism I experimented with for pino.transport().

Copy link
Member

@jsumners jsumners left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good to me.

@@ -37,7 +37,9 @@ test('pino with no args log everything when calling process.exit(0)', async ({ n
not(actual.match(/world/), null)
})

test('sync false does not log everything when calling process.exit(0)', async ({ equal }) => {
const hasWeak = !!global.WeakRef
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: I despise double inverses more than coercing checks.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

eh 🤷 all forms of boolean conversion are a bit shit. Boolean(WeakRef) is where you call a class without new to cast it. == is not good for obvious reasons, !~~ is too esoteric. I suppose you could use 'WeakRef' in global instead

Copy link
Member

@davidmarkclements davidmarkclements left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

outstanding, I love this. CI has an issue, but preapproving

lib/tools.js Outdated Show resolved Hide resolved
@mcollina mcollina merged commit 67ceb5f into master Aug 20, 2021
@mcollina mcollina deleted the automatically-flush-destination-on-exit branch August 23, 2021 12:37
@github-actions
Copy link

This pull request has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Aug 24, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants