feat: keep parent formatters bindings function option #1950
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.
Synopsis
I have the following code, which intent to make some property values upper case (it could also be stringified, etc.):
When I run this code, I actually get the following output:
{"level":30,"time":1,"pid":7068,"hostname":"myMac","logger":"PARENT","service":"FOO","msg":"one"} {"level":30,"time":1,"pid":7068,"hostname":"myMac","logger":"PARENT","service":"FOO","partner":"apple","method":"GET","msg":"two"} {"level":30,"time":1,"pid":7068,"hostname":"myMac","logger":"child","service":"foo","msg":"one"} {"level":30,"time":1,"pid":7068,"hostname":"myMac","logger":"child","service":"foo","partner":"apple","method":"GET","msg":"two"}Shape the
bindingspassed to thechild()methodThere are currently functions to shape the log
level, thelogobject, thebindings, but I cannot see any function to shape the bindings passed to a child logger through thechild()method.I would like to be able to apply my shaping function to the
partnerproperty:{ "partner": "apple" }Keep the parent
bindingsformatters function in children loggersIn case of a global
bindingsformatters function, I would like to be able to keep thatbindingsformatters function in the logger children (and without having to pass it at eachchild()call).I would like to be able to apply my shaping function to all my
propertyPathsproperties in my logger children too, so I can get the following:{"level":30,"time":1,"pid":7068,"hostname":"myMac","logger":"PARENT","service":"FOO","msg":"one"} {"level":30,"time":1,"pid":7068,"hostname":"myMac","logger":"PARENT","service":"FOO","partner":"APPLE","method":"GET","msg":"two"} {"level":30,"time":1,"pid":7068,"hostname":"myMac","logger":"CHILD","service":"FOO","msg":"one"} {"level":30,"time":1,"pid":7068,"hostname":"myMac","logger":"CHILD","service":"FOO","partner":"APPLE","method":"GET","msg":"two"}Proposal
Add an
optionsobjectAdd a formatters
optionsobject, with akeepParentBindingsoption:The formatters
optionsobject would be passed to the child loggers, except if a newoptionsobject is passed to thechild()method.The
keepParentBindingsoptionIf
true, child loggers will keep their parentbindingsformatters function.If
falseorundefined, child loggers will have theirbindingsformatters function reset to a "no-op" formatter function, as today.The
child()methodIn the
child()method, the parentbindingsfunction will be passed or not to the child logger according to thekeepParentBindingsoption, except if a newbindingsformatters function is passed to the child logger.