pino icon indicating copy to clipboard operation
pino copied to clipboard

Make logger.child() bindings type save

Open kammerjaeger opened this issue 2 years ago • 3 comments

Hi,

Similar to the logger see: https://github.com/pinojs/pino/blob/d073381c10d42782cb81a74851d703e1daba0442/pino.d.ts#L279 or v6 https://github.com/DefinitelyTyped/DefinitelyTyped/blob/6de7dbcc88c855af5d4c2c0ee1fc8f1d17506e1e/types/pino/index.d.ts#L773 I would like to have a type safe child field bindings function where the bindings to logger.child are checked against a known set of allowed parameter. Background is that we want to only allow a certain set of fields in the logger so that Elastic Search can be better configured.

For v6 it would look something like this:

type Bindings<T extends ({ [key: string]: any }) = ({ [key: string]: any })> = T & {
        /**
         * @deprecated use {@link ChildLoggerOptions.level options.level}
         */
        level?: Level | string | undefined;
        /**
         * @deprecated use {@link ChildLoggerOptions.serializers options.serializers}
         */
        serializers?: { [key: string]: SerializerFn } | undefined;
}

child<T extends ({ [key: string]: any }) = ({ [key: string]: any })>(bindings: Bindings<T>, options?: ChildLoggerOptions): Logger;

For v7 it would / should be similar.

This would make my life a lot easier :-)

What do you think?

kammerjaeger avatar Feb 01 '22 01:02 kammerjaeger

@kibertoad could you take a look?

mcollina avatar Feb 01 '22 10:02 mcollina

We are currently still using v6 so I tested the changes for v6 with my code. As soon as we switch to v7 I can test them there. I'm just not sure how I can create a pr to the v6 type definition.

kammerjaeger avatar Feb 08 '22 20:02 kammerjaeger

The v6 type def are maintained at definitelytyped.

mcollina avatar Feb 08 '22 20:02 mcollina

@kammerjaeger Did you manage to resolve this?

Fdawgs avatar May 29 '23 09:05 Fdawgs

No, I tried to understand how I can change anything at definitelytyped but the documentation was so bad (or I'm just did not find the information) that I gave up on it. I still think it would be a good extension. One problem is that it is a change for an old version and not a current version.

kammerjaeger avatar May 30 '23 19:05 kammerjaeger

This issue has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

github-actions[bot] avatar Jul 11 '23 00:07 github-actions[bot]