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

Added onChild callback with tests and documentation #1541

Merged
merged 6 commits into from Sep 5, 2022

Conversation

Diabl0269
Copy link
Contributor

As discussed in this issue #1534, i've added an onChild callback that uses the child instance as its argument.
I also included tests and documentation.

Please let me know if anything should be change :)

Copy link
Member

@mcollina mcollina left a comment

Choose a reason for hiding this comment

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

Good work! Can you please add a test for the type in https://github.com/pinojs/pino/blob/master/test/types/pino.test-d.ts?

@Diabl0269
Copy link
Contributor Author

Thanks you!
First time I use tsd so I hope I did it right.
Over then that I updated the onChild type to recognize it as an initialization option as well as a property on the logger. (The JS actually works for both but the type was missing).

Copy link
Member

@mcollina mcollina left a comment

Choose a reason for hiding this comment

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

lgtm

@Diabl0269
Copy link
Contributor Author

Diabl0269 commented Aug 31, 2022

Thanks again!
I don't have permission to merge the PR, will you give me the permission/merge it?

@mcollina
Copy link
Member

Let's wait a few more reviews, then I'll merge and ship this.

docs/api.md Outdated Show resolved Hide resolved
docs/api.md Outdated
@@ -508,6 +508,18 @@ when using the `transport` option. In this case an `Error` will be thrown.

* See [pino.transport()](#pino-transport)

#### `onChild` (Function)

The `onChild` function is a callback that will be called on each creation of a new child and use the child instance as it's first argument.
Copy link
Member

Choose a reason for hiding this comment

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

Does the callback block child creation? Do we handle any errors that occur within the callback?

Copy link
Contributor Author

@Diabl0269 Diabl0269 Aug 31, 2022

Choose a reason for hiding this comment

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

The callback doesn't block the child creation, unless the it throws an error.
Should we wrap the callback in a try-catch block?

Copy link
Member

Choose a reason for hiding this comment

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

I think the way the callback is handled should be made clear in the documentation. Adding a try/catch during child creation will have a performance penalty. So we would want to alter the documentation to make it clear that any error in the callback will be uncaught.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Got it. I've updated the documentation to mention the callback doesn't handle errors.

test/basic.test.js Show resolved Hide resolved
Co-authored-by: James Sumners <james@sumners.email>
@Diabl0269 Diabl0269 requested review from jsumners and removed request for kibertoad August 31, 2022 21:01
Expanded `onChild` documentation to mention the function doesn't handle errors
@mcollina
Copy link
Member

mcollina commented Sep 2, 2022

@jsumners PTAL

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.

@mcollina mcollina merged commit 553c66b into pinojs:master Sep 5, 2022
@github-actions
Copy link

github-actions bot commented Sep 6, 2023

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 Sep 6, 2023
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.

None yet

3 participants