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

bindings formatter not called when creating child logger bug #1700

Closed
nadhifikbarw opened this issue Apr 28, 2023 · 4 comments
Closed

bindings formatter not called when creating child logger bug #1700

nadhifikbarw opened this issue Apr 28, 2023 · 4 comments

Comments

@nadhifikbarw
Copy link
Contributor

According to docs

Changes the shape of the bindings. The default shape is { pid, hostname }. The function takes a single argument, the bindings object. It will be called every time a child logger is created.

But with this simple reproduction, it doesn't seem to be the case

"use strict";
const pino = require('pino');
const log = pino({
  formatters: {
    bindings(b) {
      console.log('will be called every time a child logger is created')
      return { pid: b.pid }
    }
  }
})
log.info('Test Main Logger');
const child = log.child({ bindprop: 42 });
child.info('Test Child Logger');
const child2 = log.child({ bindprop2: 101 });
child2.info('Test Child Logger 2');

Result

will be called every time a child logger is created
{"level":30,"time":1682657223899,"pid":12868,"msg":"Test Main Logger"}
{"level":30,"time":1682657223900,"pid":12868,"bindprop":42,"msg":"Test Child Logger"}
{"level":30,"time":1682657223900,"pid":12868,"bindprop2":101,"msg":"Test Child Logger 2"}

Would love to help, but i was bit puzzled on where to start when reading the source code 😢

@nadhifikbarw nadhifikbarw changed the title bindings formatter not called when creating child logger bindings formatter not called when creating child logger bug Apr 28, 2023
@mcollina
Copy link
Member

mcollina commented May 2, 2023

The docs is incorrect.

As you can see in https://github.com/pinojs/pino/pull/775/files#diff-78c851c106059931b9042837eb4d521a7650b32535f306d9cb85bbddef22f877R108, the bindings configuration is reset when child is created. Can you send a PR to update the docs?

@nadhifikbarw
Copy link
Contributor Author

nadhifikbarw commented May 2, 2023

@mcollina Updated docs #1702

@mcollina mcollina closed this as completed May 2, 2023
@mcollina
Copy link
Member

mcollina commented May 2, 2023

Thx!

@github-actions
Copy link

github-actions bot commented Jun 2, 2023

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 Jun 2, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

2 participants