@nest-boot/logger 7.0.4 → 7.1.0

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.
@@ -1,2 +1,3 @@
1
1
  import { type Options } from "pino-http";
2
+ /** Configuration options for the logger module (delegates to pino-http). */
2
3
  export type LoggerModuleOptions = Options;
package/dist/logger.d.ts CHANGED
@@ -1,18 +1,67 @@
1
1
  import { type LoggerService } from "@nestjs/common";
2
2
  import { type Bindings } from "pino";
3
+ /**
4
+ * Request-scoped structured logger built on top of pino.
5
+ *
6
+ * @remarks
7
+ * Implements the NestJS {@link LoggerService} interface. Each request
8
+ * gets its own logger context via {@link RequestContext}, supporting
9
+ * request-scoped bindings and automatic context propagation.
10
+ */
3
11
  export declare class Logger implements LoggerService {
4
12
  private parentClass;
13
+ /** Current logging context name. @internal */
5
14
  private context?;
15
+ /** Fallback pino logger when no request context is active. @internal */
6
16
  private globalLogger?;
17
+ /** Creates a new Logger instance.
18
+ * @param parentClass - The parent class that owns this logger instance
19
+ */
7
20
  constructor(parentClass: object);
21
+ /** Returns the current logger context name. */
8
22
  getContext(): string | undefined;
23
+ /**
24
+ * Sets the context name for this logger instance.
25
+ * @param context - The context name (typically the class name)
26
+ */
9
27
  setContext(context: string): void;
28
+ /**
29
+ * Logs a message at the `trace` level.
30
+ * @param message - Log message
31
+ * @param optionalParams - Additional structured data or context override
32
+ */
10
33
  verbose(message: string, ...optionalParams: unknown[]): void;
34
+ /**
35
+ * Logs a message at the `debug` level.
36
+ * @param message - Log message
37
+ * @param optionalParams - Additional structured data or context override
38
+ */
11
39
  debug(message: string, ...optionalParams: unknown[]): void;
40
+ /**
41
+ * Logs a message at the `info` level.
42
+ * @param message - Log message
43
+ * @param optionalParams - Additional structured data or context override
44
+ */
12
45
  log(message: string, ...optionalParams: unknown[]): void;
46
+ /**
47
+ * Logs a message at the `warn` level.
48
+ * @param message - Log message
49
+ * @param optionalParams - Additional structured data or context override
50
+ */
13
51
  warn(message: string, ...optionalParams: unknown[]): void;
52
+ /**
53
+ * Logs a message at the `error` level.
54
+ * @param message - Log message
55
+ * @param optionalParams - Additional structured data or context override
56
+ */
14
57
  error(message: string, ...optionalParams: unknown[]): void;
58
+ /**
59
+ * Merges additional bindings into the current request's log context.
60
+ * @param bindings - Key-value pairs to add to log output
61
+ */
15
62
  assign(bindings: Bindings): void;
63
+ /** Gets the current pino logger from request context or falls back to global. @internal */
16
64
  private get pinoLogger();
65
+ /** Dispatches a log message at the given level. @internal */
17
66
  private call;
18
67
  }
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,71 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const testing_1 = require("@nestjs/testing");
4
+ const rxjs_1 = require("rxjs");
5
+ const logger_1 = require("./logger");
6
+ const logger_interceptor_1 = require("./logger.interceptor");
7
+ describe("LoggingInterceptor", () => {
8
+ it("should assign route bindings for HTTP requests", async () => {
9
+ function handler() {
10
+ return undefined;
11
+ }
12
+ class TestController {
13
+ }
14
+ const assign = jest.fn();
15
+ const handle = jest.fn(() => (0, rxjs_1.of)("ok"));
16
+ const interceptor = await createInterceptor(assign);
17
+ const next = {
18
+ handle,
19
+ };
20
+ const context = {
21
+ getClass: jest.fn(() => TestController),
22
+ getHandler: jest.fn(() => handler),
23
+ getType: jest.fn(() => "http"),
24
+ switchToHttp: jest.fn(() => ({
25
+ getRequest: () => ({
26
+ route: {
27
+ path: "/test",
28
+ },
29
+ }),
30
+ })),
31
+ };
32
+ interceptor.intercept(context, next).subscribe();
33
+ expect(assign).toHaveBeenCalledWith({
34
+ route: {
35
+ controller: "TestController",
36
+ handler: "handler",
37
+ path: "/test",
38
+ },
39
+ });
40
+ expect(handle).toHaveBeenCalledTimes(1);
41
+ });
42
+ it("should skip route bindings for non-HTTP requests", async () => {
43
+ const assign = jest.fn();
44
+ const handle = jest.fn(() => (0, rxjs_1.of)("ok"));
45
+ const interceptor = await createInterceptor(assign);
46
+ const next = {
47
+ handle,
48
+ };
49
+ const context = {
50
+ getType: jest.fn(() => "rpc"),
51
+ };
52
+ interceptor.intercept(context, next);
53
+ expect(assign).not.toHaveBeenCalled();
54
+ expect(handle).toHaveBeenCalledTimes(1);
55
+ });
56
+ });
57
+ async function createInterceptor(assign) {
58
+ const moduleRef = await testing_1.Test.createTestingModule({
59
+ providers: [
60
+ logger_interceptor_1.LoggingInterceptor,
61
+ {
62
+ provide: logger_1.Logger,
63
+ useValue: {
64
+ assign,
65
+ },
66
+ },
67
+ ],
68
+ }).compile();
69
+ return moduleRef.get(logger_interceptor_1.LoggingInterceptor);
70
+ }
71
+ //# sourceMappingURL=logger.interceptor.spec.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"logger.interceptor.spec.js","sourceRoot":"","sources":["../src/logger.interceptor.spec.ts"],"names":[],"mappings":";;AAAA,6CAAuC;AACvC,+BAA0B;AAE1B,qCAAkC;AAClC,6DAA0D;AAE1D,QAAQ,CAAC,oBAAoB,EAAE,GAAG,EAAE;IAClC,EAAE,CAAC,gDAAgD,EAAE,KAAK,IAAI,EAAE;QAC9D,SAAS,OAAO;YACd,OAAO,SAAS,CAAC;QACnB,CAAC;QACD,MAAM,cAAc;SAAG;QACvB,MAAM,MAAM,GAAG,IAAI,CAAC,EAAE,EAAE,CAAC;QACzB,MAAM,MAAM,GAAG,IAAI,CAAC,EAAE,CAAC,GAAG,EAAE,CAAC,IAAA,SAAE,EAAC,IAAI,CAAC,CAAC,CAAC;QACvC,MAAM,WAAW,GAAG,MAAM,iBAAiB,CAAC,MAAM,CAAC,CAAC;QACpD,MAAM,IAAI,GAAG;YACX,MAAM;SACP,CAAC;QACF,MAAM,OAAO,GAAG;YACd,QAAQ,EAAE,IAAI,CAAC,EAAE,CAAC,GAAG,EAAE,CAAC,cAAc,CAAC;YACvC,UAAU,EAAE,IAAI,CAAC,EAAE,CAAC,GAAG,EAAE,CAAC,OAAO,CAAC;YAClC,OAAO,EAAE,IAAI,CAAC,EAAE,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;AACL,CAAC,CAAC,CAAC;AAEH,KAAK,UAAU,iBAAiB,CAAC,MAAiB;IAChD,MAAM,SAAS,GAAG,MAAM,cAAI,CAAC,mBAAmB,CAAC;QAC/C,SAAS,EAAE;YACT,uCAAkB;YAClB;gBACE,OAAO,EAAE,eAAM;gBACf,QAAQ,EAAE;oBACR,MAAM;iBACP;aACF;SACF;KACF,CAAC,CAAC,OAAO,EAAE,CAAC;IAEb,OAAO,SAAS,CAAC,GAAG,CAAC,uCAAkB,CAAC,CAAC;AAC3C,CAAC"}
package/dist/logger.js CHANGED
@@ -21,38 +21,84 @@ const common_1 = require("@nestjs/common");
21
21
  const core_1 = require("@nestjs/core");
22
22
  const pino_1 = __importDefault(require("pino"));
23
23
  const logger_module_definition_1 = require("./logger.module-definition");
24
+ /**
25
+ * Request-scoped structured logger built on top of pino.
26
+ *
27
+ * @remarks
28
+ * Implements the NestJS {@link LoggerService} interface. Each request
29
+ * gets its own logger context via {@link RequestContext}, supporting
30
+ * request-scoped bindings and automatic context propagation.
31
+ */
24
32
  let Logger = class Logger {
33
+ /** Creates a new Logger instance.
34
+ * @param parentClass - The parent class that owns this logger instance
35
+ */
25
36
  constructor(parentClass) {
26
37
  this.parentClass = parentClass;
27
38
  this.setContext(this.parentClass?.constructor?.name);
28
39
  }
40
+ /** Returns the current logger context name. */
29
41
  getContext() {
30
42
  return this.context;
31
43
  }
44
+ /**
45
+ * Sets the context name for this logger instance.
46
+ * @param context - The context name (typically the class name)
47
+ */
32
48
  setContext(context) {
33
49
  this.context = context;
34
50
  }
51
+ /**
52
+ * Logs a message at the `trace` level.
53
+ * @param message - Log message
54
+ * @param optionalParams - Additional structured data or context override
55
+ */
35
56
  verbose(message, ...optionalParams) {
36
57
  this.call("trace", message, ...optionalParams);
37
58
  }
59
+ /**
60
+ * Logs a message at the `debug` level.
61
+ * @param message - Log message
62
+ * @param optionalParams - Additional structured data or context override
63
+ */
38
64
  debug(message, ...optionalParams) {
39
65
  this.call("debug", message, ...optionalParams);
40
66
  }
67
+ /**
68
+ * Logs a message at the `info` level.
69
+ * @param message - Log message
70
+ * @param optionalParams - Additional structured data or context override
71
+ */
41
72
  log(message, ...optionalParams) {
42
73
  this.call("info", message, ...optionalParams);
43
74
  }
75
+ /**
76
+ * Logs a message at the `warn` level.
77
+ * @param message - Log message
78
+ * @param optionalParams - Additional structured data or context override
79
+ */
44
80
  warn(message, ...optionalParams) {
45
81
  this.call("warn", message, ...optionalParams);
46
82
  }
83
+ /**
84
+ * Logs a message at the `error` level.
85
+ * @param message - Log message
86
+ * @param optionalParams - Additional structured data or context override
87
+ */
47
88
  error(message, ...optionalParams) {
48
89
  this.call("error", message, ...optionalParams);
49
90
  }
91
+ /**
92
+ * Merges additional bindings into the current request's log context.
93
+ * @param bindings - Key-value pairs to add to log output
94
+ */
50
95
  assign(bindings) {
51
96
  request_context_1.RequestContext.set(logger_module_definition_1.BINDINGS, {
52
97
  ...(request_context_1.RequestContext.get(logger_module_definition_1.BINDINGS) ?? {}),
53
98
  ...bindings,
54
99
  });
55
100
  }
101
+ /** Gets the current pino logger from request context or falls back to global. @internal */
56
102
  get pinoLogger() {
57
103
  let pinoLogger;
58
104
  try {
@@ -66,6 +112,7 @@ let Logger = class Logger {
66
112
  }
67
113
  return pinoLogger;
68
114
  }
115
+ /** Dispatches a log message at the given level. @internal */
69
116
  call(level, message, ...optionalParams) {
70
117
  let bindings = {};
71
118
  try {
@@ -1 +1 @@
1
- {"version":3,"file":"logger.js","sourceRoot":"","sources":["../src/logger.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;AAAA,gEAA4D;AAC5D,2CAA+E;AAC/E,uCAAwC;AACxC,gDAIc;AAEd,yEAAmE;AAG5D,IAAM,MAAM,GAAZ,MAAM,MAAM;IAKjB,YAAsC,WAAmB;QAAnB,gBAAW,GAAX,WAAW,CAAQ;QACvD,IAAI,CAAC,UAAU,CAAC,IAAI,CAAC,WAAW,EAAE,WAAW,EAAE,IAAI,CAAC,CAAC;IACv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AE,GAAG,cAAc,CAAC,CAAC,CAAC,EAAE,CAAC;YACnD,CAAC;QACH,CAAC;QAED,QAAQ,GAAG,EAAE,GAAG,QAAQ,EAAE,OAAO,EAAE,CAAC;QAEpC,IAAI,CAAC,UAAU,CAAC,KAAK,CAAC,CAAC,QAAQ,EAAE,OAAO,CAAC,CAAC;IAC5C,CAAC;CACF,CAAA;AAnIY,wBAAM;iBAAN,MAAM;IADlB,IAAA,mBAAU,EAAC,EAAE,KAAK,EAAE,cAAK,CAAC,SAAS,EAAE,CAAC;IAWxB,WAAA,IAAA,eAAM,EAAC,eAAQ,CAAC,CAAA;;GAVlB,MAAM,CAmIlB"}
@@ -1,4 +1,4 @@
1
1
  import { type LoggerModuleOptions } from "./logger-module-options.interface";
2
2
  export declare const PINO_LOGGER: unique symbol;
3
3
  export declare const BINDINGS: unique symbol;
4
- export declare const ConfigurableModuleClass: import("@nestjs/common").ConfigurableModuleCls<LoggerModuleOptions, "register", "create", {}>, MODULE_OPTIONS_TOKEN: string | symbol;
4
+ export declare const ConfigurableModuleClass: import("@nestjs/common").ConfigurableModuleCls<LoggerModuleOptions, "register", "create", {}>, MODULE_OPTIONS_TOKEN: string | symbol, OPTIONS_TYPE: LoggerModuleOptions & Partial<{}>, ASYNC_OPTIONS_TYPE: import("@nestjs/common").ConfigurableModuleAsyncOptions<LoggerModuleOptions, "create"> & Partial<{}>;
@@ -1,9 +1,9 @@
1
1
  "use strict";
2
2
  var _a;
3
3
  Object.defineProperty(exports, "__esModule", { value: true });
4
- exports.MODULE_OPTIONS_TOKEN = exports.ConfigurableModuleClass = exports.BINDINGS = exports.PINO_LOGGER = void 0;
4
+ exports.ASYNC_OPTIONS_TYPE = exports.OPTIONS_TYPE = exports.MODULE_OPTIONS_TOKEN = exports.ConfigurableModuleClass = exports.BINDINGS = exports.PINO_LOGGER = void 0;
5
5
  const common_1 = require("@nestjs/common");
6
6
  exports.PINO_LOGGER = Symbol("PINO_LOGGER");
7
7
  exports.BINDINGS = Symbol("BINDINGS");
8
- _a = new common_1.ConfigurableModuleBuilder().build(), exports.ConfigurableModuleClass = _a.ConfigurableModuleClass, exports.MODULE_OPTIONS_TOKEN = _a.MODULE_OPTIONS_TOKEN;
8
+ _a = new common_1.ConfigurableModuleBuilder().build(), exports.ConfigurableModuleClass = _a.ConfigurableModuleClass, exports.MODULE_OPTIONS_TOKEN = _a.MODULE_OPTIONS_TOKEN, exports.OPTIONS_TYPE = _a.OPTIONS_TYPE, exports.ASYNC_OPTIONS_TYPE = _a.ASYNC_OPTIONS_TYPE;
9
9
  //# sourceMappingURL=logger.module-definition.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"logger.module-definition.js","sourceRoot":"","sources":["../src/logger.module-definition.ts"],"names":[],"mappings":";;;;AAAA,2CAA2D;AAI9C,QAAA,WAAW,GAAG,MAAM,CAAC,aAAa,CAAC,CAAC;AAEpC,QAAA,QAAQ,GAAG,MAAM,CAAC,UAAU,CAAC,CAAC;AAE9B,KACX,IAAI,kCAAyB,EAAuB,CAAC,KAAK,EAAE,EAD/C,+BAAuB,+BAAE,4BAAoB,2BACG"}
1
+ {"version":3,"file":"logger.module-definition.js","sourceRoot":"","sources":["../src/logger.module-definition.ts"],"names":[],"mappings":";;;;AAAA,2CAA2D;AAI9C,QAAA,WAAW,GAAG,MAAM,CAAC,aAAa,CAAC,CAAC;AAEpC,QAAA,QAAQ,GAAG,MAAM,CAAC,UAAU,CAAC,CAAC;AAE9B,KAKT,IAAI,kCAAyB,EAAuB,CAAC,KAAK,EAAE,EAJ9D,+BAAuB,+BACvB,4BAAoB,4BACpB,oBAAY,oBACZ,0BAAkB,yBAC6C"}
@@ -1,8 +1,31 @@
1
- import { type OnModuleInit } from "@nestjs/common";
2
- import { ConfigurableModuleClass } from "./logger.module-definition";
1
+ import { type DynamicModule, type OnModuleInit } from "@nestjs/common";
2
+ import { ASYNC_OPTIONS_TYPE, ConfigurableModuleClass, OPTIONS_TYPE } from "./logger.module-definition";
3
3
  import { LoggerModuleOptions } from "./logger-module-options.interface";
4
+ /**
5
+ * Structured logging module powered by Pino.
6
+ *
7
+ * @remarks
8
+ * Provides request-scoped structured logging with automatic request correlation,
9
+ * HTTP logging via pino-http, and a global logging interceptor.
10
+ */
4
11
  export declare class LoggerModule extends ConfigurableModuleClass implements OnModuleInit {
5
12
  private readonly options;
13
+ /**
14
+ * Registers the LoggerModule with the given options.
15
+ * @param options - Pino logger configuration options
16
+ * @returns Dynamic module configuration
17
+ */
18
+ static register(options: typeof OPTIONS_TYPE): DynamicModule;
19
+ /**
20
+ * Registers the LoggerModule asynchronously with factory functions.
21
+ * @param options - Async configuration options
22
+ * @returns Dynamic module configuration
23
+ */
24
+ static registerAsync(options: typeof ASYNC_OPTIONS_TYPE): DynamicModule;
25
+ /** Creates a new LoggerModule instance.
26
+ * @param options - Pino logger configuration options
27
+ */
6
28
  constructor(options?: LoggerModuleOptions);
29
+ /** Sets up the pino-http logger and registers it in the request context middleware. */
7
30
  onModuleInit(): void;
8
31
  }
@@ -25,7 +25,33 @@ const pino_http_1 = __importDefault(require("pino-http"));
25
25
  const logger_1 = require("./logger");
26
26
  const logger_interceptor_1 = require("./logger.interceptor");
27
27
  const logger_module_definition_1 = require("./logger.module-definition");
28
+ /**
29
+ * Structured logging module powered by Pino.
30
+ *
31
+ * @remarks
32
+ * Provides request-scoped structured logging with automatic request correlation,
33
+ * HTTP logging via pino-http, and a global logging interceptor.
34
+ */
28
35
  let LoggerModule = class LoggerModule extends logger_module_definition_1.ConfigurableModuleClass {
36
+ /**
37
+ * Registers the LoggerModule with the given options.
38
+ * @param options - Pino logger configuration options
39
+ * @returns Dynamic module configuration
40
+ */
41
+ static register(options) {
42
+ return super.register(options);
43
+ }
44
+ /**
45
+ * Registers the LoggerModule asynchronously with factory functions.
46
+ * @param options - Async configuration options
47
+ * @returns Dynamic module configuration
48
+ */
49
+ static registerAsync(options) {
50
+ return super.registerAsync(options);
51
+ }
52
+ /** Creates a new LoggerModule instance.
53
+ * @param options - Pino logger configuration options
54
+ */
29
55
  constructor(options = {}) {
30
56
  super();
31
57
  this.options = options;
@@ -44,6 +70,7 @@ let LoggerModule = class LoggerModule extends logger_module_definition_1.Configu
44
70
  ...this.options,
45
71
  };
46
72
  }
73
+ /** Sets up the pino-http logger and registers it in the request context middleware. */
47
74
  onModuleInit() {
48
75
  const logger = (0, pino_1.default)();
49
76
  const loggerMiddleware = (0, pino_http_1.default)(this.options);
@@ -1 +1 @@
1
- {"version":3,"file":"logger.module.js","sourceRoot":"","sources":["../src/logger.module.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;AAAA,gEAKoC;AACpC,2CAMwB;AACxB,uCAA+C;AAC/C,mCAAoC;AAEpC,gDAAwB;AACxB,0DAAiC;AAEjC,qCAAkC;AAClC,6DAA0D;AAC1D,yEAKoC;AAe7B,IAAM,YAAY,GAAlB,MAAM,YACX,SAAQ,kDAAuB;IAG/B,YAGmB,UAA+B,EAAE;QAElD,KAAK,EAAE,CAAC;QAFS,YAAO,GAAP,OAAO,CAA0B;QAIlD,IAAI,CAAC,OAAO,GAAG;YACb,WAAW,EAAE;gBACX,MAAM,EAAE,CAAC,GAAG,EAAE,EAAE,CACd,OAAO,CAAC,GAAG,CAAC,QAAQ,KAAK,YAAY;oBACrC,GAAG,CAAC,OAAO,CAAC,WAAW,CAAC,KAAK,OAAO;gBACtC,GAAG,CAAC,OAAO,IAAI,CAAC,OAAO,CAAC,WAAW,KAAK,SAAS;oBAC/C,CAAC,CAAC,IAAI,CAAC,OAAO,CAAC,WAAW;oBAC1B,CAAC,CAAC,EAAE,CAAC;aACR;YACD,MAAM,EAAE,CAAC,2BAA2B,EAAE,oBAAoB,CAAC;YAC3D,QAAQ,EACN,IAAI,CAAC,OAAO,CAAC,QAAQ,IAAI,CAAC,GAAG,EAAE,CAAC,gCAAc,CAAC,EAAE,IAAI,IAAA,mBAAU,GAAE,CAAC;YACpE,qBAAqB,EAAE,GAAG,EAAE,CAAC,kBAAkB;YAC/C,WAA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EAAE,CAAC,CACvD,CAAC;YACJ,CAAC;iBAAM,CAAC;gBACN,GAAG,CAAC,GAAG,CACL,sCAAW,EACX,MAAM,CAAC,KAAK,CAAC;oBACX,GAAG,EAAE,EAAE,EAAE,EAAE,GAAG,CAAC,EAAE,EAAE,IAAI,EAAE,GAAG,CAAC,IAAI,EAAE;iBACpC,CAAC,CACH,CAAC;YACJ,CAAC;YAED,OAAO,MAAM,IAAI,EAAE,CAAC;QACtB,CAAC,CAAC,CAAC;IACL,CAAC;CACF,CAAA;AAhFY,oCAAY;uBAAZ,YAAY;IAZxB,IAAA,eAAM,GAAE;IACR,IAAA,eAAM,EAAC;QACN,OAAO,EAAE,CAAC,sCAAoB,CAAC;QAC/B,SAAS,EAAE;YACT,eAAM;YACN;gBACE,OAAO,EAAE,sBAAe;gBACxB,QAAQ,EAAE,uCAAkB;aAC7B;SACF;QACD,OAAO,EAAE,CAAC,eAAM,CAAC;KAClB,CAAC;IA6BG,WAAA,IAAA,iBAAQ,GAAE,CAAA;IACV,WAAA,IAAA,eAAM,EAAC,+CAAoB,CAAC,CAAA;;GA7BpB,YAAY,CAgFxB"}
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,199 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const request_context_1 = require("@nest-boot/request-context");
4
+ const testing_1 = require("@nestjs/testing");
5
+ const mockChildLogger = {
6
+ ctx: "child",
7
+ };
8
+ const mockPinoLogger = {
9
+ child: jest.fn(() => mockChildLogger),
10
+ };
11
+ const mockPino = jest.fn(() => mockPinoLogger);
12
+ const mockLoggerMiddleware = jest.fn((req) => {
13
+ req.log = {
14
+ child: jest.fn(() => mockChildLogger),
15
+ };
16
+ });
17
+ const mockPinoHttp = jest.fn(() => mockLoggerMiddleware);
18
+ jest.mock("pino", () => ({
19
+ __esModule: true,
20
+ default: mockPino,
21
+ }));
22
+ jest.mock("pino-http", () => ({
23
+ __esModule: true,
24
+ default: mockPinoHttp,
25
+ }));
26
+ const logger_module_1 = require("./logger.module");
27
+ const logger_module_definition_1 = require("./logger.module-definition");
28
+ describe("LoggerModule", () => {
29
+ afterEach(() => {
30
+ jest.restoreAllMocks();
31
+ jest.clearAllMocks();
32
+ });
33
+ it("should register synchronous and asynchronous options", () => {
34
+ const options = {
35
+ autoLogging: false,
36
+ };
37
+ const dynamicModule = logger_module_1.LoggerModule.register(options);
38
+ const useFactory = () => options;
39
+ const asyncModule = logger_module_1.LoggerModule.registerAsync({
40
+ useFactory,
41
+ });
42
+ expect(dynamicModule.module).toBe(logger_module_1.LoggerModule);
43
+ expect(dynamicModule.providers).toEqual(expect.arrayContaining([
44
+ {
45
+ provide: logger_module_definition_1.MODULE_OPTIONS_TOKEN,
46
+ useValue: options,
47
+ },
48
+ ]));
49
+ expect(asyncModule.providers).toEqual(expect.arrayContaining([
50
+ {
51
+ inject: [],
52
+ provide: logger_module_definition_1.MODULE_OPTIONS_TOKEN,
53
+ useFactory,
54
+ },
55
+ ]));
56
+ });
57
+ it("should apply defaults while preserving supplied options", async () => {
58
+ const module = await createLoggerModule({
59
+ autoLogging: {
60
+ ignore: () => false,
61
+ },
62
+ customProps: () => ({
63
+ custom: true,
64
+ }),
65
+ genReqId: () => "custom-id",
66
+ });
67
+ const options = module.options;
68
+ expect(options.redact).toEqual([
69
+ "req.headers.authorization",
70
+ "req.headers.cookie",
71
+ ]);
72
+ expect(options.genReqId()).toBe("custom-id");
73
+ expect(options.customReceivedMessage()).toBe("request received");
74
+ expect(options.customProps()).toEqual({
75
+ custom: true,
76
+ });
77
+ });
78
+ it("should configure default request id, props, and auto logging behavior", async () => {
79
+ const module = await createLoggerModule();
80
+ const options = module.options;
81
+ jest.spyOn(request_context_1.RequestContext, "isActive").mockReturnValue(true);
82
+ jest.spyOn(request_context_1.RequestContext, "get").mockReturnValue({
83
+ tenantId: "tenant-1",
84
+ });
85
+ jest.spyOn(request_context_1.RequestContext, "id", "get").mockReturnValue("ctx-id");
86
+ process.env.NODE_ENV = "test";
87
+ expect(options.autoLogging.ignore({
88
+ headers: {
89
+ "x-logging": "false",
90
+ },
91
+ })).toBe(true);
92
+ expect(options.autoLogging.ignore({
93
+ headers: {},
94
+ })).toBe(false);
95
+ expect(options.genReqId()).toBe("ctx-id");
96
+ expect(options.customProps()).toEqual({
97
+ tenantId: "tenant-1",
98
+ });
99
+ });
100
+ it("should cover fallback defaults for boolean auto logging and inactive context", async () => {
101
+ const module = await createLoggerModule({
102
+ autoLogging: false,
103
+ });
104
+ const options = module.options;
105
+ jest.spyOn(request_context_1.RequestContext, "isActive").mockReturnValueOnce(false);
106
+ jest
107
+ .spyOn(request_context_1.RequestContext, "id", "get")
108
+ .mockReturnValue(undefined);
109
+ expect(options.autoLogging).toBe(false);
110
+ expect(options.customProps()).toEqual({});
111
+ expect(options.genReqId()).toEqual(expect.any(String));
112
+ });
113
+ it("should return empty custom props when bindings are not set", async () => {
114
+ const module = await createLoggerModule();
115
+ const options = module.options;
116
+ jest.spyOn(request_context_1.RequestContext, "isActive").mockReturnValue(true);
117
+ jest.spyOn(request_context_1.RequestContext, "get").mockReturnValue(undefined);
118
+ expect(options.customProps()).toEqual({});
119
+ });
120
+ it("should emit decorator metadata when options exist at runtime", () => {
121
+ jest.isolateModules(() => {
122
+ jest.doMock("./logger-module-options.interface", () => {
123
+ var _a;
124
+ return ({
125
+ LoggerModuleOptions: (_a = class LoggerModuleOptions {
126
+ },
127
+ _a.marker = true,
128
+ _a),
129
+ });
130
+ });
131
+ expect(jest.requireActual("./logger.module")
132
+ .LoggerModule).toBeDefined();
133
+ jest.dontMock("./logger-module-options.interface");
134
+ });
135
+ });
136
+ it("should register pino logger middleware for requests", async () => {
137
+ const module = await createLoggerModule();
138
+ const registerMiddleware = jest
139
+ .spyOn(request_context_1.RequestContext, "registerMiddleware")
140
+ .mockImplementation();
141
+ module.onModuleInit();
142
+ const middleware = registerMiddleware.mock.calls[0][1];
143
+ const req = {};
144
+ const res = {};
145
+ const ctx = {
146
+ get: jest.fn((token) => {
147
+ if (token === request_context_1.REQUEST)
148
+ return req;
149
+ if (token === request_context_1.RESPONSE)
150
+ return res;
151
+ return undefined;
152
+ }),
153
+ id: "ctx-id",
154
+ set: jest.fn(),
155
+ type: "http",
156
+ };
157
+ const next = jest.fn().mockResolvedValue("next-result");
158
+ await expect(middleware(ctx, next)).resolves.toBe("next-result");
159
+ expect(mockLoggerMiddleware).toHaveBeenCalledWith(req, res);
160
+ expect(ctx.set).toHaveBeenCalledWith(logger_module_definition_1.PINO_LOGGER, mockChildLogger);
161
+ });
162
+ it("should register fallback pino logger middleware without request objects", async () => {
163
+ const module = await createLoggerModule();
164
+ const registerMiddleware = jest
165
+ .spyOn(request_context_1.RequestContext, "registerMiddleware")
166
+ .mockImplementation();
167
+ module.onModuleInit();
168
+ const middleware = registerMiddleware.mock.calls[0][1];
169
+ const ctx = {
170
+ get: jest.fn(() => undefined),
171
+ id: "ctx-id",
172
+ set: jest.fn(),
173
+ type: "job",
174
+ };
175
+ const next = jest.fn().mockResolvedValue("next-result");
176
+ await expect(middleware(ctx, next)).resolves.toBe("next-result");
177
+ expect(mockPinoLogger.child).toHaveBeenCalledWith({
178
+ ctx: {
179
+ id: "ctx-id",
180
+ type: "job",
181
+ },
182
+ });
183
+ expect(ctx.set).toHaveBeenCalledWith(logger_module_definition_1.PINO_LOGGER, mockChildLogger);
184
+ });
185
+ });
186
+ async function createLoggerModule(options) {
187
+ const providers = [logger_module_1.LoggerModule];
188
+ if (typeof options !== "undefined") {
189
+ providers?.push({
190
+ provide: logger_module_definition_1.MODULE_OPTIONS_TOKEN,
191
+ useValue: options,
192
+ });
193
+ }
194
+ const moduleRef = await testing_1.Test.createTestingModule({
195
+ providers,
196
+ }).compile();
197
+ return moduleRef.get(logger_module_1.LoggerModule);
198
+ }
199
+ //# sourceMappingURL=logger.module.spec.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"logger.module.spec.js","sourceRoot":"","sources":["../src/logger.module.spec.ts"],"names":[],"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