docs: show child bindings access in logMethod hook - #2503
Open
la2278647-arch wants to merge 1 commit into
Open
Conversation
The logMethod hook receives the logger as `this`, so child bindings are reachable via `this.bindings()`. Document this directly, with an example that prefixes the message with the child context — the exact use case from pinojs#897. Fixes pinojs#897
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Fixes #897 — the
logMethodhook has no obvious way to access the childlogger's bindings, making use cases like "prefix the message with the
child context" non-obvious.
Change
The hook already receives the logger instance as
this, andthis.bindings()exposes the bindings set vialogger.child(). ThelogMethodsection ofdocs/api.mddid not mention either fact.Adds two short paragraphs and a second example after the existing
argument-flipping example:
followed by a minimal example that prefixes the message with the child's
featureNamebinding — matching the exact request in #897 ("prepend thatname to message").
Verification
Both snippets verified against the repo's own code (Node 24):
this.bindings()insidelogMethodreturns{"featureName":"MY FEATURE"}on a child logger and{}on the root logger. ✓Docs-only change, no code touched.