Skip to content

Commit 6429c14

Browse files
authored
docs: Note that serializers run on child bindings at creation time (#2518)
Serializers are applied to the bindings passed to `logger.child()` when the child logger is created, not on each subsequent log call. `asChindings()` calls the matching serializer while building the child's precomputed chindings string, so a serializer keyed to a binding runs exactly once. This is intentional, and is what allows child loggers to stay fast at log time, but it is surprising when a serializer is expected to run per log call, and it was not documented. Documents the behaviour and points readers at the log methods when they need a serializer invoked per call.
1 parent 6c71bc9 commit 6429c14

1 file changed

Lines changed: 7 additions & 0 deletions

File tree

‎docs/api.md‎

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -471,6 +471,13 @@ in the serializers. The only exception is the `err` serializer as it is also app
471471
the object is an instance of `Error`, e.g. `logger.info(new Error('kaboom'))`.
472472
See `errorKey` option to change `err` namespace.
473473

474+
Serializers are also applied to the [bindings passed to `logger.child()`](#logger-child-bindings).
475+
Child bindings are serialized once, when the child logger is created, so a matching
476+
serializer runs at that point rather than on every subsequent log call. This is
477+
deliberate: it allows a child logger to precompute its bindings and stay fast at log
478+
time. If a serializer needs to run per log call, pass the value to the log method
479+
instead of to `child()`.
480+
474481
* See [pino.stdSerializers](#pino-stdserializers)
475482

476483
#### `msgPrefix` (String)

0 commit comments

Comments
 (0)