From a6192a84f64e58621849e1c3685e981c3af70c3b Mon Sep 17 00:00:00 2001 From: Tal Efronny Date: Wed, 31 Aug 2022 14:24:20 +0300 Subject: [PATCH] Update `onChild` type to also be in options and added types tests --- pino.d.ts | 16 +++++++++++++--- test/types/pino.test-d.ts | 6 ++++++ 2 files changed, 19 insertions(+), 3 deletions(-) diff --git a/pino.d.ts b/pino.d.ts index 799c6f52d..89d8fed6a 100644 --- a/pino.d.ts +++ b/pino.d.ts @@ -36,6 +36,12 @@ type MixinMergeStrategyFn = (mergeObject: object, mixinObject: object) => object type CustomLevelLogger = Options extends { customLevels: Record } ? Record : Record +/** +* A callback that will run on each creation of a new child. +* @param child: The newly created child logger instance. +*/ +type OnChildCallback = (child: pino.Logger) => void + interface redactOptions { paths: string[]; censor?: string | ((value: any, path: string[]) => any); @@ -80,10 +86,9 @@ interface LoggerExtras extends EventEmitter { child(bindings: pino.Bindings, options?: ChildOptions): pino.Logger; /** - * A callback that will run on each creation of a new child. - * @param child: The newly created child logger instance. + * This can be used to modify the callback function on creation of a new child. */ - onChild(child: pino.Logger): void; + onChild: OnChildCallback; /** * Registers a listener function that is triggered when the level is changed. @@ -607,6 +612,11 @@ declare namespace pino { * Stringification limit of properties/elements when logging a specific object/array with circular references. Default: `100`. */ edgeLimit?: number + + /** + * Optional child creation callback. + */ + onChild?: OnChildCallback; } interface ChildLoggerOptions { diff --git a/test/types/pino.test-d.ts b/test/types/pino.test-d.ts index b2a6515ba..b09d8332d 100644 --- a/test/types/pino.test-d.ts +++ b/test/types/pino.test-d.ts @@ -340,3 +340,9 @@ cclog3.myLevel('') cclog3.childLevel('') // child itself cclog3.childLevel2('') + +const child3 = pino().child({}) +const withChildCallback = pino({ + onChild: (child: Logger) => {} +}) +withChildCallback.onChild = (child: Logger) => {} \ No newline at end of file