@adatechnology/logger 0.0.8 → 0.0.9

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.
package/dist/index.d.ts CHANGED
@@ -1,5 +1,7 @@
1
+ import * as _nestjs_common from '@nestjs/common';
1
2
  import { DynamicModule, NestMiddleware, NestInterceptor, ExecutionContext, CallHandler } from '@nestjs/common';
2
3
  import { LoggerOptions } from 'winston';
4
+ import { Reflector } from '@nestjs/core';
3
5
  import { Observable } from 'rxjs';
4
6
 
5
7
  interface ObfuscatorKey {
@@ -69,10 +71,16 @@ interface LoggerConfig extends WinstonModuleConfig {
69
71
  * Versão da biblioteca/módulo que está gerando o log
70
72
  */
71
73
  libVersion?: string;
74
+ /**
75
+ * Rotas excluídas do HttpLoggingInterceptor (ex.: ['/health'])
76
+ * Suporta prefixo exato ou parcial via startsWith
77
+ */
78
+ interceptorExcludedPaths?: string[];
72
79
  }
73
80
  declare const DEFAULT_LOGGER_CONFIG: LoggerConfig;
74
81
 
75
82
  declare const LOGGER_PROVIDER = "LOGGER_PROVIDER";
83
+ declare const LOGGER_CONFIG = "LOGGER_CONFIG";
76
84
  declare const HTTP_LOGGING_INTERCEPTOR = "HTTP_LOGGING_INTERCEPTOR";
77
85
 
78
86
  declare class LoggerModule {
@@ -99,7 +107,10 @@ declare class RequestContextMiddleware implements NestMiddleware {
99
107
 
100
108
  declare class HttpLoggingInterceptor implements NestInterceptor {
101
109
  private readonly logger;
102
- constructor(logger: LoggerProviderInterface);
110
+ private readonly reflector;
111
+ private readonly excludedPaths;
112
+ constructor(logger: LoggerProviderInterface, reflector: Reflector, config?: LoggerConfig);
113
+ private isExcluded;
103
114
  intercept(context: ExecutionContext, next: CallHandler): Observable<unknown>;
104
115
  }
105
116
 
@@ -109,9 +120,11 @@ declare const HTTP_LOGGING_INTERCEPTOR_CONTEXT: {
109
120
  readonly ON_ERROR: "HttpLoggingInterceptor.onError";
110
121
  };
111
122
 
123
+ declare const ExcludeHttpLogging: () => _nestjs_common.CustomDecorator<string>;
124
+
112
125
  type RequestContext = Record<string, unknown> | undefined;
113
126
 
114
127
  declare function getContext(): RequestContext;
115
128
  declare function runWithContext<T>(ctx: Record<string, unknown>, fn: () => T): T;
116
129
 
117
- export { DEFAULT_LOGGER_CONFIG, HTTP_LOGGING_INTERCEPTOR, HTTP_LOGGING_INTERCEPTOR_CONTEXT, HttpLoggingInterceptor, LOGGER_PROVIDER, type LogPayload, type LoggerConfig, LoggerLevel, LoggerModule, type LoggerProviderInterface, RequestContextMiddleware, getContext, runWithContext };
130
+ export { DEFAULT_LOGGER_CONFIG, ExcludeHttpLogging, HTTP_LOGGING_INTERCEPTOR, HTTP_LOGGING_INTERCEPTOR_CONTEXT, HttpLoggingInterceptor, LOGGER_CONFIG, LOGGER_PROVIDER, type LogPayload, type LoggerConfig, LoggerLevel, LoggerModule, type LoggerProviderInterface, RequestContextMiddleware, getContext, runWithContext };
package/dist/index.js CHANGED
@@ -8999,9 +8999,11 @@ var require_operators = __commonJS({
8999
8999
  var index_exports = {};
9000
9000
  __export(index_exports, {
9001
9001
  DEFAULT_LOGGER_CONFIG: () => DEFAULT_LOGGER_CONFIG,
9002
+ ExcludeHttpLogging: () => ExcludeHttpLogging,
9002
9003
  HTTP_LOGGING_INTERCEPTOR: () => HTTP_LOGGING_INTERCEPTOR,
9003
9004
  HTTP_LOGGING_INTERCEPTOR_CONTEXT: () => HTTP_LOGGING_INTERCEPTOR_CONTEXT,
9004
9005
  HttpLoggingInterceptor: () => HttpLoggingInterceptor,
9006
+ LOGGER_CONFIG: () => LOGGER_CONFIG,
9005
9007
  LOGGER_PROVIDER: () => LOGGER_PROVIDER,
9006
9008
  LoggerModule: () => LoggerModule,
9007
9009
  RequestContextMiddleware: () => RequestContextMiddleware,
@@ -9011,7 +9013,7 @@ __export(index_exports, {
9011
9013
  module.exports = __toCommonJS(index_exports);
9012
9014
 
9013
9015
  // src/logger.module.ts
9014
- var import_common5 = require("@nestjs/common");
9016
+ var import_common6 = require("@nestjs/common");
9015
9017
 
9016
9018
  // src/logger.provider.ts
9017
9019
  var import_common = require("@nestjs/common");
@@ -9077,6 +9079,7 @@ LoggerProvider = _ts_decorate([
9077
9079
 
9078
9080
  // src/logger.token.ts
9079
9081
  var LOGGER_PROVIDER = "LOGGER_PROVIDER";
9082
+ var LOGGER_CONFIG = "LOGGER_CONFIG";
9080
9083
  var HTTP_LOGGING_INTERCEPTOR = "HTTP_LOGGING_INTERCEPTOR";
9081
9084
 
9082
9085
  // src/implementations/winston/winston.logger.module.ts
@@ -9554,7 +9557,8 @@ WinstonImplementationModule = _ts_decorate3([
9554
9557
  ], WinstonImplementationModule);
9555
9558
 
9556
9559
  // src/interceptors/http-logging.interceptor.ts
9557
- var import_common4 = require("@nestjs/common");
9560
+ var import_common5 = require("@nestjs/common");
9561
+ var import_core = require("@nestjs/core");
9558
9562
  var import_operators = __toESM(require_operators());
9559
9563
 
9560
9564
  // src/interceptors/http-logging.interceptor.constant.ts
@@ -9564,6 +9568,11 @@ var HTTP_LOGGING_INTERCEPTOR_CONTEXT = {
9564
9568
  ON_ERROR: "HttpLoggingInterceptor.onError"
9565
9569
  };
9566
9570
 
9571
+ // src/interceptors/exclude-http-logging.decorator.ts
9572
+ var import_common4 = require("@nestjs/common");
9573
+ var EXCLUDE_HTTP_LOGGING_KEY = "EXCLUDE_HTTP_LOGGING";
9574
+ var ExcludeHttpLogging = /* @__PURE__ */ __name(() => (0, import_common4.SetMetadata)(EXCLUDE_HTTP_LOGGING_KEY, true), "ExcludeHttpLogging");
9575
+
9567
9576
  // src/interceptors/http-logging.interceptor.ts
9568
9577
  function _ts_decorate4(decorators, target, key, desc) {
9569
9578
  var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
@@ -9587,14 +9596,29 @@ var HttpLoggingInterceptor = class {
9587
9596
  __name(this, "HttpLoggingInterceptor");
9588
9597
  }
9589
9598
  logger;
9590
- constructor(logger) {
9599
+ reflector;
9600
+ excludedPaths;
9601
+ constructor(logger, reflector, config) {
9591
9602
  this.logger = logger;
9603
+ this.reflector = reflector;
9604
+ this.excludedPaths = config?.interceptorExcludedPaths ?? [];
9605
+ }
9606
+ isExcluded(url) {
9607
+ const normalized = url.replace(/^\/v\d+/, "");
9608
+ return this.excludedPaths.some((path) => normalized === path || normalized.startsWith(path + "/"));
9592
9609
  }
9593
9610
  intercept(context, next) {
9594
9611
  const http = context.switchToHttp();
9595
9612
  const request = http.getRequest();
9596
9613
  const response = http.getResponse();
9597
9614
  const start = Date.now();
9615
+ const isDecoratorExcluded = this.reflector.getAllAndOverride(EXCLUDE_HTTP_LOGGING_KEY, [
9616
+ context.getHandler(),
9617
+ context.getClass()
9618
+ ]);
9619
+ if (isDecoratorExcluded || this.isExcluded(request.url)) {
9620
+ return next.handle();
9621
+ }
9598
9622
  const { method, url, headers, body, query, params } = request;
9599
9623
  this.logger.info({
9600
9624
  message: "HTTP Request",
@@ -9651,11 +9675,15 @@ var HttpLoggingInterceptor = class {
9651
9675
  }
9652
9676
  };
9653
9677
  HttpLoggingInterceptor = _ts_decorate4([
9654
- (0, import_common4.Injectable)(),
9655
- _ts_param3(0, (0, import_common4.Inject)(LOGGER_PROVIDER)),
9678
+ (0, import_common5.Injectable)(),
9679
+ _ts_param3(0, (0, import_common5.Inject)(LOGGER_PROVIDER)),
9680
+ _ts_param3(2, (0, import_common5.Optional)()),
9681
+ _ts_param3(2, (0, import_common5.Inject)(LOGGER_CONFIG)),
9656
9682
  _ts_metadata3("design:type", Function),
9657
9683
  _ts_metadata3("design:paramtypes", [
9658
- typeof LoggerProviderInterface === "undefined" ? Object : LoggerProviderInterface
9684
+ typeof LoggerProviderInterface === "undefined" ? Object : LoggerProviderInterface,
9685
+ typeof import_core.Reflector === "undefined" ? Object : import_core.Reflector,
9686
+ typeof LoggerConfig === "undefined" ? Object : LoggerConfig
9659
9687
  ])
9660
9688
  ], HttpLoggingInterceptor);
9661
9689
 
@@ -9682,7 +9710,7 @@ var LoggerModule = class _LoggerModule {
9682
9710
  useClass: LoggerProvider
9683
9711
  };
9684
9712
  if (config && config.requestScoped) {
9685
- loggerProvider.scope = import_common5.Scope.REQUEST;
9713
+ loggerProvider.scope = import_common6.Scope.REQUEST;
9686
9714
  }
9687
9715
  return {
9688
9716
  module: _LoggerModule,
@@ -9690,11 +9718,16 @@ var LoggerModule = class _LoggerModule {
9690
9718
  implModule
9691
9719
  ],
9692
9720
  providers: [
9721
+ {
9722
+ provide: LOGGER_CONFIG,
9723
+ useValue: config ?? {}
9724
+ },
9693
9725
  loggerProvider,
9694
9726
  httpLoggingInterceptorProvider
9695
9727
  ],
9696
9728
  exports: [
9697
9729
  LOGGER_PROVIDER,
9730
+ LOGGER_CONFIG,
9698
9731
  HTTP_LOGGING_INTERCEPTOR
9699
9732
  ]
9700
9733
  };
@@ -9707,6 +9740,11 @@ var LoggerModule = class _LoggerModule {
9707
9740
  WinstonImplementationModule.forRootAsync(options)
9708
9741
  ],
9709
9742
  providers: [
9743
+ {
9744
+ provide: LOGGER_CONFIG,
9745
+ useFactory: options.useFactory,
9746
+ inject: options.inject || []
9747
+ },
9710
9748
  {
9711
9749
  provide: LOGGER_PROVIDER,
9712
9750
  useClass: LoggerProvider
@@ -9715,18 +9753,19 @@ var LoggerModule = class _LoggerModule {
9715
9753
  ],
9716
9754
  exports: [
9717
9755
  LOGGER_PROVIDER,
9756
+ LOGGER_CONFIG,
9718
9757
  HTTP_LOGGING_INTERCEPTOR
9719
9758
  ]
9720
9759
  };
9721
9760
  }
9722
9761
  };
9723
9762
  LoggerModule = _ts_decorate5([
9724
- (0, import_common5.Global)(),
9725
- (0, import_common5.Module)({})
9763
+ (0, import_common6.Global)(),
9764
+ (0, import_common6.Module)({})
9726
9765
  ], LoggerModule);
9727
9766
 
9728
9767
  // src/middleware/request-context.middleware.ts
9729
- var import_common6 = require("@nestjs/common");
9768
+ var import_common7 = require("@nestjs/common");
9730
9769
  var import_crypto = require("crypto");
9731
9770
 
9732
9771
  // src/request-id.constants.ts
@@ -9760,7 +9799,7 @@ var RequestContextMiddleware = class {
9760
9799
  }
9761
9800
  };
9762
9801
  RequestContextMiddleware = _ts_decorate6([
9763
- (0, import_common6.Injectable)()
9802
+ (0, import_common7.Injectable)()
9764
9803
  ], RequestContextMiddleware);
9765
9804
 
9766
9805
  // src/logger.config.ts
@@ -9772,9 +9811,11 @@ var DEFAULT_LOGGER_CONFIG = {
9772
9811
  // Annotate the CommonJS export names for ESM import in node:
9773
9812
  0 && (module.exports = {
9774
9813
  DEFAULT_LOGGER_CONFIG,
9814
+ ExcludeHttpLogging,
9775
9815
  HTTP_LOGGING_INTERCEPTOR,
9776
9816
  HTTP_LOGGING_INTERCEPTOR_CONTEXT,
9777
9817
  HttpLoggingInterceptor,
9818
+ LOGGER_CONFIG,
9778
9819
  LOGGER_PROVIDER,
9779
9820
  LoggerModule,
9780
9821
  RequestContextMiddleware,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@adatechnology/logger",
3
- "version": "0.0.8",
3
+ "version": "0.0.9",
4
4
  "publishConfig": {
5
5
  "access": "public"
6
6
  },
package/src/index.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  export { LoggerModule } from "./logger.module";
2
- export { LOGGER_PROVIDER, HTTP_LOGGING_INTERCEPTOR } from "./logger.token";
2
+ export { LOGGER_PROVIDER, LOGGER_CONFIG, HTTP_LOGGING_INTERCEPTOR } from "./logger.token";
3
3
  export type {
4
4
  LoggerProviderInterface,
5
5
  LogPayload,
@@ -8,6 +8,7 @@ export type {
8
8
  export { RequestContextMiddleware } from "./middleware/request-context.middleware";
9
9
  export { HttpLoggingInterceptor } from "./interceptors/http-logging.interceptor";
10
10
  export { HTTP_LOGGING_INTERCEPTOR_CONTEXT } from "./interceptors/http-logging.interceptor.constant";
11
+ export { ExcludeHttpLogging } from "./interceptors/exclude-http-logging.decorator";
11
12
  export { getContext, runWithContext } from "./context/async-context.service";
12
13
  export type { LoggerConfig } from "./logger.config";
13
14
  export { DEFAULT_LOGGER_CONFIG } from "./logger.config";
@@ -0,0 +1,6 @@
1
+ import { SetMetadata } from "@nestjs/common";
2
+
3
+ export const EXCLUDE_HTTP_LOGGING_KEY = "EXCLUDE_HTTP_LOGGING";
4
+
5
+ export const ExcludeHttpLogging = () =>
6
+ SetMetadata(EXCLUDE_HTTP_LOGGING_KEY, true);
@@ -1,16 +1,33 @@
1
- import { CallHandler, ExecutionContext, Inject, Injectable, NestInterceptor } from "@nestjs/common";
1
+ import { CallHandler, ExecutionContext, Inject, Injectable, NestInterceptor, Optional } from "@nestjs/common";
2
+ import { Reflector } from "@nestjs/core";
2
3
  import { Observable } from "rxjs";
3
4
  import { tap } from "rxjs/operators";
4
- import { LOGGER_PROVIDER } from "../logger.token";
5
+ import { LOGGER_PROVIDER, LOGGER_CONFIG } from "../logger.token";
5
6
  import type { LoggerProviderInterface } from "../logger.interface";
7
+ import type { LoggerConfig } from "../logger.config";
6
8
  import { HTTP_LOGGING_INTERCEPTOR_CONTEXT } from "./http-logging.interceptor.constant";
9
+ import { EXCLUDE_HTTP_LOGGING_KEY } from "./exclude-http-logging.decorator";
7
10
 
8
11
  @Injectable()
9
12
  export class HttpLoggingInterceptor implements NestInterceptor {
13
+ private readonly excludedPaths: string[];
14
+
10
15
  constructor(
11
16
  @Inject(LOGGER_PROVIDER)
12
17
  private readonly logger: LoggerProviderInterface,
13
- ) {}
18
+ private readonly reflector: Reflector,
19
+ @Optional() @Inject(LOGGER_CONFIG)
20
+ config?: LoggerConfig,
21
+ ) {
22
+ this.excludedPaths = config?.interceptorExcludedPaths ?? [];
23
+ }
24
+
25
+ private isExcluded(url: string): boolean {
26
+ const normalized = url.replace(/^\/v\d+/, "");
27
+ return this.excludedPaths.some(
28
+ (path) => normalized === path || normalized.startsWith(path + "/"),
29
+ );
30
+ }
14
31
 
15
32
  intercept(context: ExecutionContext, next: CallHandler): Observable<unknown> {
16
33
  const http = context.switchToHttp();
@@ -18,6 +35,15 @@ export class HttpLoggingInterceptor implements NestInterceptor {
18
35
  const response = http.getResponse<Record<string, any>>();
19
36
  const start = Date.now();
20
37
 
38
+ const isDecoratorExcluded = this.reflector.getAllAndOverride<boolean>(
39
+ EXCLUDE_HTTP_LOGGING_KEY,
40
+ [context.getHandler(), context.getClass()],
41
+ );
42
+
43
+ if (isDecoratorExcluded || this.isExcluded(request.url)) {
44
+ return next.handle();
45
+ }
46
+
21
47
  const { method, url, headers, body, query, params } = request;
22
48
 
23
49
  this.logger.info({
@@ -46,6 +46,12 @@ export interface LoggerConfig extends WinstonModuleConfig {
46
46
  * Versão da biblioteca/módulo que está gerando o log
47
47
  */
48
48
  libVersion?: string;
49
+
50
+ /**
51
+ * Rotas excluídas do HttpLoggingInterceptor (ex.: ['/health'])
52
+ * Suporta prefixo exato ou parcial via startsWith
53
+ */
54
+ interceptorExcludedPaths?: string[];
49
55
  }
50
56
 
51
57
  export const DEFAULT_LOGGER_CONFIG: LoggerConfig = {
@@ -1,6 +1,6 @@
1
1
  import { DynamicModule, Module, Scope, Provider, Global } from "@nestjs/common";
2
2
  import { LoggerProvider } from "./logger.provider";
3
- import { LOGGER_PROVIDER, HTTP_LOGGING_INTERCEPTOR } from "./logger.token";
3
+ import { LOGGER_PROVIDER, LOGGER_CONFIG, HTTP_LOGGING_INTERCEPTOR } from "./logger.token";
4
4
  import { WinstonImplementationModule } from "./implementations/winston/winston.logger.module";
5
5
  import { HttpLoggingInterceptor } from "./interceptors/http-logging.interceptor";
6
6
  import type { LoggerConfig } from "./logger.config";
@@ -26,8 +26,12 @@ export class LoggerModule {
26
26
  return {
27
27
  module: LoggerModule,
28
28
  imports: [implModule],
29
- providers: [loggerProvider, httpLoggingInterceptorProvider],
30
- exports: [LOGGER_PROVIDER, HTTP_LOGGING_INTERCEPTOR],
29
+ providers: [
30
+ { provide: LOGGER_CONFIG, useValue: config ?? {} },
31
+ loggerProvider,
32
+ httpLoggingInterceptorProvider,
33
+ ],
34
+ exports: [LOGGER_PROVIDER, LOGGER_CONFIG, HTTP_LOGGING_INTERCEPTOR],
31
35
  };
32
36
  }
33
37
 
@@ -43,13 +47,18 @@ export class LoggerModule {
43
47
  WinstonImplementationModule.forRootAsync(options),
44
48
  ],
45
49
  providers: [
50
+ {
51
+ provide: LOGGER_CONFIG,
52
+ useFactory: options.useFactory,
53
+ inject: options.inject || [],
54
+ },
46
55
  {
47
56
  provide: LOGGER_PROVIDER,
48
57
  useClass: LoggerProvider,
49
58
  },
50
59
  httpLoggingInterceptorProvider,
51
60
  ],
52
- exports: [LOGGER_PROVIDER, HTTP_LOGGING_INTERCEPTOR],
61
+ exports: [LOGGER_PROVIDER, LOGGER_CONFIG, HTTP_LOGGING_INTERCEPTOR],
53
62
  };
54
63
  }
55
64
  }
@@ -1,2 +1,3 @@
1
1
  export const LOGGER_PROVIDER = "LOGGER_PROVIDER";
2
+ export const LOGGER_CONFIG = "LOGGER_CONFIG";
2
3
  export const HTTP_LOGGING_INTERCEPTOR = "HTTP_LOGGING_INTERCEPTOR";