Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: pass logger/child logger as param to mixin
Passing the logger or child logger as a parameter to `mixin` allows users to set logger-specific context in the logger object that can be used by `mixin` to enrich the context to be added to the resulting JSON. One example use case for this is avoiding the "duplicate keys" caveat that comes with child loggers. If the user wants to make a known key "mergeable", they could add a custom function that concatenates values to the key and then use `mixin` to pass that merged value to the context. For example: ```js instance = pino({ mixin(obj, num, logger) { return { "tags": logger.tags } } }) instance.tags = {} instance.addTag = function (key, value) { child.tags[key] = value } function createChild (logger, ...context) { const child = logger.child(...context) child.tags = { ...logger.tags } child.addTag = function (key, value) { child.tags[key] = value } return child } instance.addTag('foo', 1) child.addTag('bar', 2) instance.info('this will only have `foo: 1`') child.info('this will have both `foo: 1` and `bar: 2`') ```
- Loading branch information