nestjs-pino 5.2.0 → 5.2.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (95) hide show
  1. package/dist/{InjectPinoLogger.d.ts → cjs/InjectPinoLogger.d.ts} +1 -1
  2. package/dist/{InjectPinoLogger.js → cjs/InjectPinoLogger.js} +2 -2
  3. package/dist/cjs/InjectPinoLogger.js.map +1 -0
  4. package/dist/{Logger.d.ts → cjs/Logger.d.ts} +2 -2
  5. package/dist/{Logger.js → cjs/Logger.js} +4 -4
  6. package/dist/cjs/Logger.js.map +1 -0
  7. package/dist/cjs/LoggerErrorInterceptor.js.map +1 -0
  8. package/dist/{LoggerModule.d.ts → cjs/LoggerModule.d.ts} +1 -1
  9. package/dist/{LoggerModule.js → cjs/LoggerModule.js} +35 -35
  10. package/dist/cjs/LoggerModule.js.map +1 -0
  11. package/dist/{NativeLogger.d.ts → cjs/NativeLogger.d.ts} +2 -2
  12. package/dist/{NativeLogger.js → cjs/NativeLogger.js} +4 -4
  13. package/dist/cjs/NativeLogger.js.map +1 -0
  14. package/dist/{PinoLogger.d.ts → cjs/PinoLogger.d.ts} +1 -1
  15. package/dist/{PinoLogger.js → cjs/PinoLogger.js} +12 -12
  16. package/dist/cjs/PinoLogger.js.map +1 -0
  17. package/dist/cjs/index.d.ts +10 -0
  18. package/dist/cjs/index.js +26 -0
  19. package/dist/cjs/index.js.map +1 -0
  20. package/dist/{microservice.d.ts → cjs/microservice.d.ts} +1 -1
  21. package/dist/{microservice.js → cjs/microservice.js} +7 -7
  22. package/dist/cjs/microservice.js.map +1 -0
  23. package/dist/cjs/params.js.map +1 -0
  24. package/dist/cjs/presets.js.map +1 -0
  25. package/dist/cjs/rootLogger.js.map +1 -0
  26. package/dist/cjs/rpc.js.map +1 -0
  27. package/dist/cjs/storage.js.map +1 -0
  28. package/dist/esm/InjectPinoLogger.d.ts +5 -0
  29. package/dist/esm/InjectPinoLogger.js +25 -0
  30. package/dist/esm/InjectPinoLogger.js.map +1 -0
  31. package/dist/esm/Logger.d.ts +34 -0
  32. package/dist/esm/Logger.js +100 -0
  33. package/dist/esm/Logger.js.map +1 -0
  34. package/dist/esm/LoggerErrorInterceptor.d.ts +5 -0
  35. package/dist/esm/LoggerErrorInterceptor.js +32 -0
  36. package/dist/esm/LoggerErrorInterceptor.js.map +1 -0
  37. package/dist/esm/LoggerModule.d.ts +22 -0
  38. package/dist/esm/LoggerModule.js +188 -0
  39. package/dist/esm/LoggerModule.js.map +1 -0
  40. package/dist/esm/NativeLogger.d.ts +22 -0
  41. package/dist/esm/NativeLogger.js +196 -0
  42. package/dist/esm/NativeLogger.js.map +1 -0
  43. package/dist/esm/PinoLogger.d.ts +81 -0
  44. package/dist/esm/PinoLogger.js +152 -0
  45. package/dist/esm/PinoLogger.js.map +1 -0
  46. package/dist/esm/index.d.ts +10 -0
  47. package/dist/esm/index.js +11 -0
  48. package/dist/esm/index.js.map +1 -0
  49. package/dist/esm/microservice.d.ts +47 -0
  50. package/dist/esm/microservice.js +195 -0
  51. package/dist/esm/microservice.js.map +1 -0
  52. package/dist/esm/package.json +1 -0
  53. package/dist/esm/params.d.ts +216 -0
  54. package/dist/esm/params.js +5 -0
  55. package/dist/esm/params.js.map +1 -0
  56. package/dist/esm/presets.d.ts +20 -0
  57. package/dist/esm/presets.js +33 -0
  58. package/dist/esm/presets.js.map +1 -0
  59. package/dist/esm/rootLogger.d.ts +16 -0
  60. package/dist/esm/rootLogger.js +46 -0
  61. package/dist/esm/rootLogger.js.map +1 -0
  62. package/dist/esm/rpc.d.ts +35 -0
  63. package/dist/esm/rpc.js +101 -0
  64. package/dist/esm/rpc.js.map +1 -0
  65. package/dist/esm/storage.d.ts +8 -0
  66. package/dist/esm/storage.js +11 -0
  67. package/dist/esm/storage.js.map +1 -0
  68. package/package.json +12 -6
  69. package/dist/InjectPinoLogger.js.map +0 -1
  70. package/dist/Logger.js.map +0 -1
  71. package/dist/LoggerErrorInterceptor.js.map +0 -1
  72. package/dist/LoggerModule.js.map +0 -1
  73. package/dist/NativeLogger.js.map +0 -1
  74. package/dist/PinoLogger.js.map +0 -1
  75. package/dist/index.d.ts +0 -10
  76. package/dist/index.js +0 -26
  77. package/dist/index.js.map +0 -1
  78. package/dist/microservice.js.map +0 -1
  79. package/dist/params.js.map +0 -1
  80. package/dist/presets.js.map +0 -1
  81. package/dist/rootLogger.js.map +0 -1
  82. package/dist/rpc.js.map +0 -1
  83. package/dist/storage.js.map +0 -1
  84. /package/dist/{LoggerErrorInterceptor.d.ts → cjs/LoggerErrorInterceptor.d.ts} +0 -0
  85. /package/dist/{LoggerErrorInterceptor.js → cjs/LoggerErrorInterceptor.js} +0 -0
  86. /package/dist/{params.d.ts → cjs/params.d.ts} +0 -0
  87. /package/dist/{params.js → cjs/params.js} +0 -0
  88. /package/dist/{presets.d.ts → cjs/presets.d.ts} +0 -0
  89. /package/dist/{presets.js → cjs/presets.js} +0 -0
  90. /package/dist/{rootLogger.d.ts → cjs/rootLogger.d.ts} +0 -0
  91. /package/dist/{rootLogger.js → cjs/rootLogger.js} +0 -0
  92. /package/dist/{rpc.d.ts → cjs/rpc.d.ts} +0 -0
  93. /package/dist/{rpc.js → cjs/rpc.js} +0 -0
  94. /package/dist/{storage.d.ts → cjs/storage.d.ts} +0 -0
  95. /package/dist/{storage.js → cjs/storage.js} +0 -0
@@ -0,0 +1 @@
1
+ {"version":3,"file":"params.js","sourceRoot":"","sources":["../../src/params.ts"],"names":[],"mappings":";;;;AAkSA,wBACE,YAAiB;IAEjB,OAAO,CAAC,CAAC,YAAY,IAAI,QAAQ,IAAI,YAAY,CAAC;AACpD,CAAC;AAEY,QAAA,qBAAqB,GAAG,aAAa,CAAC","sourcesContent":["import { IncomingMessage, ServerResponse } from 'node:http';\n\nimport {\n ExecutionContext,\n FactoryProvider,\n MiddlewareConsumer,\n ModuleMetadata,\n} from '@nestjs/common';\nimport { DestinationStream, LevelWithSilent, Logger } from 'pino';\nimport { Options, ReqId } from 'pino-http';\n\n// The `@nestjs/common/interfaces` subpath stopped resolving in v12, where the\n// package is ESM and its exports map turns `./interfaces` into a missing\n// `interfaces.js`. `MiddlewareConfigProxy` is not re-exported from the root\n// either, so derive it from `MiddlewareConsumer`.\nexport type MiddlewareConfigProxy = ReturnType<MiddlewareConsumer['apply']>;\n\nexport type PassedLogger<CustomLevels extends string = never> = {\n logger: Logger<CustomLevels>;\n};\n\n/**\n * The type parameters are all optional and default to what `pino-http` itself\n * defaults to, so `Params` keeps working unparameterised.\n *\n * @typeParam IM - request type, e.g. express' `Request`\n * @typeParam SR - response type, e.g. express' `Response`\n * @typeParam CustomLevels - union of the `customLevels` keys, if any\n */\nexport interface Params<\n IM = IncomingMessage,\n SR = ServerResponse,\n CustomLevels extends string = never,\n> {\n /**\n * Optional parameters for `pino-http` module\n * @see https://github.com/pinojs/pino-http#pinohttpopts-stream\n */\n pinoHttp?:\n | Options<IM, SR, CustomLevels>\n | DestinationStream\n | [Options<IM, SR, CustomLevels>, DestinationStream];\n\n /**\n * Optional parameter for routing. It should implement interface of\n * parameters of NestJS built-in `MiddlewareConfigProxy['forRoutes']`.\n * @see https://docs.nestjs.com/middleware#applying-middleware\n * It can be used for both disabling automatic req/res logs and\n * removing request context from following logs. It works for all requests by\n * default. If you only need to turn off the automatic request/response\n * logging for some specific (or all) routes but keep request context for app\n * logs use `pinoHttp.autoLogging` field.\n */\n exclude?: Parameters<MiddlewareConfigProxy['exclude']>;\n\n /**\n * Optional parameter for routing. It should implement interface of\n * parameters of NestJS built-in `MiddlewareConfigProxy['forRoutes']`.\n * @see https://docs.nestjs.com/middleware#applying-middleware\n * It can be used for both disabling automatic req/res logs and\n * removing request context from following logs. It works for all requests by\n * default. If you only need to turn off the automatic request/response\n * logging for some specific (or all) routes but keep request context for app\n * logs use `pinoHttp.autoLogging` field.\n */\n forRoutes?: Parameters<MiddlewareConfigProxy['forRoutes']>;\n\n /**\n * Optional parameter to skip pino configuration in case you are using\n * FastifyAdapter, and already configure logger in adapter's config. The Pros\n * and cons of this approach are described in the FAQ section of the\n * documentation:\n * @see https://github.com/iamolegga/nestjs-pino#faq.\n */\n useExisting?: true;\n\n /**\n * Optional parameter to change property name `context` in resulted logs,\n * so logs will be like:\n * {\"level\":30, ... \"RENAME_CONTEXT_VALUE_HERE\":\"AppController\" }\n */\n renameContext?: string;\n\n /**\n * Optional parameter to also assign the response logger during calls to\n * `PinoLogger.assign`. By default, `assign` does not impact response logs\n * (e.g.`Request completed`).\n */\n assignResponse?: boolean;\n\n /**\n * Optional parameters for `NativeLogger`, mirroring the `ConsoleLogger`\n * options of the same name so that an application can move over keeping its\n * existing configuration. Unlike NestJS, both are honoured on every supported\n * NestJS version; only the default of `structuredParams` follows the\n * `ConsoleLogger` that is actually installed.\n */\n nativeLogger?: {\n /**\n * If enabled, plain objects logged after the message are attached to the\n * same entry as `params` instead of being logged as separate entries.\n * @default true on NestJS 12+, false before that\n */\n structuredParams?: boolean;\n\n /**\n * If enabled, params are spread into the root of the record instead of\n * nested under `params`. Keys already used by the log record itself are\n * never overwritten.\n * @default false\n */\n flattenParams?: boolean;\n };\n\n /**\n * Enables `pino-http`-like automatic logging and, more importantly, a logging\n * context for microservice message handlers, so that `PinoLogger.assign` and\n * inherited fields work there the way they do in an HTTP request. Pass `true`\n * for the defaults.\n *\n * Implemented on the NestJS 12 microservices pre-request hooks, which the\n * module registers by itself; 12.0.2 or later, because earlier 12.0.x\n * releases mangled a handler's plain return value once a hook was present.\n * Two caveats follow from how NestJS wires them: on NestJS 11 the API does\n * not exist and this is ignored with a warning, and a hybrid application has\n * to be connected with `{ inheritAppConfig: true }` for the hook to reach its\n * microservice.\n * @see https://docs.nestjs.com/microservices/pre-request-hooks\n */\n microservice?: boolean | MicroserviceParams<CustomLevels>;\n}\n\n/**\n * Options for automatic logging of microservice messages, deliberately shaped\n * after `pino-http`'s: every parameter that does not need the request or the\n * response keeps its name and meaning, and the ones that do take an\n * `ExecutionContext` instead. Use {@link getRpcInfo} inside them to reach the\n * pattern, the transport and whether the handler is a `@MessagePattern` or an\n * `@EventPattern`.\n *\n * Everything pino itself is configured with — level, transport, redact,\n * serializers, formatters — stays in `pinoHttp`, which builds the one logger\n * both halves of the application share.\n *\n * @see https://github.com/pinojs/pino-http#pinohttpopts-stream\n */\nexport interface MicroserviceParams<CustomLevels extends string = never> {\n /**\n * Set to `false` to stop logging a line per message. The logging *context*\n * is still established either way, so `PinoLogger.assign` and the inherited\n * fields keep working.\n * @default true\n */\n autoLogging?:\n | boolean\n | {\n /** Skip the automatic logs for the messages this returns `true` for. */\n ignore?: (context: ExecutionContext) => boolean;\n };\n\n /**\n * Level of the `received` and `completed` logs. Errors default to `error`\n * regardless of this — unlike `pino-http`, where a failed request is logged\n * at `useLevel` too — so that lowering this to quiet down events does not\n * also hide failures. Use `customLogLevel` to change the error level.\n * Cannot be combined with `customLogLevel`.\n * @default 'info'\n */\n useLevel?: LevelWithSilent | CustomLevels;\n\n /**\n * Decides the level of every automatic log, including the error one. Note\n * that the hook runs before any `@Catch()` filter, so `error` is set for\n * exceptions the application goes on to handle itself, an `RpcException`\n * thrown on purpose included.\n */\n customLogLevel?: (\n context: ExecutionContext,\n error?: Error,\n ) => LevelWithSilent | CustomLevels;\n\n /**\n * Generates the value bound as `reqId`. Defaults to an incrementing counter,\n * as in `pino-http`; a correlation id off the transport context is usually a\n * better choice.\n */\n genReqId?: (context: ExecutionContext) => ReqId;\n\n /**\n * Setting this — or `customReceivedObject` — is what enables the log on\n * arrival. There is no default text, so nothing is logged on arrival unless\n * asked for, exactly as in `pino-http`.\n */\n customReceivedMessage?: (context: ExecutionContext) => string;\n\n /** @default `'message completed'`, or `'event completed'` for an `@EventPattern` */\n customSuccessMessage?: (\n context: ExecutionContext,\n result: unknown,\n responseTime: number,\n ) => string;\n\n /** @default `'message errored'`, or `'event errored'` for an `@EventPattern` */\n customErrorMessage?: (\n context: ExecutionContext,\n error: Error,\n responseTime: number,\n ) => string;\n\n /**\n * Fields of the log on arrival, which it enables the same way\n * `customReceivedMessage` does. There is no default object, so what it\n * returns is logged as is.\n */\n customReceivedObject?: (context: ExecutionContext) => object;\n\n /**\n * Replaces the fields of the `completed` log. `value` is what would be logged\n * otherwise — `responseTime` under its configured key — and is not merged\n * back in, so spread it if the extra fields should come on top.\n */\n customSuccessObject?: (\n context: ExecutionContext,\n result: unknown,\n value: object,\n ) => object;\n\n /**\n * Replaces the fields of the `errored` log. `value` holds `err` and\n * `responseTime` under their configured keys and, as with\n * `customSuccessObject`, is not merged back in.\n */\n customErrorObject?: (\n context: ExecutionContext,\n error: Error,\n value: object,\n ) => object;\n\n /** Extra fields bound to every log made while handling the message. */\n customProps?: (context: ExecutionContext) => object;\n\n /**\n * Renames the keys this adds to the log record. The `rpc` key is the\n * microservice counterpart of `pino-http`'s `req`/`res`.\n */\n customAttributeKeys?: {\n /** @default 'rpc' */\n rpc?: string;\n /** @default 'err' */\n err?: string;\n /** @default 'reqId' */\n reqId?: string;\n /** @default 'responseTime' */\n responseTime?: string;\n };\n\n /**\n * Bind only `reqId`, leaving the `rpc` object out of the logs made while\n * handling the message. Mirrors `pino-http`'s `quietReqLogger`.\n */\n quietRpcLogger?: boolean;\n\n /**\n * Leave the `rpc` object out of the `completed`/`errored` log, which repeats\n * what the surrounding logs already carry. Mirrors `quietResLogger`.\n */\n quietResLogger?: boolean;\n\n /**\n * Log the message payload as `rpc.payload`. Off by default: payloads are\n * unbounded in size and routinely carry personal data. `redact` and a\n * `serializers.rpc` entry in `pinoHttp` apply to it as to anything else.\n * @default false\n */\n includePayload?: boolean;\n}\n\nexport interface LoggerModuleAsyncParams<\n IM = IncomingMessage,\n SR = ServerResponse,\n CustomLevels extends string = never,\n> extends Pick<ModuleMetadata, 'imports' | 'providers'>,\n // `provide` is deliberately not picked: `forRootAsync` sets it to\n // `PARAMS_PROVIDER_TOKEN` itself, so a caller-supplied token would only be\n // overwritten.\n Pick<\n FactoryProvider<Params<IM, SR, CustomLevels>>,\n 'useFactory' | 'inject'\n > {}\n\nexport function isPassedLogger(\n pinoHttpProp: any,\n): pinoHttpProp is PassedLogger {\n return !!pinoHttpProp && 'logger' in pinoHttpProp;\n}\n\nexport const PARAMS_PROVIDER_TOKEN = 'pino-params';\n"]}
@@ -0,0 +1 @@
1
+ {"version":3,"file":"presets.js","sourceRoot":"","sources":["../../src/presets.ts"],"names":[],"mappings":";;;AAEA,MAAM,SAAS,GAA2B;IACxC,KAAK,EAAE,SAAS;IAChB,IAAI,EAAE,KAAK;CACZ,CAAC;AAEF;;;;;;;;;;;;;;;;;GAiBG;AACU,QAAA,mBAAmB,GAAY;IAC1C,UAAU,EAAE,SAAS;IACrB,SAAS,EAAE,GAAG,EAAE,CAAC,gBAAgB,IAAI,CAAC,GAAG,EAAE,EAAE;IAC7C,IAAI,EAAE,EAAE,GAAG,EAAE,OAAO,CAAC,GAAG,EAAE;IAC1B,UAAU,EAAE;QACV,KAAK,CAAC,KAAK;YACT,OAAO,EAAE,KAAK,EAAE,SAAS,CAAC,KAAK,CAAC,IAAI,KAAK,EAAE,CAAC;QAC9C,CAAC;KACF;CACF,CAAC","sourcesContent":["import { Options } from 'pino-http';\n\nconst LEVEL_MAP: Record<string, string> = {\n trace: 'verbose',\n info: 'log',\n};\n\n/**\n * Pino options preset that makes pino's JSON output match the field names and\n * format of NestJS's built-in `ConsoleLogger` in JSON mode.\n *\n * ConsoleLogger JSON: {\"level\":\"log\",\"pid\":17580,\"timestamp\":1765305000999,\"message\":\"Hello World\",\"context\":\"AppService\"}\n *\n * Use together with `NativeLogger` for a full drop-in replacement:\n *\n * ```ts\n * import { NativeLogger, nativeLoggerOptions } from 'nestjs-pino';\n *\n * @Module({ imports: [LoggerModule.forRoot({ pinoHttp: nativeLoggerOptions })] })\n * class AppModule {}\n *\n * const app = await NestFactory.create(AppModule, { bufferLogs: true });\n * app.useLogger(app.get(NativeLogger));\n * ```\n */\nexport const nativeLoggerOptions: Options = {\n messageKey: 'message',\n timestamp: () => `,\"timestamp\":${Date.now()}`,\n base: { pid: process.pid },\n formatters: {\n level(label) {\n return { level: LEVEL_MAP[label] || label };\n },\n },\n};\n"]}
@@ -0,0 +1 @@
1
+ {"version":3,"file":"rootLogger.js","sourceRoot":"","sources":["../../src/rootLogger.ts"],"names":[],"mappings":";;;;;;AACA,yCAAiD;AAYjD;;;;;;;;;;;;;;GAcG;AACH,IAAI,UAAkC,CAAC;AAEvC,SAAS,mBAAmB,CAAC,KAAc;IACzC,OAAO,CACL,CAAC,CAAC,KAAK;QACP,OAAO,KAAK,KAAK,QAAQ;QACzB,OAAQ,KAA2B,CAAC,KAAK,KAAK,UAAU,CACzD,CAAC;AACJ,CAAC;AAED,gCAAuC,MAAuB;IAC5D,IAAI,CAAC,UAAU,EAAE,CAAC;QAChB,IAAI,KAAK,CAAC,OAAO,CAAC,MAAM,CAAC,EAAE,CAAC;YAC1B,UAAU,GAAG,IAAA,oBAAQ,EAAC,GAAI,MAAmC,CAAC,CAAC;QACjE,CAAC;aAAM,IAAI,mBAAmB,CAAC,MAAM,CAAC,EAAE,CAAC;YACvC,UAAU,GAAG,IAAA,oBAAQ,EAAC,MAAM,CAAC,CAAC;QAChC,CAAC;aAAM,CAAC;YACN,UAAU,GAAG,IAAA,oBAAQ,EAAC,MAAa,CAAC,CAAC;QACvC,CAAC;IACH,CAAC;IACD,OAAO,UAAU,CAAC;AACpB,CAAC;AAED,0BAAiC,MAAuB;IACtD,OAAO,sBAAsB,CAAC,MAAM,CAAC,CAAC,MAAM,CAAC;AAC/C,CAAC;AAED;IACE,OAAO,UAAU,EAAE,MAAM,CAAC;AAC5B,CAAC;AAED;IACE,UAAU,GAAG,SAAS,CAAC;AACzB,CAAC","sourcesContent":["import { DestinationStream, Logger } from 'pino';\nimport { HttpLogger, pinoHttp } from 'pino-http';\n\n/**\n * These helpers only forward their argument to `pino-http`, so they are\n * deliberately blind to the request, response and custom-level type arguments\n * the caller picked. It cannot be spelled as `Params<any, any, any>['pinoHttp']`\n * either: pino's `onChild` makes two `Logger<CustomLevels>` instantiations\n * mutually non-assignable, so no instantiation is general enough to accept the\n * others.\n */\ntype PinoHttpParams = object;\n\n/**\n * The one `pino-http` instance of the application, and with it the one pino\n * logger everything else derives from.\n *\n * It used to be built twice: once in the `PinoLogger` constructor, for logs made\n * outside a request, and once by `pino-http` inside the middleware, for logs\n * made inside one. The two were unrelated objects writing to the same\n * destination, so a `transport` was spawned twice, `PinoLogger.root` only ever\n * governed the request half, and an application with no HTTP middleware — a\n * microservice, a standalone script — had no root at all.\n *\n * `pinoHttp()` is just a factory, so nothing requires it to be called from\n * `configure()`. It is called on first use instead, whoever gets there first,\n * and `configure()` mounts that same instance as the middleware.\n */\nlet middleware: HttpLogger | undefined;\n\nfunction isDestinationStream(value: unknown): value is DestinationStream {\n return (\n !!value &&\n typeof value === 'object' &&\n typeof (value as DestinationStream).write === 'function'\n );\n}\n\nexport function ensureLoggerMiddleware(params?: PinoHttpParams): HttpLogger {\n if (!middleware) {\n if (Array.isArray(params)) {\n middleware = pinoHttp(...(params as [any, DestinationStream]));\n } else if (isDestinationStream(params)) {\n middleware = pinoHttp(params);\n } else {\n middleware = pinoHttp(params as any);\n }\n }\n return middleware;\n}\n\nexport function ensureRootLogger(params?: PinoHttpParams): Logger {\n return ensureLoggerMiddleware(params).logger;\n}\n\nexport function getRootLogger(): Logger | undefined {\n return middleware?.logger;\n}\n\nexport function resetRootLogger(): void {\n middleware = undefined;\n}\n"]}
@@ -0,0 +1 @@
1
+ {"version":3,"file":"rpc.js","sourceRoot":"","sources":["../../src/rpc.ts"],"names":[],"mappings":";;;AAEA;;;;;GAKG;AACH,MAAM,gBAAgB,GAAG,uBAAuB,CAAC;AACjD,MAAM,wBAAwB,GAAG,4BAA4B,CAAC;AAC9D,MAAM,kBAAkB,GAAG,yBAAyB,CAAC;AAErD,8CAA8C;AAC9C,MAAM,aAAa,GAAG,CAAC,CAAC;AAExB,2EAA2E;AAC3E,MAAM,eAAe,GAAG;IACtB,KAAK;IACL,OAAO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O,CAAC,WAAW,EAAE,CAAC,UAAU,EAAE,CAAC;IAClD,CAAC;IAAC,MAAM,CAAC;QACP,OAAO,SAAS,CAAC;IACnB,CAAC;IAED,MAAM,IAAI,GAAI,UAAkD,EAAE,WAAW;QAC3E,EAAE,IAAI,CAAC;IACT,IACE,OAAO,IAAI,KAAK,QAAQ;QACxB,IAAI,KAAK,cAAc;QACvB,CAAC,IAAI,CAAC,QAAQ,CAAC,cAAc,CAAC,EAC9B,CAAC;QACD,OAAO,SAAS,CAAC;IACnB,CAAC;IACD,OAAO,IAAI,CAAC,KAAK,CAAC,CAAC,EAAE,CAAC,cAAc,CAAC,MAAM,CAAC,CAAC,WAAW,EAAE,CAAC;AAC7D,CAAC;AAED;;;;;;;;;;;;;;GAcG;AACH,oBAA2B,OAAyB;IAClD,MAAM,OAAO,GAAG,OAAO,CAAC,UAAU,EAAE,EAEvB,CAAC;IAEd,IAAI,UAAU,GAAG,OAAO,IAAI,eAAe,CAAC,GAAG,CAAC,OAAO,CAAC,CAAC;IACzD,IAAI,CAAC,UAAU,EAAE,CAAC;QAChB,UAAU,GAAG,cAAc,CAAC,OAAO,CAAC,CAAC;QACrC,IAAI,OAAO,EAAE,CAAC;YACZ,eAAe,CAAC,GAAG,CAAC,OAAO,EAAE,UAAU,CAAC,CAAC;QAC3C,CAAC;IACH,CAAC;IAED,OAAO;QACL,IAAI,EAAE,UAAU,CAAC,IAAI;QACrB,OAAO,EAAE,UAAU,CAAC,OAAO;QAC3B,SAAS,EAAE,aAAa,CAAC,OAAO,CAAC,IAAI,UAAU,CAAC,SAAS;QACzD,UAAU,EAAE,OAAO,CAAC,QAAQ,EAAE,EAAE,EAAE,IAAI,IAAI,EAAE;QAC5C,OAAO,EAAE,OAAO,EAAE,IAAI,IAAI,EAAE;KAC7B,CAAC;AACJ,CAAC","sourcesContent":["import { ExecutionContext } from '@nestjs/common';\n\n/**\n * Read reflectively rather than imported, so that `@nestjs/microservices` stays\n * a dependency of the *application* and never of this package. These keys are\n * part of the metadata `@MessagePattern` and `@EventPattern` write, and are\n * stable across NestJS 11 and 12.\n */\nconst PATTERN_METADATA = 'microservices:pattern';\nconst PATTERN_HANDLER_METADATA = 'microservices:handler_type';\nconst TRANSPORT_METADATA = 'microservices:transport';\n\n/** `PatternHandler.EVENT`; `MESSAGE` is 1. */\nconst EVENT_HANDLER = 2;\n\n/** Indexed by the `Transport` enum, for the rare handler that pins one. */\nconst TRANSPORT_NAMES = [\n 'tcp',\n 'redis',\n 'nats',\n 'mqtt',\n 'grpc',\n 'rmq',\n 'kafka',\n];\n\nconst CONTEXT_SUFFIX = 'Context';\n\nexport type RpcType = 'message' | 'event';\n\n/**\n * What is known about the message being handled. This is also what is logged\n * under the `rpc` key, apart from the payload, which `includePayload` adds.\n */\nexport interface RpcInfo {\n /**\n * `'message'` for `@MessagePattern`, where the caller is waiting for a reply,\n * `'event'` for `@EventPattern`, where nobody is.\n */\n type: RpcType;\n\n /** The pattern the handler is registered for, as given to the decorator. */\n pattern: string | number | symbol | Record<string, unknown> | undefined;\n\n /** Lowercased transport name, e.g. `'rmq'`, `'kafka'`, `'tcp'`. */\n transport: string | undefined;\n\n controller: string;\n\n handler: string;\n}\n\ntype StaticRpcInfo = Pick<RpcInfo, 'type' | 'pattern' | 'transport'>;\n\n// The pattern and the kind are fixed for a handler method, so they are read\n// once instead of on every message.\nconst staticInfoCache = new WeakMap<(...args: any[]) => any, StaticRpcInfo>();\n\nfunction readStaticInfo(\n handler: ((...args: any[]) => any) | undefined,\n): StaticRpcInfo {\n if (!handler || typeof Reflect.getMetadata !== 'function') {\n return { type: 'message', pattern: undefined, transport: undefined };\n }\n\n const patterns = Reflect.getMetadata(PATTERN_METADATA, handler);\n const kind = Reflect.getMetadata(PATTERN_HANDLER_METADATA, handler);\n const transport = Reflect.getMetadata(TRANSPORT_METADATA, handler);\n\n return {\n // A handler with no metadata at all is not necessarily a mistake — a custom\n // transport strategy can register one — so it is reported as a message,\n // which is both the more common kind and the safer default.\n type: kind === EVENT_HANDLER ? 'event' : 'message',\n pattern: Array.isArray(patterns)\n ? patterns.length > 1\n ? patterns\n : patterns[0]\n : patterns,\n transport:\n typeof transport === 'number' ? TRANSPORT_NAMES[transport] : undefined,\n };\n}\n\n/**\n * The transport a message actually arrived on, taken from the class of the\n * per-message context — `RmqContext`, `KafkaContext`, `TcpContext` and so on.\n * More reliable than the decorator metadata, which is only set when a handler\n * explicitly pins a transport.\n */\nfunction readTransport(context: ExecutionContext): string | undefined {\n let rpcContext: unknown;\n try {\n rpcContext = context.switchToRpc().getContext();\n } catch {\n return undefined;\n }\n\n const name = (rpcContext as { constructor?: { name?: string } })?.constructor\n ?.name;\n if (\n typeof name !== 'string' ||\n name === CONTEXT_SUFFIX ||\n !name.endsWith(CONTEXT_SUFFIX)\n ) {\n return undefined;\n }\n return name.slice(0, -CONTEXT_SUFFIX.length).toLowerCase();\n}\n\n/**\n * Describes the message a microservice handler was called with.\n *\n * Every callback of the `microservice` parameters receives an `ExecutionContext`\n * and nothing else, the way `pino-http`'s callbacks receive the request, so\n * this is how they reach the pattern, the transport and — most usefully — the\n * `type`, to tell a `@MessagePattern` from an `@EventPattern`:\n *\n * ```ts\n * customLogLevel: (ctx, err) =>\n * err ? 'error' : getRpcInfo(ctx).type === 'event' ? 'debug' : 'info',\n * ```\n *\n * Never throws: a context it cannot read reports a message with no pattern.\n */\nexport function getRpcInfo(context: ExecutionContext): RpcInfo {\n const handler = context.getHandler?.() as\n | ((...args: any[]) => any)\n | undefined;\n\n let staticInfo = handler && staticInfoCache.get(handler);\n if (!staticInfo) {\n staticInfo = readStaticInfo(handler);\n if (handler) {\n staticInfoCache.set(handler, staticInfo);\n }\n }\n\n return {\n type: staticInfo.type,\n pattern: staticInfo.pattern,\n transport: readTransport(context) ?? staticInfo.transport,\n controller: context.getClass?.()?.name ?? '',\n handler: handler?.name ?? '',\n };\n}\n"]}
@@ -0,0 +1 @@
1
+ {"version":3,"file":"storage.js","sourceRoot":"","sources":["../../src/storage.ts"],"names":[],"mappings":";;;AAAA,uDAAqD;AAIrD;IAEW,MAAM;IACN,cAAc;IAFvB,YACS,MAAc,EACd,cAAuB;sBADvB,MAAM;8BACN,cAAc;IACpB,CAAC;CACL;;AAEY,QAAA,OAAO,GAAG,IAAI,oCAAiB,EAAS,CAAC","sourcesContent":["import { AsyncLocalStorage } from 'node:async_hooks';\n\nimport { Logger } from 'pino';\n\nexport class Store {\n constructor(\n public logger: Logger,\n public responseLogger?: Logger,\n ) {}\n}\n\nexport const storage = new AsyncLocalStorage<Store>();\n"]}
@@ -0,0 +1,5 @@
1
+ import { Provider } from '@nestjs/common';
2
+ import { PinoLogger } from './PinoLogger.js';
3
+ export declare function InjectPinoLogger(context?: string): PropertyDecorator & ParameterDecorator;
4
+ export declare function createProvidersForDecorated(): Array<Provider<PinoLogger>>;
5
+ export declare function getLoggerToken(context: string): string;
@@ -0,0 +1,25 @@
1
+ import { Inject } from '@nestjs/common';
2
+ import { PinoLogger } from './PinoLogger.js';
3
+ const decoratedTokenPrefix = 'PinoLogger:';
4
+ const decoratedLoggers = new Set();
5
+ export function InjectPinoLogger(context = '') {
6
+ decoratedLoggers.add(context);
7
+ return Inject(getLoggerToken(context));
8
+ }
9
+ function createDecoratedLoggerProvider(context) {
10
+ return {
11
+ provide: getLoggerToken(context),
12
+ useFactory: (logger) => {
13
+ logger.setContext(context);
14
+ return logger;
15
+ },
16
+ inject: [PinoLogger],
17
+ };
18
+ }
19
+ export function createProvidersForDecorated() {
20
+ return [...decoratedLoggers.values()].map(createDecoratedLoggerProvider);
21
+ }
22
+ export function getLoggerToken(context) {
23
+ return `${decoratedTokenPrefix}${context}`;
24
+ }
25
+ //# sourceMappingURL=InjectPinoLogger.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"InjectPinoLogger.js","sourceRoot":"","sources":["../../src/InjectPinoLogger.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAY,MAAM,gBAAgB,CAAC;AAElD,OAAO,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAC;AAE7C,MAAM,oBAAoB,GAAG,aAAa,CAAC;AAE3C,MAAM,gBAAgB,GAAG,IAAI,GAAG,EAAU,CAAC;AAE3C,MAAM,UAAU,gBAAgB,CAAC,OAAO,GAAG,EAAE;IAC3C,gBAAgB,CAAC,GAAG,CAAC,OAAO,CAAC,CAAC;IAC9B,OAAO,MAAM,CAAC,cAAc,CAAC,OAAO,CAAC,CAAC,CAAC;AACzC,CAAC;AAED,SAAS,6BAA6B,CAAC,OAAe;IACpD,OAAO;QACL,OAAO,EAAE,cAAc,CAAC,OAAO,CAAC;QAChC,UAAU,EAAE,CAAC,MAAkB,EAAE,EAAE;YACjC,MAAM,CAAC,UAAU,CAAC,OAAO,CAAC,CAAC;YAC3B,OAAO,MAAM,CAAC;QAChB,CAAC;QACD,MAAM,EAAE,CAAC,UAAU,CAAC;KACrB,CAAC;AACJ,CAAC;AAED,MAAM,UAAU,2BAA2B;IACzC,OAAO,CAAC,GAAG,gBAAgB,CAAC,MAAM,EAAE,CAAC,CAAC,GAAG,CAAC,6BAA6B,CAAC,CAAC;AAC3E,CAAC;AAED,MAAM,UAAU,cAAc,CAAC,OAAe;IAC5C,OAAO,GAAG,oBAAoB,GAAG,OAAO,EAAE,CAAC;AAC7C,CAAC","sourcesContent":["import { Inject, Provider } from '@nestjs/common';\n\nimport { PinoLogger } from './PinoLogger.js';\n\nconst decoratedTokenPrefix = 'PinoLogger:';\n\nconst decoratedLoggers = new Set<string>();\n\nexport function InjectPinoLogger(context = '') {\n decoratedLoggers.add(context);\n return Inject(getLoggerToken(context));\n}\n\nfunction createDecoratedLoggerProvider(context: string): Provider<PinoLogger> {\n return {\n provide: getLoggerToken(context),\n useFactory: (logger: PinoLogger) => {\n logger.setContext(context);\n return logger;\n },\n inject: [PinoLogger],\n };\n}\n\nexport function createProvidersForDecorated(): Array<Provider<PinoLogger>> {\n return [...decoratedLoggers.values()].map(createDecoratedLoggerProvider);\n}\n\nexport function getLoggerToken(context: string): string {\n return `${decoratedTokenPrefix}${context}`;\n}\n"]}
@@ -0,0 +1,34 @@
1
+ import { LoggerService } from '@nestjs/common';
2
+ import { PinoLogger } from './PinoLogger.js';
3
+ import { Params } from './params.js';
4
+ export declare class Logger implements LoggerService {
5
+ protected readonly logger: PinoLogger;
6
+ private readonly contextName;
7
+ constructor(logger: PinoLogger, { renameContext }: Params);
8
+ verbose(message: any, ...optionalParams: any[]): void;
9
+ debug(message: any, ...optionalParams: any[]): void;
10
+ log(message: any, ...optionalParams: any[]): void;
11
+ warn(message: any, ...optionalParams: any[]): void;
12
+ error(message: any, ...optionalParams: any[]): void;
13
+ fatal(message: any, ...optionalParams: any[]): void;
14
+ private call;
15
+ /**
16
+ * Unfortunately built-in (not only) `^.*Exception(s?)Handler$` classes call `.error`
17
+ * method with not supported contract:
18
+ *
19
+ * - ExceptionsHandler
20
+ * @see https://github.com/nestjs/nest/blob/35baf7a077bb972469097c5fea2f184b7babadfc/packages/core/exceptions/base-exception-filter.ts#L60-L63
21
+ *
22
+ * - ExceptionHandler
23
+ * @see https://github.com/nestjs/nest/blob/99ee3fd99341bcddfa408d1604050a9571b19bc9/packages/core/errors/exception-handler.ts#L9
24
+ *
25
+ * - WsExceptionsHandler
26
+ * @see https://github.com/nestjs/nest/blob/9d0551ff25c5085703bcebfa7ff3b6952869e794/packages/websockets/exceptions/base-ws-exception-filter.ts#L47-L50
27
+ *
28
+ * - RpcExceptionsHandler @see https://github.com/nestjs/nest/blob/9d0551ff25c5085703bcebfa7ff3b6952869e794/packages/microservices/exceptions/base-rpc-exception-filter.ts#L26-L30
29
+ *
30
+ * - all of them
31
+ * @see https://github.com/search?l=TypeScript&q=org%3Anestjs+logger+error+stack&type=Code
32
+ */
33
+ private isWrongExceptionsHandlerContract;
34
+ }
@@ -0,0 +1,100 @@
1
+ var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
2
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
3
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
4
+ else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
5
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
6
+ };
7
+ var __metadata = (this && this.__metadata) || function (k, v) {
8
+ if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
9
+ };
10
+ var __param = (this && this.__param) || function (paramIndex, decorator) {
11
+ return function (target, key) { decorator(target, key, paramIndex); }
12
+ };
13
+ import { Inject, Injectable } from '@nestjs/common';
14
+ import { PinoLogger } from './PinoLogger.js';
15
+ import { PARAMS_PROVIDER_TOKEN } from './params.js';
16
+ let Logger = class Logger {
17
+ logger;
18
+ contextName;
19
+ constructor(logger, { renameContext }) {
20
+ this.logger = logger;
21
+ this.contextName = renameContext || 'context';
22
+ }
23
+ verbose(message, ...optionalParams) {
24
+ this.call('trace', message, ...optionalParams);
25
+ }
26
+ debug(message, ...optionalParams) {
27
+ this.call('debug', message, ...optionalParams);
28
+ }
29
+ log(message, ...optionalParams) {
30
+ this.call('info', message, ...optionalParams);
31
+ }
32
+ warn(message, ...optionalParams) {
33
+ this.call('warn', message, ...optionalParams);
34
+ }
35
+ error(message, ...optionalParams) {
36
+ this.call('error', message, ...optionalParams);
37
+ }
38
+ fatal(message, ...optionalParams) {
39
+ this.call('fatal', message, ...optionalParams);
40
+ }
41
+ call(level, message, ...optionalParams) {
42
+ const objArg = {};
43
+ // optionalParams contains extra params passed to logger
44
+ // context name is the last item
45
+ let params = [];
46
+ if (optionalParams.length !== 0) {
47
+ objArg[this.contextName] = optionalParams[optionalParams.length - 1];
48
+ params = optionalParams.slice(0, -1);
49
+ }
50
+ if (typeof message === 'object') {
51
+ if (message instanceof Error) {
52
+ objArg.err = message;
53
+ }
54
+ else {
55
+ Object.assign(objArg, message);
56
+ }
57
+ this.logger[level](objArg, ...params);
58
+ }
59
+ else if (this.isWrongExceptionsHandlerContract(level, message, params)) {
60
+ objArg.err = new Error(message);
61
+ objArg.err.stack = params[0];
62
+ this.logger[level](objArg);
63
+ }
64
+ else {
65
+ this.logger[level](objArg, message, ...params);
66
+ }
67
+ }
68
+ /**
69
+ * Unfortunately built-in (not only) `^.*Exception(s?)Handler$` classes call `.error`
70
+ * method with not supported contract:
71
+ *
72
+ * - ExceptionsHandler
73
+ * @see https://github.com/nestjs/nest/blob/35baf7a077bb972469097c5fea2f184b7babadfc/packages/core/exceptions/base-exception-filter.ts#L60-L63
74
+ *
75
+ * - ExceptionHandler
76
+ * @see https://github.com/nestjs/nest/blob/99ee3fd99341bcddfa408d1604050a9571b19bc9/packages/core/errors/exception-handler.ts#L9
77
+ *
78
+ * - WsExceptionsHandler
79
+ * @see https://github.com/nestjs/nest/blob/9d0551ff25c5085703bcebfa7ff3b6952869e794/packages/websockets/exceptions/base-ws-exception-filter.ts#L47-L50
80
+ *
81
+ * - RpcExceptionsHandler @see https://github.com/nestjs/nest/blob/9d0551ff25c5085703bcebfa7ff3b6952869e794/packages/microservices/exceptions/base-rpc-exception-filter.ts#L26-L30
82
+ *
83
+ * - all of them
84
+ * @see https://github.com/search?l=TypeScript&q=org%3Anestjs+logger+error+stack&type=Code
85
+ */
86
+ isWrongExceptionsHandlerContract(level, message, params) {
87
+ return (level === 'error' &&
88
+ typeof message === 'string' &&
89
+ params.length === 1 &&
90
+ typeof params[0] === 'string' &&
91
+ /\n\s*at /.test(params[0]));
92
+ }
93
+ };
94
+ Logger = __decorate([
95
+ Injectable(),
96
+ __param(1, Inject(PARAMS_PROVIDER_TOKEN)),
97
+ __metadata("design:paramtypes", [PinoLogger, Object])
98
+ ], Logger);
99
+ export { Logger };
100
+ //# sourceMappingURL=Logger.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"Logger.js","sourceRoot":"","sources":["../../src/Logger.ts"],"names":[],"mappings":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AO,OAAO,KAAK,QAAQ;YAC3B,MAAM,CAAC,MAAM,KAAK,CAAC;YACnB,OAAO,MAAM,CAAC,CAAC,CAAC,KAAK,QAAQ;YAC7B,UAAU,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,CAC3B,CAAC;IACJ,CAAC;CACF,CAAA;AA5FY,MAAM;IADlB,UAAU,EAAE;IAMR,WAAA,MAAM,CAAC,qBAAqB,CAAC,CAAA;qCADH,UAAU;GAJ5B,MAAM,CA4FlB","sourcesContent":["import { Inject, Injectable, LoggerService } from '@nestjs/common';\nimport { Level } from 'pino';\nimport { PinoLogger } from './PinoLogger.js';\nimport { PARAMS_PROVIDER_TOKEN, Params } from './params.js';\n\n@Injectable()\nexport class Logger implements LoggerService {\n private readonly contextName: string;\n\n constructor(\n protected readonly logger: PinoLogger,\n @Inject(PARAMS_PROVIDER_TOKEN) { renameContext }: Params,\n ) {\n this.contextName = renameContext || 'context';\n }\n\n verbose(message: any, ...optionalParams: any[]) {\n this.call('trace', message, ...optionalParams);\n }\n\n debug(message: any, ...optionalParams: any[]) {\n this.call('debug', message, ...optionalParams);\n }\n\n log(message: any, ...optionalParams: any[]) {\n this.call('info', message, ...optionalParams);\n }\n\n warn(message: any, ...optionalParams: any[]) {\n this.call('warn', message, ...optionalParams);\n }\n\n error(message: any, ...optionalParams: any[]) {\n this.call('error', message, ...optionalParams);\n }\n\n fatal(message: any, ...optionalParams: any[]) {\n this.call('fatal', message, ...optionalParams);\n }\n\n private call(level: Level, message: any, ...optionalParams: any[]) {\n const objArg: Record<string, any> = {};\n\n // optionalParams contains extra params passed to logger\n // context name is the last item\n let params: any[] = [];\n if (optionalParams.length !== 0) {\n objArg[this.contextName] = optionalParams[optionalParams.length - 1];\n params = optionalParams.slice(0, -1);\n }\n\n if (typeof message === 'object') {\n if (message instanceof Error) {\n objArg.err = message;\n } else {\n Object.assign(objArg, message);\n }\n this.logger[level](objArg, ...params);\n } else if (this.isWrongExceptionsHandlerContract(level, message, params)) {\n objArg.err = new Error(message);\n objArg.err.stack = params[0];\n this.logger[level](objArg);\n } else {\n this.logger[level](objArg, message, ...params);\n }\n }\n\n /**\n * Unfortunately built-in (not only) `^.*Exception(s?)Handler$` classes call `.error`\n * method with not supported contract:\n *\n * - ExceptionsHandler\n * @see https://github.com/nestjs/nest/blob/35baf7a077bb972469097c5fea2f184b7babadfc/packages/core/exceptions/base-exception-filter.ts#L60-L63\n *\n * - ExceptionHandler\n * @see https://github.com/nestjs/nest/blob/99ee3fd99341bcddfa408d1604050a9571b19bc9/packages/core/errors/exception-handler.ts#L9\n *\n * - WsExceptionsHandler\n * @see https://github.com/nestjs/nest/blob/9d0551ff25c5085703bcebfa7ff3b6952869e794/packages/websockets/exceptions/base-ws-exception-filter.ts#L47-L50\n *\n * - RpcExceptionsHandler @see https://github.com/nestjs/nest/blob/9d0551ff25c5085703bcebfa7ff3b6952869e794/packages/microservices/exceptions/base-rpc-exception-filter.ts#L26-L30\n *\n * - all of them\n * @see https://github.com/search?l=TypeScript&q=org%3Anestjs+logger+error+stack&type=Code\n */\n private isWrongExceptionsHandlerContract(\n level: Level,\n message: any,\n params: any[],\n ): params is [string] {\n return (\n level === 'error' &&\n typeof message === 'string' &&\n params.length === 1 &&\n typeof params[0] === 'string' &&\n /\\n\\s*at /.test(params[0])\n );\n }\n}\n"]}
@@ -0,0 +1,5 @@
1
+ import { type CallHandler, type ExecutionContext, type NestInterceptor } from '@nestjs/common';
2
+ import { Observable } from 'rxjs';
3
+ export declare class LoggerErrorInterceptor implements NestInterceptor {
4
+ intercept(context: ExecutionContext, next: CallHandler): Observable<any> | Promise<Observable<any>>;
5
+ }
@@ -0,0 +1,32 @@
1
+ var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
2
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
3
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
4
+ else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
5
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
6
+ };
7
+ import { Injectable, } from '@nestjs/common';
8
+ import { catchError, throwError } from 'rxjs';
9
+ let LoggerErrorInterceptor = class LoggerErrorInterceptor {
10
+ intercept(context, next) {
11
+ return next.handle().pipe(catchError((error) => {
12
+ return throwError(() => {
13
+ const response = context.switchToHttp().getResponse();
14
+ if (response) {
15
+ const isFastifyResponse = response.raw !== undefined;
16
+ if (isFastifyResponse) {
17
+ response.raw.err = error;
18
+ }
19
+ else {
20
+ response.err = error;
21
+ }
22
+ }
23
+ return error;
24
+ });
25
+ }));
26
+ }
27
+ };
28
+ LoggerErrorInterceptor = __decorate([
29
+ Injectable()
30
+ ], LoggerErrorInterceptor);
31
+ export { LoggerErrorInterceptor };
32
+ //# sourceMappingURL=LoggerErrorInterceptor.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"LoggerErrorInterceptor.js","sourceRoot":"","sources":["../../src/LoggerErrorInterceptor.ts"],"names":[],"mappings":";;;;;;AAAA,OAAO,EAGL,UAAU,GAEX,MAAM,gBAAgB,CAAC;AACxB,OAAO,EAAE,UAAU,EAAc,UAAU,EAAE,MAAM,MAAM,CAAC;AAGnD,IAAM,sBAAsB,GAA5B,MAAM,sBAAsB;IACjC,SAAS,CACP,OAAyB,EACzB,IAAiB;QAEjB,OAAO,IAAI,CAAC,MAAM,EAAE,CAAC,IAAI,CACvB,UAAU,CAAC,CAAC,KAAK,EAAE,EAAE;YACnB,OAAO,UAAU,CAAC,GAAG,EAAE;gBACrB,MAAM,QAAQ,GAAG,OAAO,CAAC,YAAY,EAAE,CAAC,WAAW,EAAE,CAAC;gBAEtD,IAAI,QAAQ,EAAE,CAAC;oBACb,MAAM,iBAAiB,GAAG,QAAQ,CAAC,GAAG,KAAK,SAAS,CAAC;oBAErD,IAAI,iBAAiB,EAAE,CAAC;wBACtB,QAAQ,CAAC,GAAG,CAAC,GAAG,GAAG,KAAK,CAAC;oBAC3B,CAAC;yBAAM,CAAC;wBACN,QAAQ,CAAC,GAAG,GAAG,KAAK,CAAC;oBACvB,CAAC;gBACH,CAAC;gBAED,OAAO,KAAK,CAAC;YACf,CAAC,CAAC,CAAC;QACL,CAAC,CAAC,CACH,CAAC;IACJ,CAAC;CACF,CAAA;AAzBY,sBAAsB;IADlC,UAAU,EAAE;GACA,sBAAsB,CAyBlC","sourcesContent":["import {\n type CallHandler,\n type ExecutionContext,\n Injectable,\n type NestInterceptor,\n} from '@nestjs/common';\nimport { catchError, Observable, throwError } from 'rxjs';\n\n@Injectable()\nexport class LoggerErrorInterceptor implements NestInterceptor {\n intercept(\n context: ExecutionContext,\n next: CallHandler,\n ): Observable<any> | Promise<Observable<any>> {\n return next.handle().pipe(\n catchError((error) => {\n return throwError(() => {\n const response = context.switchToHttp().getResponse();\n\n if (response) {\n const isFastifyResponse = response.raw !== undefined;\n\n if (isFastifyResponse) {\n response.raw.err = error;\n } else {\n response.err = error;\n }\n }\n\n return error;\n });\n }),\n );\n }\n}\n"]}
@@ -0,0 +1,22 @@
1
+ import { IncomingMessage, ServerResponse } from 'node:http';
2
+ import { type DynamicModule, type MiddlewareConsumer, type NestModule } from '@nestjs/common';
3
+ import { ApplicationConfig } from '@nestjs/core';
4
+ import { type LoggerModuleAsyncParams, type Params } from './params.js';
5
+ export declare class LoggerModule implements NestModule {
6
+ private readonly params;
7
+ private readonly applicationConfig;
8
+ static forRoot<IM = IncomingMessage, SR = ServerResponse, CustomLevels extends string = never>(params?: Params<IM, SR, CustomLevels>): DynamicModule;
9
+ static forRootAsync<IM = IncomingMessage, SR = ServerResponse, CustomLevels extends string = never>(params: LoggerModuleAsyncParams<IM, SR, CustomLevels>): DynamicModule;
10
+ constructor(params: Params, applicationConfig: ApplicationConfig);
11
+ configure(consumer: MiddlewareConsumer): void;
12
+ /**
13
+ * A path excluded from the global prefix is served outside of it, while
14
+ * `DEFAULT_ROUTES` is prefixed like any other middleware route, so such a
15
+ * path would go unlogged. NestJS adds excluded paths back on its own, but
16
+ * only for routes that `RouteInfoPathExtractor.isAWildcard` recognises —
17
+ * which `{/*splat}`, with its leading slash deliberately missing, is not.
18
+ *
19
+ * Only the default applies: an explicit `forRoutes` is the user's own call.
20
+ */
21
+ private defaultRoutes;
22
+ }
@@ -0,0 +1,188 @@
1
+ var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
2
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
3
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
4
+ else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
5
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
6
+ };
7
+ var __metadata = (this && this.__metadata) || function (k, v) {
8
+ if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
9
+ };
10
+ var __param = (this && this.__param) || function (paramIndex, decorator) {
11
+ return function (target, key) { decorator(target, key, paramIndex); }
12
+ };
13
+ var LoggerModule_1;
14
+ import { Global, Inject, Module, RequestMethod, } from '@nestjs/common';
15
+ import { ApplicationConfig } from '@nestjs/core';
16
+ import { createProvidersForDecorated } from './InjectPinoLogger.js';
17
+ import { Logger } from './Logger.js';
18
+ import { getMicroserviceHook, PINO_PRE_REQUEST_HOOK, registerMicroserviceHook, } from './microservice.js';
19
+ import { NativeLogger } from './NativeLogger.js';
20
+ import { PinoLogger } from './PinoLogger.js';
21
+ import { PARAMS_PROVIDER_TOKEN, } from './params.js';
22
+ import { ensureLoggerMiddleware, ensureRootLogger } from './rootLogger.js';
23
+ import { Store, storage } from './storage.js';
24
+ /**
25
+ * path-to-regexp v8, used by express@5 and @fastify/middie@9, no longer accepts
26
+ * the unnamed `*` wildcard: NestJS auto-converts it, but warns while doing so
27
+ * as soon as a global prefix is set.
28
+ *
29
+ * The missing leading slash is deliberate, and is supported upstream: since
30
+ * @nestjs/common@11.0.8 `addLeadingSlash` leaves a path starting with `{/`
31
+ * alone. A global prefix is then applied as `/v1{/*splat}` rather than
32
+ * `/v1/{*splat}`, which matters because the latter does not match the prefix
33
+ * root itself — `/v1` would go unlogged, while `/v1/anything` would not.
34
+ */
35
+ const DEFAULT_ROUTES = [{ path: '{/*splat}', method: RequestMethod.ALL }];
36
+ let LoggerModule = LoggerModule_1 = class LoggerModule {
37
+ params;
38
+ applicationConfig;
39
+ static forRoot(params) {
40
+ const paramsProvider = {
41
+ provide: PARAMS_PROVIDER_TOKEN,
42
+ useValue: params || {},
43
+ };
44
+ const decorated = createProvidersForDecorated();
45
+ const hookProvider = createHookProvider();
46
+ return {
47
+ module: LoggerModule_1,
48
+ providers: [
49
+ Logger,
50
+ NativeLogger,
51
+ ...decorated,
52
+ PinoLogger,
53
+ paramsProvider,
54
+ hookProvider,
55
+ ],
56
+ exports: [
57
+ Logger,
58
+ NativeLogger,
59
+ ...decorated,
60
+ PinoLogger,
61
+ paramsProvider,
62
+ hookProvider,
63
+ ],
64
+ };
65
+ }
66
+ static forRootAsync(params) {
67
+ const paramsProvider = {
68
+ provide: PARAMS_PROVIDER_TOKEN,
69
+ useFactory: params.useFactory,
70
+ inject: params.inject,
71
+ };
72
+ const decorated = createProvidersForDecorated();
73
+ const hookProvider = createHookProvider();
74
+ const providers = [
75
+ Logger,
76
+ NativeLogger,
77
+ ...decorated,
78
+ PinoLogger,
79
+ paramsProvider,
80
+ hookProvider,
81
+ ...(params.providers || []),
82
+ ];
83
+ return {
84
+ module: LoggerModule_1,
85
+ imports: params.imports,
86
+ providers,
87
+ exports: [
88
+ Logger,
89
+ NativeLogger,
90
+ ...decorated,
91
+ PinoLogger,
92
+ paramsProvider,
93
+ hookProvider,
94
+ ],
95
+ };
96
+ }
97
+ constructor(params, applicationConfig) {
98
+ this.params = params;
99
+ this.applicationConfig = applicationConfig;
100
+ // Microservices have no middleware, so `configure` is never called for
101
+ // them. The hook is registered here instead, early enough that the message
102
+ // handlers being built later pick it up.
103
+ if (params.microservice) {
104
+ ensureRootLogger(params.pinoHttp);
105
+ registerMicroserviceHook(applicationConfig, params);
106
+ }
107
+ }
108
+ configure(consumer) {
109
+ const { exclude, forRoutes = this.defaultRoutes(), pinoHttp, useExisting, assignResponse, } = this.params;
110
+ const middlewares = createLoggerMiddlewares(pinoHttp || {}, useExisting, assignResponse);
111
+ if (exclude) {
112
+ consumer
113
+ .apply(...middlewares)
114
+ .exclude(...exclude)
115
+ .forRoutes(...forRoutes);
116
+ }
117
+ else {
118
+ consumer.apply(...middlewares).forRoutes(...forRoutes);
119
+ }
120
+ }
121
+ /**
122
+ * A path excluded from the global prefix is served outside of it, while
123
+ * `DEFAULT_ROUTES` is prefixed like any other middleware route, so such a
124
+ * path would go unlogged. NestJS adds excluded paths back on its own, but
125
+ * only for routes that `RouteInfoPathExtractor.isAWildcard` recognises —
126
+ * which `{/*splat}`, with its leading slash deliberately missing, is not.
127
+ *
128
+ * Only the default applies: an explicit `forRoutes` is the user's own call.
129
+ */
130
+ defaultRoutes() {
131
+ const { exclude } = this.applicationConfig.getGlobalPrefixOptions();
132
+ return [
133
+ ...DEFAULT_ROUTES,
134
+ ...(exclude ?? []).map(({ path, requestMethod }) => ({
135
+ path,
136
+ method: requestMethod,
137
+ })),
138
+ ];
139
+ }
140
+ };
141
+ LoggerModule = LoggerModule_1 = __decorate([
142
+ Global(),
143
+ Module({ providers: [Logger, NativeLogger], exports: [Logger, NativeLogger] }),
144
+ __param(0, Inject(PARAMS_PROVIDER_TOKEN)),
145
+ __metadata("design:paramtypes", [Object, ApplicationConfig])
146
+ ], LoggerModule);
147
+ export { LoggerModule };
148
+ /**
149
+ * Exposes the very hook the module registers on its own, for the one case it
150
+ * cannot reach: a hybrid application connected without `inheritAppConfig`.
151
+ */
152
+ function createHookProvider() {
153
+ return {
154
+ provide: PINO_PRE_REQUEST_HOOK,
155
+ useFactory: (params) => {
156
+ ensureRootLogger(params.pinoHttp);
157
+ return getMicroserviceHook(params);
158
+ },
159
+ inject: [PARAMS_PROVIDER_TOKEN],
160
+ };
161
+ }
162
+ function createLoggerMiddlewares(params, useExisting = false, assignResponse = false) {
163
+ if (useExisting) {
164
+ return [bindLoggerMiddlewareFactory(useExisting, assignResponse)];
165
+ }
166
+ // The same instance the rest of the application already logs through, rather
167
+ // than a second one built here: one `transport`, and a `PinoLogger.root` that
168
+ // governs every log in the application, request-scoped or not.
169
+ const middleware = ensureLoggerMiddleware(params);
170
+ // @ts-expect-error: root is readonly field, but this is the place where
171
+ // it's set actually
172
+ PinoLogger.root = middleware.logger;
173
+ return [middleware, bindLoggerMiddlewareFactory(useExisting, assignResponse)];
174
+ }
175
+ function bindLoggerMiddlewareFactory(useExisting, assignResponse) {
176
+ return function bindLoggerMiddleware(req, res, next) {
177
+ let log = req.log;
178
+ let resLog = assignResponse ? res.log : undefined;
179
+ if (!useExisting && req.allLogs) {
180
+ log = req.allLogs[req.allLogs.length - 1];
181
+ }
182
+ if (assignResponse && !useExisting && res.allLogs) {
183
+ resLog = res.allLogs[res.allLogs.length - 1];
184
+ }
185
+ storage.run(new Store(log, resLog), next);
186
+ };
187
+ }
188
+ //# sourceMappingURL=LoggerModule.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"LoggerModule.js","sourceRoot":"","sources":["../../src/LoggerModule.ts"],"names":[],"mappings":";;;;;;;;;;;;;AAEA,OAAO,EAEL,MAAM,EACN,MAAM,EAEN,MAAM,EAGN,aAAa,GACd,MAAM,gBAAgB,CAAC;AACxB,OAAO,EAAE,iBAAiB,EAAE,MAAM,cAAc,CAAC;AAEjD,OAAO,EAAE,2BAA2B,EAAE,MAAM,uBAAuB,CAAC;AACpE,OAAO,EAAE,MAAM,EAAE,MAAM,aAAa,CAAC;AACrC,OAAO,EACL,mBAAmB,EACnB,qB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oB;IACpB,UAAU,CAAC,IAAI,GAAG,UAAU,CAAC,MAAM,CAAC;IAEpC,OAAO,CAAC,UAAU,EAAE,2BAA2B,CAAC,WAAW,EAAE,cAAc,CAAC,CAAC,CAAC;AAChF,CAAC;AAED,SAAS,2BAA2B,CAClC,WAAoB,EACpB,cAAuB;IAEvB,OAAO,SAAS,oBAAoB,CAClC,GAAoB,EACpB,GAAmB,EACnB,IAAgB;QAEhB,IAAI,GAAG,GAAG,GAAG,CAAC,GAAG,CAAC;QAClB,IAAI,MAAM,GAAG,cAAc,CAAC,CAAC,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC,CAAC,SAAS,CAAC;QAElD,IAAI,CAAC,WAAW,IAAI,GAAG,CAAC,OAAO,EAAE,CAAC;YAChC,GAAG,GAAG,GAAG,CAAC,OAAO,CAAC,GAAG,CAAC,OAAO,CAAC,MAAM,GAAG,CAAC,CAAE,CAAC;QAC7C,CAAC;QACD,IAAI,cAAc,IAAI,CAAC,WAAW,IAAI,GAAG,CAAC,OAAO,EAAE,CAAC;YAClD,MAAM,GAAG,GAAG,CAAC,OAAO,CAAC,GAAG,CAAC,OAAO,CAAC,MAAM,GAAG,CAAC,CAAE,CAAC;QAChD,CAAC;QAED,OAAO,CAAC,GAAG,CAAC,IAAI,KAAK,CAAC,GAAG,EAAE,MAAM,CAAC,EAAE,IAAI,CAAC,CAAC;IAC5C,CAAC,CAAC;AACJ,CAAC","sourcesContent":["import { IncomingMessage, ServerResponse } from 'node:http';\n\nimport {\n type DynamicModule,\n Global,\n Inject,\n type MiddlewareConsumer,\n Module,\n type NestModule,\n type Provider,\n RequestMethod,\n} from '@nestjs/common';\nimport { ApplicationConfig } from '@nestjs/core';\n\nimport { createProvidersForDecorated } from './InjectPinoLogger.js';\nimport { Logger } from './Logger.js';\nimport {\n getMicroserviceHook,\n PINO_PRE_REQUEST_HOOK,\n registerMicroserviceHook,\n} from './microservice.js';\nimport { NativeLogger } from './NativeLogger.js';\nimport { PinoLogger } from './PinoLogger.js';\nimport {\n type LoggerModuleAsyncParams,\n PARAMS_PROVIDER_TOKEN,\n type Params,\n} from './params.js';\nimport { ensureLoggerMiddleware, ensureRootLogger } from './rootLogger.js';\nimport { Store, storage } from './storage.js';\n\n/**\n * path-to-regexp v8, used by express@5 and @fastify/middie@9, no longer accepts\n * the unnamed `*` wildcard: NestJS auto-converts it, but warns while doing so\n * as soon as a global prefix is set.\n *\n * The missing leading slash is deliberate, and is supported upstream: since\n * @nestjs/common@11.0.8 `addLeadingSlash` leaves a path starting with `{/`\n * alone. A global prefix is then applied as `/v1{/*splat}` rather than\n * `/v1/{*splat}`, which matters because the latter does not match the prefix\n * root itself — `/v1` would go unlogged, while `/v1/anything` would not.\n */\nconst DEFAULT_ROUTES = [{ path: '{/*splat}', method: RequestMethod.ALL }];\n\n@Global()\n@Module({ providers: [Logger, NativeLogger], exports: [Logger, NativeLogger] })\nexport class LoggerModule implements NestModule {\n static forRoot<\n IM = IncomingMessage,\n SR = ServerResponse,\n CustomLevels extends string = never,\n >(params?: Params<IM, SR, CustomLevels>): DynamicModule {\n const paramsProvider: Provider<Params<IM, SR, CustomLevels>> = {\n provide: PARAMS_PROVIDER_TOKEN,\n useValue: params || {},\n };\n\n const decorated = createProvidersForDecorated();\n const hookProvider = createHookProvider();\n\n return {\n module: LoggerModule,\n providers: [\n Logger,\n NativeLogger,\n ...decorated,\n PinoLogger,\n paramsProvider,\n hookProvider,\n ],\n exports: [\n Logger,\n NativeLogger,\n ...decorated,\n PinoLogger,\n paramsProvider,\n hookProvider,\n ],\n };\n }\n\n static forRootAsync<\n IM = IncomingMessage,\n SR = ServerResponse,\n CustomLevels extends string = never,\n >(params: LoggerModuleAsyncParams<IM, SR, CustomLevels>): DynamicModule {\n const paramsProvider: Provider<\n Params<IM, SR, CustomLevels> | Promise<Params<IM, SR, CustomLevels>>\n > = {\n provide: PARAMS_PROVIDER_TOKEN,\n useFactory: params.useFactory,\n inject: params.inject,\n };\n\n const decorated = createProvidersForDecorated();\n const hookProvider = createHookProvider();\n\n const providers: any[] = [\n Logger,\n NativeLogger,\n ...decorated,\n PinoLogger,\n paramsProvider,\n hookProvider,\n ...(params.providers || []),\n ];\n\n return {\n module: LoggerModule,\n imports: params.imports,\n providers,\n exports: [\n Logger,\n NativeLogger,\n ...decorated,\n PinoLogger,\n paramsProvider,\n hookProvider,\n ],\n };\n }\n\n constructor(\n @Inject(PARAMS_PROVIDER_TOKEN) private readonly params: Params,\n private readonly applicationConfig: ApplicationConfig,\n ) {\n // Microservices have no middleware, so `configure` is never called for\n // them. The hook is registered here instead, early enough that the message\n // handlers being built later pick it up.\n if (params.microservice) {\n ensureRootLogger(params.pinoHttp);\n registerMicroserviceHook(applicationConfig, params);\n }\n }\n\n configure(consumer: MiddlewareConsumer) {\n const {\n exclude,\n forRoutes = this.defaultRoutes(),\n pinoHttp,\n useExisting,\n assignResponse,\n } = this.params;\n\n const middlewares = createLoggerMiddlewares(\n pinoHttp || {},\n useExisting,\n assignResponse,\n );\n\n if (exclude) {\n consumer\n .apply(...middlewares)\n .exclude(...exclude)\n .forRoutes(...forRoutes);\n } else {\n consumer.apply(...middlewares).forRoutes(...forRoutes);\n }\n }\n\n /**\n * A path excluded from the global prefix is served outside of it, while\n * `DEFAULT_ROUTES` is prefixed like any other middleware route, so such a\n * path would go unlogged. NestJS adds excluded paths back on its own, but\n * only for routes that `RouteInfoPathExtractor.isAWildcard` recognises —\n * which `{/*splat}`, with its leading slash deliberately missing, is not.\n *\n * Only the default applies: an explicit `forRoutes` is the user's own call.\n */\n private defaultRoutes() {\n const { exclude } = this.applicationConfig.getGlobalPrefixOptions();\n\n return [\n ...DEFAULT_ROUTES,\n ...(exclude ?? []).map(({ path, requestMethod }) => ({\n path,\n method: requestMethod,\n })),\n ];\n }\n}\n\n/**\n * Exposes the very hook the module registers on its own, for the one case it\n * cannot reach: a hybrid application connected without `inheritAppConfig`.\n */\nfunction createHookProvider(): Provider {\n return {\n provide: PINO_PRE_REQUEST_HOOK,\n useFactory: (params: Params) => {\n ensureRootLogger(params.pinoHttp);\n return getMicroserviceHook(params);\n },\n inject: [PARAMS_PROVIDER_TOKEN],\n };\n}\n\nfunction createLoggerMiddlewares(\n params: NonNullable<Params['pinoHttp']>,\n useExisting = false,\n assignResponse = false,\n) {\n if (useExisting) {\n return [bindLoggerMiddlewareFactory(useExisting, assignResponse)];\n }\n\n // The same instance the rest of the application already logs through, rather\n // than a second one built here: one `transport`, and a `PinoLogger.root` that\n // governs every log in the application, request-scoped or not.\n const middleware = ensureLoggerMiddleware(params);\n\n // @ts-expect-error: root is readonly field, but this is the place where\n // it's set actually\n PinoLogger.root = middleware.logger;\n\n return [middleware, bindLoggerMiddlewareFactory(useExisting, assignResponse)];\n}\n\nfunction bindLoggerMiddlewareFactory(\n useExisting: boolean,\n assignResponse: boolean,\n) {\n return function bindLoggerMiddleware(\n req: IncomingMessage,\n res: ServerResponse,\n next: () => void,\n ) {\n let log = req.log;\n let resLog = assignResponse ? res.log : undefined;\n\n if (!useExisting && req.allLogs) {\n log = req.allLogs[req.allLogs.length - 1]!;\n }\n if (assignResponse && !useExisting && res.allLogs) {\n resLog = res.allLogs[res.allLogs.length - 1]!;\n }\n\n storage.run(new Store(log, resLog), next);\n };\n}\n"]}
@@ -0,0 +1,22 @@
1
+ import { type LoggerService } from '@nestjs/common';
2
+ import { PinoLogger } from './PinoLogger.js';
3
+ import { Params } from './params.js';
4
+ export declare class NativeLogger implements LoggerService {
5
+ protected readonly logger: PinoLogger;
6
+ private readonly contextName;
7
+ private readonly structuredParams;
8
+ private readonly flattenParams;
9
+ constructor(logger: PinoLogger, { renameContext, nativeLogger }: Params);
10
+ verbose(message: any, ...optionalParams: any[]): void;
11
+ debug(message: any, ...optionalParams: any[]): void;
12
+ log(message: any, ...optionalParams: any[]): void;
13
+ warn(message: any, ...optionalParams: any[]): void;
14
+ error(message: any, ...optionalParams: any[]): void;
15
+ fatal(message: any, ...optionalParams: any[]): void;
16
+ private call;
17
+ private callError;
18
+ private logSingleMessage;
19
+ private getContextAndMessagesToPrint;
20
+ private getContextAndStackAndMessagesToPrint;
21
+ private isStackFormat;
22
+ }