Skip to content

Commit

Permalink
Update onChild type to also be in options and added types tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Diabl0269 committed Aug 31, 2022
1 parent 386f46f commit 3a85fcd
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 3 deletions.
16 changes: 13 additions & 3 deletions pino.d.ts
Expand Up @@ -36,6 +36,12 @@ type MixinMergeStrategyFn = (mergeObject: object, mixinObject: object) => object

type CustomLevelLogger<Options> = Options extends { customLevels: Record<string, number> } ? Record<keyof Options["customLevels"], LogFn> : Record<never, LogFn>

/**
* A callback that will run on each creation of a new child.
* @param child: The newly created child logger instance.
*/
type OnChildCallback<Options = LoggerOptions> = <ChildOptions extends pino.ChildLoggerOptions>(child: pino.Logger<Options & ChildOptions>) => void

interface redactOptions {
paths: string[];
censor?: string | ((value: any, path: string[]) => any);
Expand Down Expand Up @@ -80,10 +86,9 @@ interface LoggerExtras<Options = LoggerOptions> extends EventEmitter {
child<ChildOptions extends pino.ChildLoggerOptions>(bindings: pino.Bindings, options?: ChildOptions): pino.Logger<Options & ChildOptions>;

/**
* 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<ChildOptions extends pino.ChildLoggerOptions>(child: pino.Logger<Options & ChildOptions>): void;
onChild: OnChildCallback<Options>;

/**
* Registers a listener function that is triggered when the level is changed.
Expand Down Expand Up @@ -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 {
Expand Down
5 changes: 5 additions & 0 deletions test/types/pino.test-d.ts
Expand Up @@ -340,3 +340,8 @@ cclog3.myLevel('')
cclog3.childLevel('')
// child itself
cclog3.childLevel2('')

const withChildCallback = pino({
onChild: (child: Logger) => {}
})
withChildCallback.onChild = (child: Logger) => {}

0 comments on commit 3a85fcd

Please sign in to comment.