@adatechnology/logger 0.0.8 → 0.0.10

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.
@@ -5,21 +5,37 @@ export enum LoggerLevel {
5
5
  ERROR = "error",
6
6
  }
7
7
 
8
- export interface LogPayload {
8
+ export type LogParams = {
9
9
  message: string;
10
10
  context?: string;
11
11
  meta?: Record<string, unknown>;
12
- }
12
+ };
13
+
14
+ export type LogResult = void;
15
+
16
+ export type DebugParams = LogParams;
17
+ export type DebugResult = LogResult;
18
+
19
+ export type InfoParams = LogParams;
20
+ export type InfoResult = LogResult;
21
+
22
+ export type WarnParams = LogParams;
23
+ export type WarnResult = LogResult;
24
+
25
+ export type ErrorParams = LogParams;
26
+ export type ErrorResult = LogResult;
13
27
 
14
28
  export interface LoggerProviderInterface {
15
- debug(payload: LogPayload): void;
16
- info(payload: LogPayload): void;
17
- warn(payload: LogPayload): void;
18
- error(payload: LogPayload): void;
29
+ debug(params: DebugParams): DebugResult;
30
+ info(params: InfoParams): InfoResult;
31
+ warn(params: WarnParams): WarnResult;
32
+ error(params: ErrorParams): ErrorResult;
19
33
  setContext?(context: string): void;
20
34
  }
21
35
 
22
- export type LogParams = {
36
+ export type WriteLogParams = {
23
37
  level: LoggerLevel;
24
- payload: LogPayload;
38
+ payload: LogParams;
25
39
  };
40
+
41
+ export type WriteLogResult = LogResult;
@@ -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,5 +1,15 @@
1
1
  import { Injectable, Inject } from "@nestjs/common";
2
- import type { LoggerProviderInterface, LogPayload } from "./logger.interface";
2
+ import type {
3
+ DebugParams,
4
+ DebugResult,
5
+ ErrorParams,
6
+ ErrorResult,
7
+ InfoParams,
8
+ InfoResult,
9
+ LoggerProviderInterface,
10
+ WarnParams,
11
+ WarnResult,
12
+ } from "./logger.interface";
3
13
  import { WINSTON_LOGGER } from "./implementations/winston/winston.logger.token";
4
14
 
5
15
  @Injectable()
@@ -9,45 +19,24 @@ export class LoggerProvider implements LoggerProviderInterface {
9
19
  private readonly implementation: LoggerProviderInterface,
10
20
  ) {}
11
21
 
12
- debug(payload: LogPayload): void;
13
- debug(
14
- message: string,
15
- meta?: Record<string, unknown>,
16
- context?: string,
17
- ): void;
18
- debug(...args: unknown[]): void {
19
- // @ts-ignore - delegate to implementation which supports overloads
20
- return this.implementation.debug(...(args as any));
22
+ debug(params: DebugParams): DebugResult {
23
+ return this.implementation.debug(params);
21
24
  }
22
25
 
23
- info(payload: LogPayload): void;
24
- info(message: string, meta?: Record<string, unknown>, context?: string): void;
25
- info(...args: unknown[]): void {
26
- // @ts-ignore
27
- return this.implementation.info(...(args as any));
26
+ info(params: InfoParams): InfoResult {
27
+ return this.implementation.info(params);
28
28
  }
29
29
 
30
- warn(payload: LogPayload): void;
31
- warn(message: string, meta?: Record<string, unknown>, context?: string): void;
32
- warn(...args: unknown[]): void {
33
- // @ts-ignore
34
- return this.implementation.warn(...(args as any));
30
+ warn(params: WarnParams): WarnResult {
31
+ return this.implementation.warn(params);
35
32
  }
36
33
 
37
- error(payload: LogPayload): void;
38
- error(
39
- message: string,
40
- meta?: Record<string, unknown>,
41
- context?: string,
42
- ): void;
43
- error(...args: unknown[]): void {
44
- // @ts-ignore
45
- return this.implementation.error(...(args as any));
34
+ error(params: ErrorParams): ErrorResult {
35
+ return this.implementation.error(params);
46
36
  }
47
37
  setContext?(context: string): void {
48
38
  if (typeof this.implementation.setContext === "function") {
49
39
  return this.implementation.setContext(context);
50
40
  }
51
- return;
52
41
  }
53
42
  }
@@ -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";