nestjs-pino 5.2.0 → 5.2.1-alpha.138f60

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 (96) hide show
  1. package/README.md +6 -3
  2. package/dist/{InjectPinoLogger.d.ts → cjs/InjectPinoLogger.d.ts} +1 -1
  3. package/dist/{InjectPinoLogger.js → cjs/InjectPinoLogger.js} +2 -2
  4. package/dist/cjs/InjectPinoLogger.js.map +1 -0
  5. package/dist/{Logger.d.ts → cjs/Logger.d.ts} +2 -2
  6. package/dist/{Logger.js → cjs/Logger.js} +4 -4
  7. package/dist/cjs/Logger.js.map +1 -0
  8. package/dist/cjs/LoggerErrorInterceptor.js.map +1 -0
  9. package/dist/{LoggerModule.d.ts → cjs/LoggerModule.d.ts} +1 -1
  10. package/dist/{LoggerModule.js → cjs/LoggerModule.js} +35 -35
  11. package/dist/cjs/LoggerModule.js.map +1 -0
  12. package/dist/{NativeLogger.d.ts → cjs/NativeLogger.d.ts} +3 -2
  13. package/dist/{NativeLogger.js → cjs/NativeLogger.js} +110 -13
  14. package/dist/cjs/NativeLogger.js.map +1 -0
  15. package/dist/{PinoLogger.d.ts → cjs/PinoLogger.d.ts} +1 -1
  16. package/dist/{PinoLogger.js → cjs/PinoLogger.js} +12 -12
  17. package/dist/cjs/PinoLogger.js.map +1 -0
  18. package/dist/cjs/index.d.ts +10 -0
  19. package/dist/cjs/index.js +26 -0
  20. package/dist/cjs/index.js.map +1 -0
  21. package/dist/{microservice.d.ts → cjs/microservice.d.ts} +1 -1
  22. package/dist/{microservice.js → cjs/microservice.js} +7 -7
  23. package/dist/cjs/microservice.js.map +1 -0
  24. package/dist/cjs/params.js.map +1 -0
  25. package/dist/cjs/presets.js.map +1 -0
  26. package/dist/cjs/rootLogger.js.map +1 -0
  27. package/dist/cjs/rpc.js.map +1 -0
  28. package/dist/cjs/storage.js.map +1 -0
  29. package/dist/esm/InjectPinoLogger.d.ts +5 -0
  30. package/dist/esm/InjectPinoLogger.js +25 -0
  31. package/dist/esm/InjectPinoLogger.js.map +1 -0
  32. package/dist/esm/Logger.d.ts +34 -0
  33. package/dist/esm/Logger.js +100 -0
  34. package/dist/esm/Logger.js.map +1 -0
  35. package/dist/esm/LoggerErrorInterceptor.d.ts +5 -0
  36. package/dist/esm/LoggerErrorInterceptor.js +32 -0
  37. package/dist/esm/LoggerErrorInterceptor.js.map +1 -0
  38. package/dist/esm/LoggerModule.d.ts +22 -0
  39. package/dist/esm/LoggerModule.js +188 -0
  40. package/dist/esm/LoggerModule.js.map +1 -0
  41. package/dist/esm/NativeLogger.d.ts +23 -0
  42. package/dist/esm/NativeLogger.js +293 -0
  43. package/dist/esm/NativeLogger.js.map +1 -0
  44. package/dist/esm/PinoLogger.d.ts +81 -0
  45. package/dist/esm/PinoLogger.js +152 -0
  46. package/dist/esm/PinoLogger.js.map +1 -0
  47. package/dist/esm/index.d.ts +10 -0
  48. package/dist/esm/index.js +11 -0
  49. package/dist/esm/index.js.map +1 -0
  50. package/dist/esm/microservice.d.ts +47 -0
  51. package/dist/esm/microservice.js +195 -0
  52. package/dist/esm/microservice.js.map +1 -0
  53. package/dist/esm/package.json +1 -0
  54. package/dist/esm/params.d.ts +216 -0
  55. package/dist/esm/params.js +5 -0
  56. package/dist/esm/params.js.map +1 -0
  57. package/dist/esm/presets.d.ts +20 -0
  58. package/dist/esm/presets.js +33 -0
  59. package/dist/esm/presets.js.map +1 -0
  60. package/dist/esm/rootLogger.d.ts +16 -0
  61. package/dist/esm/rootLogger.js +46 -0
  62. package/dist/esm/rootLogger.js.map +1 -0
  63. package/dist/esm/rpc.d.ts +35 -0
  64. package/dist/esm/rpc.js +101 -0
  65. package/dist/esm/rpc.js.map +1 -0
  66. package/dist/esm/storage.d.ts +8 -0
  67. package/dist/esm/storage.js +11 -0
  68. package/dist/esm/storage.js.map +1 -0
  69. package/package.json +19 -13
  70. package/dist/InjectPinoLogger.js.map +0 -1
  71. package/dist/Logger.js.map +0 -1
  72. package/dist/LoggerErrorInterceptor.js.map +0 -1
  73. package/dist/LoggerModule.js.map +0 -1
  74. package/dist/NativeLogger.js.map +0 -1
  75. package/dist/PinoLogger.js.map +0 -1
  76. package/dist/index.d.ts +0 -10
  77. package/dist/index.js +0 -26
  78. package/dist/index.js.map +0 -1
  79. package/dist/microservice.js.map +0 -1
  80. package/dist/params.js.map +0 -1
  81. package/dist/presets.js.map +0 -1
  82. package/dist/rootLogger.js.map +0 -1
  83. package/dist/rpc.js.map +0 -1
  84. package/dist/storage.js.map +0 -1
  85. /package/dist/{LoggerErrorInterceptor.d.ts → cjs/LoggerErrorInterceptor.d.ts} +0 -0
  86. /package/dist/{LoggerErrorInterceptor.js → cjs/LoggerErrorInterceptor.js} +0 -0
  87. /package/dist/{params.d.ts → cjs/params.d.ts} +0 -0
  88. /package/dist/{params.js → cjs/params.js} +0 -0
  89. /package/dist/{presets.d.ts → cjs/presets.d.ts} +0 -0
  90. /package/dist/{presets.js → cjs/presets.js} +0 -0
  91. /package/dist/{rootLogger.d.ts → cjs/rootLogger.d.ts} +0 -0
  92. /package/dist/{rootLogger.js → cjs/rootLogger.js} +0 -0
  93. /package/dist/{rpc.d.ts → cjs/rpc.d.ts} +0 -0
  94. /package/dist/{rpc.js → cjs/rpc.js} +0 -0
  95. /package/dist/{storage.d.ts → cjs/storage.d.ts} +0 -0
  96. /package/dist/{storage.js → cjs/storage.js} +0 -0
package/README.md CHANGED
@@ -178,10 +178,11 @@ That's it. Your existing `new Logger(MyService.name)` calls throughout the codeb
178
178
  - Argument parsing: last string = context, rest = separate log entries
179
179
  - Structured params: on NestJS 12, plain objects after the message are merged into a single `params` field on one entry (`ConsoleLoggerOptions.structuredParams`, on by default) — `this.logger.log('foo', { a: 1 }, { b: 2 })` → `{"message":"foo","params":{"a":1,"b":2}}`. On NestJS 11 each of them is a separate entry. `NativeLogger` follows the `ConsoleLogger` of the NestJS version you actually have, so out of the box there is nothing to configure — see below to override it
180
180
  - Error handling: `this.logger.error('msg', stackTrace, 'Ctx')` → `{"message":"msg","stack":"Error: ...","context":"Ctx"}`
181
- - Error objects: `this.logger.log(new Error('oops'))` → full error+stack as message string
182
- - Exception handler: thrown errors logged with full stack in `message` field
181
+ - Error objects: on NestJS 12.1.1+ the first error passed with the message goes to the same entry as a structured `error` field with `name`, `message`, `stack`, own primitive properties such as `code`, and the `cause` chain and `AggregateError#errors` — `this.logger.error('Checkout failed', err)` → `{"message":"Checkout failed","error":{"name":"Error","message":"Payment failed","stack":"Error: ...","cause":{...}}}`. An error passed as the message itself, including the ones logged by NestJS's exception handlers, logs its own message: `this.logger.log(new Error('oops'))` → `{"message":"oops","error":{...}}`. Before 12.1.1 an error is logged as an entry of its own, with its stack as the message
182
+ - Fatal: on NestJS 12.1.1+ `fatal` parses its arguments like `error` — `this.logger.fatal('msg', stackTrace)` → `{"message":"msg","stack":"Error: ..."}`
183
+ - Function messages: a lazy message is logged as its result, a class as its name — `this.logger.debug(() => expensive())`. Unlike `ConsoleLogger` before NestJS 12.1.1, this works on every supported version
183
184
  - Object messages: `this.logger.log({ foo: 'bar' })` → `{"message":{"foo":"bar"}}`
184
- - Field names (with `nativeLoggerOptions`): `message`, `timestamp`, `pid`, `level`, `context`, `stack`
185
+ - Field names (with `nativeLoggerOptions`): `message`, `timestamp`, `pid`, `level`, `context`, `stack`, `error`
185
186
 
186
187
  #### Keeping your ConsoleLogger options
187
188
 
@@ -968,6 +969,8 @@ import { Logger } from 'nestjs-pino';
968
969
  // ...
969
970
  ```
970
971
 
972
+ Call `app.useLogger()` before `app.init()` or `app.listen()`: since NestJS 12.1.1 the buffer is flushed by `init()` too, so with a logger set after `await app.init()` (as e2e tests often do) the startup logs have already been printed by the built-in logger.
973
+
971
974
  Note that for [standalone applications](https://docs.nestjs.com/standalone-applications), buffering has to be [flushed using app.flushLogs()](https://github.com/nestjs/nest/blob/24e6c821a0859448646fd88831f20e4c5ae50980/packages/core/nest-application-context.ts#L136) manually after custom logger is ready to be used by NestJS (refer to [this issue](https://github.com/iamolegga/nestjs-pino/issues/553) for more details):
972
975
 
973
976
  ```ts
@@ -1,5 +1,5 @@
1
1
  import { Provider } from '@nestjs/common';
2
- import { PinoLogger } from './PinoLogger';
2
+ import { PinoLogger } from './PinoLogger.js';
3
3
  export declare function InjectPinoLogger(context?: string): PropertyDecorator & ParameterDecorator;
4
4
  export declare function createProvidersForDecorated(): Array<Provider<PinoLogger>>;
5
5
  export declare function getLoggerToken(context: string): string;
@@ -4,7 +4,7 @@ exports.InjectPinoLogger = InjectPinoLogger;
4
4
  exports.createProvidersForDecorated = createProvidersForDecorated;
5
5
  exports.getLoggerToken = getLoggerToken;
6
6
  const common_1 = require("@nestjs/common");
7
- const PinoLogger_1 = require("./PinoLogger");
7
+ const PinoLogger_js_1 = require("./PinoLogger.js");
8
8
  const decoratedTokenPrefix = 'PinoLogger:';
9
9
  const decoratedLoggers = new Set();
10
10
  function InjectPinoLogger(context = '') {
@@ -18,7 +18,7 @@ function createDecoratedLoggerProvider(context) {
18
18
  logger.setContext(context);
19
19
  return logger;
20
20
  },
21
- inject: [PinoLogger_1.PinoLogger],
21
+ inject: [PinoLogger_js_1.PinoLogger],
22
22
  };
23
23
  }
24
24
  function createProvidersForDecorated() {
@@ -0,0 +1 @@
1
+ {"version":3,"file":"InjectPinoLogger.js","sourceRoot":"","sources":["../../src/InjectPinoLogger.ts"],"names":[],"mappings":";;;;;AAAA,2CAAkD;AAElD,mDAA6C;AAE7C,MAAM,oBAAoB,GAAG,aAAa,CAAC;AAE3C,MAAM,gBAAgB,GAAG,IAAI,GAAG,EAAU,CAAC;AAE3C,0BAAiC,OAAO,GAAG,EAAE;IAC3C,gBAAgB,CAAC,GAAG,CAAC,OAAO,CAAC,CAAC;IAC9B,OAAO,IAAA,eAAM,EAAC,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,0BAAU,CAAC;KACrB,CAAC;AACJ,CAAC;AAED;IACE,OAAO,CAAC,GAAG,gBAAgB,CAAC,MAAM,EAAE,CAAC,CAAC,GAAG,CAAC,6BAA6B,CAAC,CAAC;AAC3E,CAAC;AAED,wBAA+B,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"]}
@@ -1,6 +1,6 @@
1
1
  import { LoggerService } from '@nestjs/common';
2
- import { PinoLogger } from './PinoLogger';
3
- import { Params } from './params';
2
+ import { PinoLogger } from './PinoLogger.js';
3
+ import { Params } from './params.js';
4
4
  export declare class Logger implements LoggerService {
5
5
  protected readonly logger: PinoLogger;
6
6
  private readonly contextName;
@@ -14,8 +14,8 @@ var __param = (this && this.__param) || function (paramIndex, decorator) {
14
14
  Object.defineProperty(exports, "__esModule", { value: true });
15
15
  exports.Logger = void 0;
16
16
  const common_1 = require("@nestjs/common");
17
- const PinoLogger_1 = require("./PinoLogger");
18
- const params_1 = require("./params");
17
+ const PinoLogger_js_1 = require("./PinoLogger.js");
18
+ const params_js_1 = require("./params.js");
19
19
  let Logger = class Logger {
20
20
  logger;
21
21
  contextName;
@@ -97,7 +97,7 @@ let Logger = class Logger {
97
97
  exports.Logger = Logger;
98
98
  exports.Logger = Logger = __decorate([
99
99
  (0, common_1.Injectable)(),
100
- __param(1, (0, common_1.Inject)(params_1.PARAMS_PROVIDER_TOKEN)),
101
- __metadata("design:paramtypes", [PinoLogger_1.PinoLogger, Object])
100
+ __param(1, (0, common_1.Inject)(params_js_1.PARAMS_PROVIDER_TOKEN)),
101
+ __metadata("design:paramtypes", [PinoLogger_js_1.PinoLogger, Object])
102
102
  ], Logger);
103
103
  //# sourceMappingURL=Logger.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"Logger.js","sourceRoot":"","sources":["../../src/Logger.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;AAAA,2CAAmE;AAEnE,mDAA6C;AAC7C,2CAA4D;AAGrD,IAAM,MAAM,GAAZ,MAAM,MAAM;IAII,MAAM;IAHV,WAAW,CAAS;IAErC,YACqB,MAAkB,EACN,EAAE,aAAa,EAAU;sBADrC,MAAM;QAGzB,IAAI,CAAC,WAAW,GAAG,aAAa,IAAI,SAAS,CAAC;IAChD,CAAC;IAED,OAAO,CAAC,OAAY,EAAE,GAAG,cAAqB;QAC5C,IAAI,CAAC,IAAI,CAAC,OAAO,EAAE,OAAO,EAAE,GAAG,cAAc,CAAC,CAAC;IACjD,CAAC;IAED,KAAK,CAAC,OAAY,EAAE,GAAG,cAAqB;QAC1C,IAAI,CAAC,IAAI,CAAC,OAAO,EAAE,OAAO,EAAE,GAAG,cAAc,CAAC,CAAC;IACjD,CAAC;IAED,GAAG,CAAC,OAAY,EAAE,GAAG,cAAqB;QACxC,IAAI,CAAC,IAAI,CAAC,MAAM,EAAE,OAAO,EAAE,GAAG,cAAc,CAAC,CAAC;IAChD,CAAC;IAED,IAAI,CAAC,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,IAAI,KAAK,CAAC,OAAO,CAAC,CAAC;YAChC,MAAM,CAAC,GAAG,CAAC,KAAK,GAAG,MAAM,CAAC,CAAC,CAAC,CAAC;YAC7B,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC,MAAM,CAAC,CAAC;QAC7B,CAAC;aAAM,CAAC;YACN,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC,MAAM,EAAE,OAAO,EAAE,GAAG,MAAM,CAAC,CAAC;QACjD,CAAC;IACH,CAAC;IAED;;;;;;;;;;;;;;;;;OAiBG;IACK,gCAAgC,CACtC,KAAY,EACZ,OAAY,EACZ,MAAa;QAEb,OAAO,CACL,KAAK,KAAK,OAAO;YACjB,OAAO,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;;iBA5FY,MAAM;IADlB,IAAA,mBAAU,GAAE;IAMR,WAAA,IAAA,eAAM,EAAC,iCAAqB,CAAC,CAAA;qCADH,0BAAU;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 @@
1
+ {"version":3,"file":"LoggerErrorInterceptor.js","sourceRoot":"","sources":["../../src/LoggerErrorInterceptor.ts"],"names":[],"mappings":";;;;;;;;;AAAA,2CAKwB;AACxB,+BAA0D;AAGnD,IAAM,sBAAsB,GAA5B,MAAM,sBAAsB;IACjC,SAAS,CACP,OAAyB,EACzB,IAAiB;QAEjB,OAAO,IAAI,CAAC,MAAM,EAAE,CAAC,IAAI,CACvB,IAAA,iBAAU,EAAC,CAAC,KAAK,EAAE,EAAE;YACnB,OAAO,IAAA,iBAAU,EAAC,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;;iCAzBY,sBAAsB;IADlC,IAAA,mBAAU,GAAE;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"]}
@@ -1,7 +1,7 @@
1
1
  import { IncomingMessage, ServerResponse } from 'node:http';
2
2
  import { type DynamicModule, type MiddlewareConsumer, type NestModule } from '@nestjs/common';
3
3
  import { ApplicationConfig } from '@nestjs/core';
4
- import { type LoggerModuleAsyncParams, type Params } from './params';
4
+ import { type LoggerModuleAsyncParams, type Params } from './params.js';
5
5
  export declare class LoggerModule implements NestModule {
6
6
  private readonly params;
7
7
  private readonly applicationConfig;
@@ -16,14 +16,14 @@ Object.defineProperty(exports, "__esModule", { value: true });
16
16
  exports.LoggerModule = void 0;
17
17
  const common_1 = require("@nestjs/common");
18
18
  const core_1 = require("@nestjs/core");
19
- const InjectPinoLogger_1 = require("./InjectPinoLogger");
20
- const Logger_1 = require("./Logger");
21
- const microservice_1 = require("./microservice");
22
- const NativeLogger_1 = require("./NativeLogger");
23
- const PinoLogger_1 = require("./PinoLogger");
24
- const params_1 = require("./params");
25
- const rootLogger_1 = require("./rootLogger");
26
- const storage_1 = require("./storage");
19
+ const InjectPinoLogger_js_1 = require("./InjectPinoLogger.js");
20
+ const Logger_js_1 = require("./Logger.js");
21
+ const microservice_js_1 = require("./microservice.js");
22
+ const NativeLogger_js_1 = require("./NativeLogger.js");
23
+ const PinoLogger_js_1 = require("./PinoLogger.js");
24
+ const params_js_1 = require("./params.js");
25
+ const rootLogger_js_1 = require("./rootLogger.js");
26
+ const storage_js_1 = require("./storage.js");
27
27
  /**
28
28
  * path-to-regexp v8, used by express@5 and @fastify/middie@9, no longer accepts
29
29
  * the unnamed `*` wildcard: NestJS auto-converts it, but warns while doing so
@@ -41,26 +41,26 @@ let LoggerModule = LoggerModule_1 = class LoggerModule {
41
41
  applicationConfig;
42
42
  static forRoot(params) {
43
43
  const paramsProvider = {
44
- provide: params_1.PARAMS_PROVIDER_TOKEN,
44
+ provide: params_js_1.PARAMS_PROVIDER_TOKEN,
45
45
  useValue: params || {},
46
46
  };
47
- const decorated = (0, InjectPinoLogger_1.createProvidersForDecorated)();
47
+ const decorated = (0, InjectPinoLogger_js_1.createProvidersForDecorated)();
48
48
  const hookProvider = createHookProvider();
49
49
  return {
50
50
  module: LoggerModule_1,
51
51
  providers: [
52
- Logger_1.Logger,
53
- NativeLogger_1.NativeLogger,
52
+ Logger_js_1.Logger,
53
+ NativeLogger_js_1.NativeLogger,
54
54
  ...decorated,
55
- PinoLogger_1.PinoLogger,
55
+ PinoLogger_js_1.PinoLogger,
56
56
  paramsProvider,
57
57
  hookProvider,
58
58
  ],
59
59
  exports: [
60
- Logger_1.Logger,
61
- NativeLogger_1.NativeLogger,
60
+ Logger_js_1.Logger,
61
+ NativeLogger_js_1.NativeLogger,
62
62
  ...decorated,
63
- PinoLogger_1.PinoLogger,
63
+ PinoLogger_js_1.PinoLogger,
64
64
  paramsProvider,
65
65
  hookProvider,
66
66
  ],
@@ -68,17 +68,17 @@ let LoggerModule = LoggerModule_1 = class LoggerModule {
68
68
  }
69
69
  static forRootAsync(params) {
70
70
  const paramsProvider = {
71
- provide: params_1.PARAMS_PROVIDER_TOKEN,
71
+ provide: params_js_1.PARAMS_PROVIDER_TOKEN,
72
72
  useFactory: params.useFactory,
73
73
  inject: params.inject,
74
74
  };
75
- const decorated = (0, InjectPinoLogger_1.createProvidersForDecorated)();
75
+ const decorated = (0, InjectPinoLogger_js_1.createProvidersForDecorated)();
76
76
  const hookProvider = createHookProvider();
77
77
  const providers = [
78
- Logger_1.Logger,
79
- NativeLogger_1.NativeLogger,
78
+ Logger_js_1.Logger,
79
+ NativeLogger_js_1.NativeLogger,
80
80
  ...decorated,
81
- PinoLogger_1.PinoLogger,
81
+ PinoLogger_js_1.PinoLogger,
82
82
  paramsProvider,
83
83
  hookProvider,
84
84
  ...(params.providers || []),
@@ -88,10 +88,10 @@ let LoggerModule = LoggerModule_1 = class LoggerModule {
88
88
  imports: params.imports,
89
89
  providers,
90
90
  exports: [
91
- Logger_1.Logger,
92
- NativeLogger_1.NativeLogger,
91
+ Logger_js_1.Logger,
92
+ NativeLogger_js_1.NativeLogger,
93
93
  ...decorated,
94
- PinoLogger_1.PinoLogger,
94
+ PinoLogger_js_1.PinoLogger,
95
95
  paramsProvider,
96
96
  hookProvider,
97
97
  ],
@@ -104,8 +104,8 @@ let LoggerModule = LoggerModule_1 = class LoggerModule {
104
104
  // them. The hook is registered here instead, early enough that the message
105
105
  // handlers being built later pick it up.
106
106
  if (params.microservice) {
107
- (0, rootLogger_1.ensureRootLogger)(params.pinoHttp);
108
- (0, microservice_1.registerMicroserviceHook)(applicationConfig, params);
107
+ (0, rootLogger_js_1.ensureRootLogger)(params.pinoHttp);
108
+ (0, microservice_js_1.registerMicroserviceHook)(applicationConfig, params);
109
109
  }
110
110
  }
111
111
  configure(consumer) {
@@ -144,8 +144,8 @@ let LoggerModule = LoggerModule_1 = class LoggerModule {
144
144
  exports.LoggerModule = LoggerModule;
145
145
  exports.LoggerModule = LoggerModule = LoggerModule_1 = __decorate([
146
146
  (0, common_1.Global)(),
147
- (0, common_1.Module)({ providers: [Logger_1.Logger, NativeLogger_1.NativeLogger], exports: [Logger_1.Logger, NativeLogger_1.NativeLogger] }),
148
- __param(0, (0, common_1.Inject)(params_1.PARAMS_PROVIDER_TOKEN)),
147
+ (0, common_1.Module)({ providers: [Logger_js_1.Logger, NativeLogger_js_1.NativeLogger], exports: [Logger_js_1.Logger, NativeLogger_js_1.NativeLogger] }),
148
+ __param(0, (0, common_1.Inject)(params_js_1.PARAMS_PROVIDER_TOKEN)),
149
149
  __metadata("design:paramtypes", [Object, core_1.ApplicationConfig])
150
150
  ], LoggerModule);
151
151
  /**
@@ -154,12 +154,12 @@ exports.LoggerModule = LoggerModule = LoggerModule_1 = __decorate([
154
154
  */
155
155
  function createHookProvider() {
156
156
  return {
157
- provide: microservice_1.PINO_PRE_REQUEST_HOOK,
157
+ provide: microservice_js_1.PINO_PRE_REQUEST_HOOK,
158
158
  useFactory: (params) => {
159
- (0, rootLogger_1.ensureRootLogger)(params.pinoHttp);
160
- return (0, microservice_1.getMicroserviceHook)(params);
159
+ (0, rootLogger_js_1.ensureRootLogger)(params.pinoHttp);
160
+ return (0, microservice_js_1.getMicroserviceHook)(params);
161
161
  },
162
- inject: [params_1.PARAMS_PROVIDER_TOKEN],
162
+ inject: [params_js_1.PARAMS_PROVIDER_TOKEN],
163
163
  };
164
164
  }
165
165
  function createLoggerMiddlewares(params, useExisting = false, assignResponse = false) {
@@ -169,10 +169,10 @@ function createLoggerMiddlewares(params, useExisting = false, assignResponse = f
169
169
  // The same instance the rest of the application already logs through, rather
170
170
  // than a second one built here: one `transport`, and a `PinoLogger.root` that
171
171
  // governs every log in the application, request-scoped or not.
172
- const middleware = (0, rootLogger_1.ensureLoggerMiddleware)(params);
172
+ const middleware = (0, rootLogger_js_1.ensureLoggerMiddleware)(params);
173
173
  // @ts-expect-error: root is readonly field, but this is the place where
174
174
  // it's set actually
175
- PinoLogger_1.PinoLogger.root = middleware.logger;
175
+ PinoLogger_js_1.PinoLogger.root = middleware.logger;
176
176
  return [middleware, bindLoggerMiddlewareFactory(useExisting, assignResponse)];
177
177
  }
178
178
  function bindLoggerMiddlewareFactory(useExisting, assignResponse) {
@@ -185,7 +185,7 @@ function bindLoggerMiddlewareFactory(useExisting, assignResponse) {
185
185
  if (assignResponse && !useExisting && res.allLogs) {
186
186
  resLog = res.allLogs[res.allLogs.length - 1];
187
187
  }
188
- storage_1.storage.run(new storage_1.Store(log, resLog), next);
188
+ storage_js_1.storage.run(new storage_js_1.Store(log, resLog), next);
189
189
  };
190
190
  }
191
191
  //# sourceMappingURL=LoggerModule.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"LoggerModule.js","sourceRoot":"","sources":["../../src/LoggerModule.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAEA,2CASwB;AACxB,uCAAiD;AAEjD,+DAAoE;AACpE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AC;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,oBAAO,CAAC,GAAG,CAAC,IAAI,kBAAK,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"]}
@@ -1,6 +1,6 @@
1
1
  import { type LoggerService } from '@nestjs/common';
2
- import { PinoLogger } from './PinoLogger';
3
- import { Params } from './params';
2
+ import { PinoLogger } from './PinoLogger.js';
3
+ import { Params } from './params.js';
4
4
  export declare class NativeLogger implements LoggerService {
5
5
  protected readonly logger: PinoLogger;
6
6
  private readonly contextName;
@@ -15,6 +15,7 @@ export declare class NativeLogger implements LoggerService {
15
15
  fatal(message: any, ...optionalParams: any[]): void;
16
16
  private call;
17
17
  private callError;
18
+ private logMessages;
18
19
  private logSingleMessage;
19
20
  private getContextAndMessagesToPrint;
20
21
  private getContextAndStackAndMessagesToPrint;
@@ -14,8 +14,8 @@ var __param = (this && this.__param) || function (paramIndex, decorator) {
14
14
  Object.defineProperty(exports, "__esModule", { value: true });
15
15
  exports.NativeLogger = void 0;
16
16
  const common_1 = require("@nestjs/common");
17
- const PinoLogger_1 = require("./PinoLogger");
18
- const params_1 = require("./params");
17
+ const PinoLogger_js_1 = require("./PinoLogger.js");
18
+ const params_js_1 = require("./params.js");
19
19
  /**
20
20
  * NestJS v12 collects plain objects passed after the message into a single
21
21
  * `params` field instead of logging each of them as its own entry
@@ -28,6 +28,76 @@ const params_1 = require("./params");
28
28
  * and works on every supported NestJS version when asked for explicitly.
29
29
  */
30
30
  const HAS_STRUCTURED_PARAMS = 'stringifyParams' in common_1.ConsoleLogger.prototype;
31
+ /**
32
+ * NestJS v12.1.1 (nestjs/nest#17893) attaches the first `Error` passed with the
33
+ * message to that entry as a structured `error` field instead of logging it as
34
+ * an entry of its own, and parses the arguments of `fatal` the way it parses
35
+ * those of `error`. Detected the same way as above: `extractJsonError` is the
36
+ * method added for it. Unlike `structuredParams`, ConsoleLogger has no option
37
+ * for this, so neither does NativeLogger.
38
+ */
39
+ const HAS_STRUCTURED_ERRORS = 'extractJsonError' in common_1.ConsoleLogger.prototype;
40
+ /**
41
+ * How many levels of nested errors (`cause`, `AggregateError#errors`) are
42
+ * serialized, as in `ConsoleLogger`.
43
+ */
44
+ const MAX_ERROR_DEPTH = 5;
45
+ /**
46
+ * Mirrors `ConsoleLogger#resolveMessage`: a class resolves to its name, any
47
+ * other function is called (lazy message) and its result resolved again.
48
+ */
49
+ function resolveMessage(message) {
50
+ if (typeof message !== 'function') {
51
+ return message;
52
+ }
53
+ if (Function.prototype.toString.call(message).startsWith('class ')) {
54
+ return message.name;
55
+ }
56
+ return resolveMessage(message());
57
+ }
58
+ /**
59
+ * Mirrors `ConsoleLogger#serializeError`: `name`, `message`, `stack`, own
60
+ * primitive properties (e.g. `code`) and, recursively, `cause` and the
61
+ * `errors` of an `AggregateError`, up to a fixed depth.
62
+ */
63
+ function serializeError(error, depth = 0, ancestors = new Set()) {
64
+ const serialized = {
65
+ name: error.name,
66
+ message: error.message,
67
+ stack: error.stack,
68
+ };
69
+ for (const [key, value] of Object.entries(error)) {
70
+ if (key in serialized || key === 'cause' || key === 'errors') {
71
+ continue;
72
+ }
73
+ if (value === null ||
74
+ (typeof value !== 'object' && typeof value !== 'function')) {
75
+ serialized[key] = value;
76
+ }
77
+ }
78
+ const serializeNested = (value) => {
79
+ if (!(value instanceof Error)) {
80
+ return value;
81
+ }
82
+ if (ancestors.has(value)) {
83
+ return '[Circular]';
84
+ }
85
+ if (depth + 1 > MAX_ERROR_DEPTH) {
86
+ return '[Truncated]';
87
+ }
88
+ return serializeError(value, depth + 1, ancestors);
89
+ };
90
+ ancestors.add(error);
91
+ if (error.cause !== undefined) {
92
+ serialized.cause = serializeNested(error.cause);
93
+ }
94
+ const errors = error.errors;
95
+ if (Array.isArray(errors)) {
96
+ serialized.errors = errors.map(serializeNested);
97
+ }
98
+ ancestors.delete(error);
99
+ return serialized;
100
+ }
31
101
  /** Mirrors `isPlainObject` from `@nestjs/common`, which is not public API. */
32
102
  function isPlainObject(value) {
33
103
  if (typeof value !== 'object' || value === null) {
@@ -69,26 +139,50 @@ let NativeLogger = class NativeLogger {
69
139
  this.call('warn', message, ...optionalParams);
70
140
  }
71
141
  error(message, ...optionalParams) {
72
- this.callError(message, ...optionalParams);
142
+ this.callError('error', message, ...optionalParams);
73
143
  }
74
144
  fatal(message, ...optionalParams) {
75
- this.call('fatal', message, ...optionalParams);
145
+ if (HAS_STRUCTURED_ERRORS) {
146
+ this.callError('fatal', message, ...optionalParams);
147
+ }
148
+ else {
149
+ this.call('fatal', message, ...optionalParams);
150
+ }
76
151
  }
77
152
  call(level, message, ...optionalParams) {
78
153
  const args = [message, ...optionalParams];
79
154
  const { messages, context, params } = this.getContextAndMessagesToPrint(args);
80
- for (const msg of messages) {
81
- this.logSingleMessage(level, msg, context, undefined, params);
82
- }
155
+ this.logMessages(level, messages, context, undefined, params);
83
156
  }
84
- callError(message, ...optionalParams) {
157
+ callError(level, message, ...optionalParams) {
85
158
  const args = [message, ...optionalParams];
86
159
  const { messages, context, stack, params } = this.getContextAndStackAndMessagesToPrint(args);
87
- for (const msg of messages) {
88
- this.logSingleMessage('error', msg, context, stack, params);
160
+ this.logMessages(level, messages, context, stack, params);
161
+ }
162
+ logMessages(level, messages, context, stack, params) {
163
+ // Lazy messages must not be evaluated for a disabled level.
164
+ if (!this.logger.logger.isLevelEnabled(level)) {
165
+ return;
166
+ }
167
+ messages = messages.map(resolveMessage);
168
+ // Mirrors `ConsoleLogger#extractJsonError`: the first error goes to the
169
+ // first entry; when it is the message itself, its message takes its place.
170
+ let error;
171
+ const errorIndex = HAS_STRUCTURED_ERRORS
172
+ ? messages.findIndex((msg) => msg instanceof Error)
173
+ : -1;
174
+ if (errorIndex !== -1) {
175
+ error = messages[errorIndex];
176
+ messages =
177
+ errorIndex === 0
178
+ ? [error.message, ...messages.slice(1)]
179
+ : messages.filter((_, index) => index !== errorIndex);
89
180
  }
181
+ messages.forEach((msg, index) => {
182
+ this.logSingleMessage(level, msg, context, stack, params, index === 0 ? error : undefined);
183
+ });
90
184
  }
91
- logSingleMessage(level, message, context, stack, params) {
185
+ logSingleMessage(level, message, context, stack, params, error) {
92
186
  // Flattened params go in first so that this logger's own fields win on a
93
187
  // key collision. Collisions with pino's fields (the level, the timestamp,
94
188
  // the message key, the base bindings) are not handled: pino does not
@@ -101,6 +195,9 @@ let NativeLogger = class NativeLogger {
101
195
  if (stack) {
102
196
  objArg.stack = stack;
103
197
  }
198
+ if (error) {
199
+ objArg.error = serializeError(error);
200
+ }
104
201
  if (params && !this.flattenParams) {
105
202
  objArg.params = params;
106
203
  }
@@ -193,7 +290,7 @@ let NativeLogger = class NativeLogger {
193
290
  exports.NativeLogger = NativeLogger;
194
291
  exports.NativeLogger = NativeLogger = __decorate([
195
292
  (0, common_1.Injectable)(),
196
- __param(1, (0, common_1.Inject)(params_1.PARAMS_PROVIDER_TOKEN)),
197
- __metadata("design:paramtypes", [PinoLogger_1.PinoLogger, Object])
293
+ __param(1, (0, common_1.Inject)(params_js_1.PARAMS_PROVIDER_TOKEN)),
294
+ __metadata("design:paramtypes", [PinoLogger_js_1.PinoLogger, Object])
198
295
  ], NativeLogger);
199
296
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CAAC;YAC1E,OAAO;gBACL,KAAK,EAAE,WAAW;gBAClB,QAAQ,EAAE,QAAQ,CAAC,KAAK,CAAC,CAAC,EAAE,QAAQ,CAAC,MAAM,GAAG,CAAC,CAAC;gBAChD,OAAO;gBACP,MAAM;aACP,CAAC;QACJ,CAAC;QACD,OAAO,EAAE,QAAQ,EAAE,OAAO,EAAE,MAAM,EAAE,CAAC;IACvC,CAAC;IAEO,aAAa,CAAC,KAAc;QAClC,IAAI,OAAO,KAAK,KAAK,QAAQ,IAAI,OAAO,KAAK,KAAK,WAAW,EAAE,CAAC;YAC9D,OAAO,KAAK,CAAC;QACf,CAAC;QACD,OAAO,OAAO,KAAK,KAAK,QAAQ,IAAI,yBAAyB,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;IAC5E,CAAC;CACF,CAAA;;uBAvOY,YAAY;IADxB,IAAA,mBAAU,GAAE;IAQR,WAAA,IAAA,eAAM,EAAC,iCAAqB,CAAC,CAAA;qCADH,0BAAU;GAN5B,YAAY,CAuOxB","sourcesContent":["import {\n ConsoleLogger,\n Inject,\n Injectable,\n type LoggerService,\n} from '@nestjs/common';\nimport { Level } from 'pino';\nimport { PinoLogger } from './PinoLogger.js';\nimport { PARAMS_PROVIDER_TOKEN, Params } from './params.js';\n\n/**\n * NestJS v12 collects plain objects passed after the message into a single\n * `params` field instead of logging each of them as its own entry\n * (`ConsoleLoggerOptions.structuredParams`, on by default). NativeLogger exists\n * to match whichever `ConsoleLogger` the application actually has, so detect\n * the capability rather than the version: `stringifyParams` is the method v12\n * added for exactly this, and NestJS exposes no version at runtime.\n *\n * This only decides the *default*; the collecting itself is implemented here\n * and works on every supported NestJS version when asked for explicitly.\n */\nconst HAS_STRUCTURED_PARAMS = 'stringifyParams' in ConsoleLogger.prototype;\n\n/**\n * NestJS v12.1.1 (nestjs/nest#17893) attaches the first `Error` passed with the\n * message to that entry as a structured `error` field instead of logging it as\n * an entry of its own, and parses the arguments of `fatal` the way it parses\n * those of `error`. Detected the same way as above: `extractJsonError` is the\n * method added for it. Unlike `structuredParams`, ConsoleLogger has no option\n * for this, so neither does NativeLogger.\n */\nconst HAS_STRUCTURED_ERRORS = 'extractJsonError' in ConsoleLogger.prototype;\n\n/**\n * How many levels of nested errors (`cause`, `AggregateError#errors`) are\n * serialized, as in `ConsoleLogger`.\n */\nconst MAX_ERROR_DEPTH = 5;\n\n/**\n * Mirrors `ConsoleLogger#resolveMessage`: a class resolves to its name, any\n * other function is called (lazy message) and its result resolved again.\n */\nfunction resolveMessage(message: unknown): unknown {\n if (typeof message !== 'function') {\n return message;\n }\n if (Function.prototype.toString.call(message).startsWith('class ')) {\n return message.name;\n }\n return resolveMessage(message());\n}\n\n/**\n * Mirrors `ConsoleLogger#serializeError`: `name`, `message`, `stack`, own\n * primitive properties (e.g. `code`) and, recursively, `cause` and the\n * `errors` of an `AggregateError`, up to a fixed depth.\n */\nfunction serializeError(\n error: Error,\n depth = 0,\n ancestors = new Set<Error>(),\n): Record<string, unknown> {\n const serialized: Record<string, unknown> = {\n name: error.name,\n message: error.message,\n stack: error.stack,\n };\n for (const [key, value] of Object.entries(error)) {\n if (key in serialized || key === 'cause' || key === 'errors') {\n continue;\n }\n if (\n value === null ||\n (typeof value !== 'object' && typeof value !== 'function')\n ) {\n serialized[key] = value;\n }\n }\n\n const serializeNested = (value: unknown) => {\n if (!(value instanceof Error)) {\n return value;\n }\n if (ancestors.has(value)) {\n return '[Circular]';\n }\n if (depth + 1 > MAX_ERROR_DEPTH) {\n return '[Truncated]';\n }\n return serializeError(value, depth + 1, ancestors);\n };\n\n ancestors.add(error);\n if (error.cause !== undefined) {\n serialized.cause = serializeNested(error.cause);\n }\n const errors = (error as Partial<AggregateError>).errors;\n if (Array.isArray(errors)) {\n serialized.errors = errors.map(serializeNested);\n }\n ancestors.delete(error);\n\n return serialized;\n}\n\n/** Mirrors `isPlainObject` from `@nestjs/common`, which is not public API. */\nfunction isPlainObject(value: unknown): boolean {\n if (typeof value !== 'object' || value === null) {\n return false;\n }\n const proto = Object.getPrototypeOf(value) as object | null;\n if (proto === null) {\n return true;\n }\n const ctor =\n Object.hasOwn(proto, 'constructor') &&\n (proto as { constructor: unknown }).constructor;\n return (\n typeof ctor === 'function' &&\n ctor instanceof ctor &&\n Function.prototype.toString.call(ctor) ===\n Function.prototype.toString.call(Object)\n );\n}\n\n@Injectable()\nexport class NativeLogger implements LoggerService {\n private readonly contextName: string;\n private readonly structuredParams: boolean;\n private readonly flattenParams: boolean;\n\n constructor(\n protected readonly logger: PinoLogger,\n @Inject(PARAMS_PROVIDER_TOKEN) { renameContext, nativeLogger }: Params,\n ) {\n this.contextName = renameContext || 'context';\n this.structuredParams =\n nativeLogger?.structuredParams ?? HAS_STRUCTURED_PARAMS;\n this.flattenParams = nativeLogger?.flattenParams ?? false;\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.callError('error', message, ...optionalParams);\n }\n\n fatal(message: any, ...optionalParams: any[]) {\n if (HAS_STRUCTURED_ERRORS) {\n this.callError('fatal', message, ...optionalParams);\n } else {\n this.call('fatal', message, ...optionalParams);\n }\n }\n\n private call(level: Level, message: any, ...optionalParams: any[]) {\n const args = [message, ...optionalParams];\n const { messages, context, params } =\n this.getContextAndMessagesToPrint(args);\n this.logMessages(level, messages, context, undefined, params);\n }\n\n private callError(level: Level, message: any, ...optionalParams: any[]) {\n const args = [message, ...optionalParams];\n const { messages, context, stack, params } =\n this.getContextAndStackAndMessagesToPrint(args);\n this.logMessages(level, messages, context, stack, params);\n }\n\n private logMessages(\n level: Level,\n messages: unknown[],\n context: string | undefined,\n stack?: string,\n params?: Record<string, any>,\n ) {\n // Lazy messages must not be evaluated for a disabled level.\n if (!this.logger.logger.isLevelEnabled(level)) {\n return;\n }\n messages = messages.map(resolveMessage);\n\n // Mirrors `ConsoleLogger#extractJsonError`: the first error goes to the\n // first entry; when it is the message itself, its message takes its place.\n let error: Error | undefined;\n const errorIndex = HAS_STRUCTURED_ERRORS\n ? messages.findIndex((msg) => msg instanceof Error)\n : -1;\n if (errorIndex !== -1) {\n error = messages[errorIndex] as Error;\n messages =\n errorIndex === 0\n ? [error.message, ...messages.slice(1)]\n : messages.filter((_, index) => index !== errorIndex);\n }\n\n messages.forEach((msg, index) => {\n this.logSingleMessage(\n level,\n msg,\n context,\n stack,\n params,\n index === 0 ? error : undefined,\n );\n });\n }\n\n private logSingleMessage(\n level: Level,\n message: unknown,\n context: string | undefined,\n stack?: string,\n params?: Record<string, any>,\n error?: Error,\n ) {\n // Flattened params go in first so that this logger's own fields win on a\n // key collision. Collisions with pino's fields (the level, the timestamp,\n // the message key, the base bindings) are not handled: pino does not\n // deduplicate keys either, and their names depend on the pino options, so\n // any guard here would be guesswork.\n const objArg: Record<string, any> =\n params && this.flattenParams ? { ...params } : {};\n\n if (context) {\n objArg[this.contextName] = context;\n }\n\n if (stack) {\n objArg.stack = stack;\n }\n\n if (error) {\n objArg.error = serializeError(error);\n }\n\n if (params && !this.flattenParams) {\n objArg.params = params;\n }\n\n if (typeof message === 'object' && message !== null) {\n if (message instanceof Error) {\n this.logger[level](objArg, message.stack || message.message);\n } else {\n this.logger[level](objArg, message as unknown as string);\n }\n } else {\n this.logger[level](objArg, String(message));\n }\n }\n\n private getContextAndMessagesToPrint(args: unknown[]): {\n messages: unknown[];\n context: string | undefined;\n params?: Record<string, any>;\n } {\n if (args.length <= 1) {\n return { messages: args, context: undefined };\n }\n const lastElement = args[args.length - 1];\n const isContext = typeof lastElement === 'string';\n const context = isContext ? lastElement : undefined;\n const remainingArgs = isContext ? args.slice(0, args.length - 1) : args;\n\n if (!this.structuredParams) {\n return { messages: remainingArgs, context };\n }\n\n // The first argument is always the message; only plain objects after it\n // become params, everything else stays a message of its own.\n const messages: unknown[] = [remainingArgs[0]];\n const paramObjects: Record<string, any>[] = [];\n for (const arg of remainingArgs.slice(1)) {\n if (isPlainObject(arg)) {\n paramObjects.push(arg as Record<string, any>);\n } else {\n messages.push(arg);\n }\n }\n\n return {\n messages,\n context,\n params: paramObjects.length\n ? Object.assign({}, ...paramObjects)\n : undefined,\n };\n }\n\n private getContextAndStackAndMessagesToPrint(args: unknown[]): {\n messages: unknown[];\n context: string | undefined;\n stack?: string;\n params?: Record<string, any>;\n } {\n if (args.length === 2) {\n if (this.isStackFormat(args[1])) {\n return {\n messages: [args[0]],\n stack: args[1] as string,\n context: undefined,\n };\n }\n if (typeof args[1] === 'string') {\n return {\n messages: [args[0]],\n context: args[1],\n };\n }\n }\n\n const trailingArg = args[args.length - 1];\n if (args.length > 2 && this.isStackFormat(trailingArg)) {\n const { messages, context, params } = this.getContextAndMessagesToPrint(\n args.slice(0, -1),\n );\n return { messages, context, stack: trailingArg as string, params };\n }\n\n const { messages, context, params } =\n this.getContextAndMessagesToPrint(args);\n if (messages.length <= 1) {\n return { messages, context, params };\n }\n\n const lastMessage = messages[messages.length - 1];\n if (typeof lastMessage === 'string' || typeof lastMessage === 'undefined') {\n return {\n stack: lastMessage,\n messages: messages.slice(0, messages.length - 1),\n context,\n params,\n };\n }\n return { messages, context, params };\n }\n\n private isStackFormat(value: unknown): boolean {\n if (typeof value !== 'string' && typeof value !== 'undefined') {\n return false;\n }\n return typeof value === 'string' && /^(.)+\\n\\s+at .+:\\d+:\\d+/.test(value);\n }\n}\n"]}
@@ -1,5 +1,5 @@
1
1
  import pino from 'pino';
2
- import { Params } from './params';
2
+ import { Params } from './params.js';
3
3
  type PinoMethods<CustomLevels extends string = never> = Pick<pino.Logger<CustomLevels>, 'trace' | 'debug' | 'info' | 'warn' | 'error' | 'fatal'>;
4
4
  /**
5
5
  * This is copy of pino.LogFn but with possibilty to make method override.
@@ -16,11 +16,11 @@ Object.defineProperty(exports, "__esModule", { value: true });
16
16
  exports.PinoLogger = void 0;
17
17
  exports.__resetOutOfContextForTests = __resetOutOfContextForTests;
18
18
  const common_1 = require("@nestjs/common");
19
- const params_1 = require("./params");
20
- const rootLogger_1 = require("./rootLogger");
21
- const storage_1 = require("./storage");
19
+ const params_js_1 = require("./params.js");
20
+ const rootLogger_js_1 = require("./rootLogger.js");
21
+ const storage_js_1 = require("./storage.js");
22
22
  function __resetOutOfContextForTests() {
23
- (0, rootLogger_1.resetRootLogger)();
23
+ (0, rootLogger_js_1.resetRootLogger)();
24
24
  // @ts-expect-error reset root for tests only
25
25
  PinoLogger.root = undefined;
26
26
  }
@@ -49,7 +49,7 @@ let PinoLogger = class PinoLogger {
49
49
  typeof pinoHttpOptions.customAttributeKeys !== 'undefined') {
50
50
  this.errorKey = pinoHttpOptions.customAttributeKeys.err ?? 'err';
51
51
  }
52
- const root = (0, rootLogger_1.ensureRootLogger)(pinoHttp);
52
+ const root = (0, rootLogger_js_1.ensureRootLogger)(pinoHttp);
53
53
  // With `useExisting` the logger belongs to the Fastify adapter, so there is
54
54
  // no root of ours to expose and the documented `undefined` stands. The root
55
55
  // logger itself is still built, because logs made outside of a request have
@@ -67,8 +67,8 @@ let PinoLogger = class PinoLogger {
67
67
  // `http.IncomingMessage` with a plain, non-generic `pino.Logger`, so `Store`
68
68
  // cannot carry the custom levels through, and `pino.Logger`'s `onChild`
69
69
  // makes the two instantiations mutually non-comparable.
70
- return (storage_1.storage.getStore()?.logger ||
71
- (0, rootLogger_1.getRootLogger)());
70
+ return (storage_js_1.storage.getStore()?.logger ||
71
+ (0, rootLogger_js_1.getRootLogger)());
72
72
  }
73
73
  trace(...args) {
74
74
  this.call('trace', ...args);
@@ -92,7 +92,7 @@ let PinoLogger = class PinoLogger {
92
92
  this.context = value;
93
93
  }
94
94
  assign(fields) {
95
- const store = storage_1.storage.getStore();
95
+ const store = storage_js_1.storage.getStore();
96
96
  if (!store) {
97
97
  throw new Error(`${PinoLogger_1.name}: unable to assign extra fields out of request scope`);
98
98
  }
@@ -111,13 +111,13 @@ let PinoLogger = class PinoLogger {
111
111
  */
112
112
  runInContext(fn, options = {}) {
113
113
  const { bindings, inherit = false } = options;
114
- const current = storage_1.storage.getStore();
115
- const base = (inherit && current ? current.logger : (0, rootLogger_1.getRootLogger)());
114
+ const current = storage_js_1.storage.getStore();
115
+ const base = (inherit && current ? current.logger : (0, rootLogger_js_1.getRootLogger)());
116
116
  const logger = bindings ? base.child(bindings) : base;
117
117
  // The response logger is deliberately not carried over when inheriting:
118
118
  // fields assigned inside the nested context must not reach the log that
119
119
  // closes the surrounding request.
120
- return storage_1.storage.run(new storage_1.Store(logger), fn);
120
+ return storage_js_1.storage.run(new storage_js_1.Store(logger), fn);
121
121
  }
122
122
  call(method, ...args) {
123
123
  if (this.context) {
@@ -147,7 +147,7 @@ let PinoLogger = class PinoLogger {
147
147
  exports.PinoLogger = PinoLogger;
148
148
  exports.PinoLogger = PinoLogger = PinoLogger_1 = __decorate([
149
149
  (0, common_1.Injectable)({ scope: common_1.Scope.TRANSIENT }),
150
- __param(0, (0, common_1.Inject)(params_1.PARAMS_PROVIDER_TOKEN)),
150
+ __param(0, (0, common_1.Inject)(params_js_1.PARAMS_PROVIDER_TOKEN)),
151
151
  __metadata("design:paramtypes", [Object])
152
152
  ], PinoLogger);
153
153
  function isFirstArgObject(args) {