pino
pino copied to clipboard
Make logger.child() bindings type save
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?
@kibertoad could you take a look?
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.
The v6 type def are maintained at definitelytyped.
@kammerjaeger Did you manage to resolve this?
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.
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.