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

Get access to children instances from parent #1534

Closed
Diabl0269 opened this issue Aug 29, 2022 · 9 comments
Closed

Get access to children instances from parent #1534

Diabl0269 opened this issue Aug 29, 2022 · 9 comments

Comments

@Diabl0269
Copy link
Contributor

Hey,
I am using pino in a big project containing multiple children. I want to be able to change the log level on all loggers at once.
I saw there is another issue (#1330) about a similar scenario in which the answer was to create an array of loggers.
I would like to suggest to implement an array of children on a parent myself if you'd accept a PR regarding the subject.
The PR will:

  1. Add children array to the prototype object here.
  2. Push the newly created child at the end of its creation function here.

Please let me know your thoughts and in hope you agree I will create a PR :)

@mcollina
Copy link
Member

We want the children to be lightweight and be able to create a new logger for each incoming and http request. Therefore tracking each children from the parent will be a memory leak.

What you'd like to achieve could be done in an external module. I think https://github.com/pinojs/pino-arborsculpture does what you need.

@Diabl0269
Copy link
Contributor Author

@mcollina Firstly, thanks for the quick response.
Secondly, what do you think about allowing a to pass a callback function on creation of an instance (which will be also passed to the children, same as the other properties).
Then the users of pino (e.g me), could pass such a callback in a single place to do a certain operation on the newly created instance.

About your point regarding memory leak, I understand the issue in implementing the original request as for some use cases it could actually be dangerous, but for my use case there is no risk of this. (All loggers are born and die on the service startup and shutdown).

@Diabl0269 Diabl0269 reopened this Aug 30, 2022
@mcollina
Copy link
Member

yeah, I'll be ok with an onChild callback

@jonathansamines
Copy link
Contributor

@mcollina Would it be feasible for pino to track all child instances internally using an iterable weakset implementation and transparently change the log level when the parent level is updated?

@mcollina
Copy link
Member

That technique you are mentioning adds quite a bit of overhead in a hot path.

@Diabl0269
Copy link
Contributor Author

@mcollina I have a PR I'm ready to push but missing access rights to push my branch, could you grant the needed permission?

@mcollina
Copy link
Member

You should fork the repository (https://www.freecodecamp.org/news/how-to-fork-a-github-repository/)

@Diabl0269
Copy link
Contributor Author

Diabl0269 commented Aug 31, 2022

I am new to contributing to open source projects, so thank you for the explanation!
I am closing this issue in favor of the PR I opened regarding this issue. #1541

@github-actions
Copy link

github-actions bot commented Oct 1, 2022

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.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Oct 1, 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

No branches or pull requests

3 participants