| 82 | } |
| 83 | } |
| 84 | |
| 85 | method.apply(this, args); |
| 86 | }, |
| 87 | }, |
| 88 | mixin: traceMixin, |
| 89 | }); |
| 90 | |
| 91 | type ChildBindings = Record<string, unknown>; |
| 92 | type EventCtx = { event: ILogEventName } & Record<string, unknown>; |
| 93 | |
| 94 | /* |
| 95 | * Pino 10 strictly requires (obj, msg) when passing context. We expose a |
| 96 | * (msg, ctx?) shim to keep call sites readable. `child()` is preserved so |
| 97 | * per-request loggers still work; its bindings are unconstrained because |
| 98 | * they're request-scoped metadata, not an event. |
| 99 | */ |
| 100 | interface IAppLogger { |
| 101 | fatal: (msg: string, ctx?: EventCtx) => void; |
| 102 | error: (msg: string, ctx?: EventCtx) => void; |
| 103 | warn: (msg: string, ctx?: EventCtx) => void; |
| 104 | info: (msg: string, ctx?: EventCtx) => void; |
| 105 | debug: (msg: string, ctx?: EventCtx) => void; |
| 106 | trace: (msg: string, ctx?: EventCtx) => void; |
| 107 | child: (bindings: ChildBindings) => IAppLogger; |
| 108 | } |
| 109 | |
| 110 | const wrap = (instance: pino.Logger): IAppLogger => { |
| 111 | const call = ( |
| 112 | method: "fatal" | "error" | "warn" | "info" | "debug" | "trace", |
| 113 | msg: string, |
| 114 | ctx: EventCtx | undefined |
| 115 | ): void => { |
| 116 | if (ctx === undefined) { |
| 117 | instance[method](msg); |
| 118 | } else { |
| 119 | instance[method](ctx, msg); |
| 120 | } |
| 121 | }; |