Skip to content

docs: show child bindings access in logMethod hook - #2503

Open
la2278647-arch wants to merge 1 commit into
pinojs:mainfrom
la2278647-arch:docs/logmethod-bindings
Open

docs: show child bindings access in logMethod hook#2503
la2278647-arch wants to merge 1 commit into
pinojs:mainfrom
la2278647-arch:docs/logmethod-bindings

Conversation

@la2278647-arch

Copy link
Copy Markdown

Summary

Fixes #897 — the logMethod hook has no obvious way to access the child
logger'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, and
this.bindings() exposes the bindings set via logger.child(). The
logMethod section of docs/api.md did not mention either fact.

Adds two short paragraphs and a second example after the existing
argument-flipping example:

Inside the hook, `this` is the logger instance the method was called on.
For a child logger, `this.bindings()` provides the bindings set via
logger.child(), which allows adapting the message based on the child context:

followed by a minimal example that prefixes the message with the child's
featureName binding — matching the exact request in #897 ("prepend that
name to message").

Verification

Both snippets verified against the repo's own code (Node 24):

const child = logger.child({ featureName: 'MY FEATURE' })
child.info('special')
// msg becomes "MY FEATURE: special"

this.bindings() inside logMethod returns {"featureName":"MY FEATURE"} on a child logger and {} on the root logger. ✓
Docs-only change, no code touched.

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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Access to child object in logMethod

1 participant