-
Notifications
You must be signed in to change notification settings - Fork 878
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
#135 - child logger names #138
Conversation
In my opinion this is a conflict. The To properly solve #135, if overriding is desired, then it should only happen to the |
The current approach is to not set a global name, and then add it to all the children. Would that work for you? Possibly it's fine to support the override |
EDITED x 2 well. My use-case is around managing warn levels. root-logger created with Then, the web server creates a child-logger per request, adds req_id (the infra does that, great). Now in our infra-level user code we create more specific child-loggers with more binding (through some infra API), that provides a more specific name - based on the web-operation invoked (see openapi spec). |
I think that if the user choses to override name - it's his choice and it should be respected. I did spent time thinking how to prevent the repetition in the chindings (there will be a the default name, and a later cascading passed name). I could not find an elegant way to do it. So I left it... |
@mcollina - thanks for asking. |
I think we should change this. How about we do |
@@ -273,6 +273,10 @@ Pino.prototype.child = function child (bindings) { | |||
throw new Error('missing bindings for child Pino') | |||
} | |||
|
|||
if (bindings.name && typeof bindings.name !== 'string') { | |||
throw new Error('when provided, bindings.name must be a string for child Pino') | |||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
definitely not needed, we use this without a name to set serializers and other things.
We will need a unit test to merge this. |
Let me clarify something. We already deal with duplicate keys on child bindings. It is in our documentation -- https://github.com/pinojs/pino#duplicate-keys var pino = require('pino')
var log = pino()
var child = log.child({foo: 'bar'})
var grandchild = child.child({foo: 'baz'})
child.info('child')
grandchild.info('grandchild')
// {"pid":9907,"hostname":"dalekprime.local","level":30,"time":1480600215813,"msg":"child","foo":"bar","v":1}
// {"pid":9907,"hostname":"dalekprime.local","level":30,"time":1480600215815,"msg":"grandchild","foo":"bar","foo":"baz","v":1} There is confusion because @osher wants to override the name of the logger. As I have been saying, this is an option of the logger and really doesn't have anything to do with the child bindings. So let's look at what Bunyan does with children and names: var bunyan = require('bunyan')
var log = bunyan({name: 'blogger'})
var child = log.child({name: 'child'})
var grandchild = child.child({name: 'grandchild'})
child.info('child')
grandchild.info('grandchild')
// /private/tmp/01/node_modules/bunyan/lib/bunyan.js:378
// throw new TypeError(
// ^
//
// TypeError: invalid options.name: child cannot set logger name
// at new Logger (/private/tmp/01/node_modules/bunyan/lib/bunyan.js:378:19)
// at Logger.child (/private/tmp/01/node_modules/bunyan/lib/bunyan.js:689:12)
// at Object.<anonymous> (/private/tmp/01/btest.js:3:17)
// at Module._compile (module.js:570:32)
// at Object.Module._extensions..js (module.js:579:10)
// at Module.load (module.js:487:32)
// at tryModuleLoad (module.js:446:12)
// at Function.Module._load (module.js:438:3)
// at Module.runMain (module.js:604:10)
// at run (bootstrap_node.js:394:7) So I stand by my assertion that the |
@jsumners on second thought, I agree. |
yes I see this now - the logger is a child - a sub-logger - so the name should be the same |
@jsumners - good answer. thanks 😺 |
This pull request has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs. |
This does the trick.
I also thought about fixing the name in the chindings if it's found there - just because in this case we may be able to prevent this duplication from resulting strings.
But - I could not find a robust and high performing way that that in case there are nested objects with name property - will replace the right name attribute ... 😛
solves #135