MCPcopy Create free account
hub / github.com/boringstack-xyz/boringstack / wrap

Function wrap

apps/api/src/config/logger/logger.ts:84–118  ·  view source on GitHub ↗
(instance: pino.Logger)

Source from the content-addressed store, hash-verified

82 }
83 }
84
85 method.apply(this, args);
86 },
87 },
88 mixin: traceMixin,
89});
90
91type ChildBindings = Record<string, unknown>;
92type 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 */
100interface 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
110const 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 };

Callers 1

logger.tsFile · 0.85

Calls 1

callFunction · 0.85

Tested by

no test coverage detected