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

Fix configurable log level #2

Open
1 of 2 tasks
ogallagher opened this issue Feb 2, 2025 · 4 comments
Open
1 of 2 tasks

Fix configurable log level #2

ogallagher opened this issue Feb 2, 2025 · 4 comments
Labels
bug Something isn't working

Comments

@ogallagher
Copy link
Owner

ogallagher commented Feb 2, 2025

  • Create reproduceable isolated example and raise as new issue to pino repo.
  • Use custom workaround for desired behavior: cascade parent log level update to all children.
@ogallagher ogallagher added the bug Something isn't working label Feb 2, 2025
@ogallagher
Copy link
Owner Author

In both cjs and mjs local tests, I see that updating the parent log level does not affect its children. For now, it seems I have to propogate the log level update to its children myself.

@ogallagher
Copy link
Owner Author

Created issue pinojs/pino#2130

@ogallagher
Copy link
Owner Author

Use custom workaround for desired behavior

Planning to create a map of known child loggers. Then add a level-change listener to the root logger to cascade level updates to children. Note the listener is called even when updating child logger levels, so the source logger instance that emitted the event must be checked.

const loggerChildren = new Map()

// ...

logger.addListener('level-change', (level, _val, _prevLevel, _prevVal, source) => {
  if (source === loggerRoot) {
    for (let loggerChild of loggerChildren.values()) {
      loggerChild.level = level
    }
  }
})

@ogallagher
Copy link
Owner Author

I will go with a custom setLevel method, rather than a listener, to reduce redundant execution of the handler from child logger level updates.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant