@takentrade/takentrade-libs 4.1.9 → 4.1.11

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/README.md CHANGED
@@ -2,7 +2,7 @@
2
2
 
3
3
  Shared libraries for the TakeNTrade microservices architecture.
4
4
 
5
- This package provides shared authentication, caching, messaging, notification, and utility contracts used by the service repos.
5
+ This package provides shared authentication, caching, logging, messaging, RPC, notification, and utility contracts used by the service repos.
6
6
 
7
7
  ## Installation
8
8
 
@@ -50,6 +50,7 @@ For authentication, services can extend the shared `TntBaseAuthGuard` and pair i
50
50
  | ------------------ | ---------------------------------------------- | ---------------------------------------------- |
51
51
  | **Authentication** | Route protection and role-based access control | [docs/auth.md](docs/auth.md) |
52
52
  | **Cache** | Redis-based caching with TTL support | [docs/cache.md](docs/cache.md) |
53
+ | **Logging** | Shared structured logging helpers | [docs/logging.md](docs/logging.md) |
53
54
  | **NATS** | Microservice messaging and event streaming | [docs/nats.md](docs/nats.md) |
54
55
  | **Notifications** | Email, SMS, and push notifications | [docs/notifications.md](docs/notifications.md) |
55
56
  | **RPC** | Request-response patterns for NATS | [docs/rpc.md](docs/rpc.md) |
@@ -5,6 +5,7 @@ export interface LogContext {
5
5
  service?: string;
6
6
  [key: string]: any;
7
7
  }
8
+ type LoggerContext = string | LogContext;
8
9
  /**
9
10
  * TNT Logger Service - Pino-based structured JSON logger
10
11
  * Provides consistent logging across all microservices
@@ -17,26 +18,27 @@ export declare class TntLoggerService implements NestLoggerService {
17
18
  * Set context for all subsequent log messages
18
19
  */
19
20
  setContext(context: LogContext): void;
21
+ private normalizeContext;
20
22
  /**
21
23
  * Log info message
22
24
  */
23
- log(message: string, context?: LogContext): void;
25
+ log(message: string, context?: LoggerContext): void;
24
26
  /**
25
27
  * Log error message
26
28
  */
27
- error(message: string, trace?: string, context?: LogContext): void;
29
+ error(message: string, trace?: string, context?: LoggerContext): void;
28
30
  /**
29
31
  * Log warning message
30
32
  */
31
- warn(message: string, context?: LogContext): void;
33
+ warn(message: string, context?: LoggerContext): void;
32
34
  /**
33
35
  * Log debug message
34
36
  */
35
- debug(message: string, context?: LogContext): void;
37
+ debug(message: string, context?: LoggerContext): void;
36
38
  /**
37
39
  * Log verbose message
38
40
  */
39
- verbose(message: string, context?: LogContext): void;
41
+ verbose(message: string, context?: LoggerContext): void;
40
42
  /**
41
43
  * Log HTTP request
42
44
  */
@@ -46,3 +48,4 @@ export declare class TntLoggerService implements NestLoggerService {
46
48
  */
47
49
  logResponse(req: any, res: any, responseTime: number, context?: LogContext): void;
48
50
  }
51
+ export {};
@@ -44,35 +44,44 @@ let TntLoggerService = class TntLoggerService {
44
44
  setContext(context) {
45
45
  this.context = { ...this.context, ...context };
46
46
  }
47
+ normalizeContext(context) {
48
+ if (!context) {
49
+ return {};
50
+ }
51
+ if (typeof context === 'string') {
52
+ return { context };
53
+ }
54
+ return context;
55
+ }
47
56
  /**
48
57
  * Log info message
49
58
  */
50
59
  log(message, context) {
51
- this.logger.info({ ...this.context, ...context }, message);
60
+ this.logger.info({ ...this.context, ...this.normalizeContext(context) }, message);
52
61
  }
53
62
  /**
54
63
  * Log error message
55
64
  */
56
65
  error(message, trace, context) {
57
- this.logger.error({ ...this.context, ...context, trace }, message);
66
+ this.logger.error({ ...this.context, ...this.normalizeContext(context), trace }, message);
58
67
  }
59
68
  /**
60
69
  * Log warning message
61
70
  */
62
71
  warn(message, context) {
63
- this.logger.warn({ ...this.context, ...context }, message);
72
+ this.logger.warn({ ...this.context, ...this.normalizeContext(context) }, message);
64
73
  }
65
74
  /**
66
75
  * Log debug message
67
76
  */
68
77
  debug(message, context) {
69
- this.logger.debug({ ...this.context, ...context }, message);
78
+ this.logger.debug({ ...this.context, ...this.normalizeContext(context) }, message);
70
79
  }
71
80
  /**
72
81
  * Log verbose message
73
82
  */
74
83
  verbose(message, context) {
75
- this.logger.trace({ ...this.context, ...context }, message);
84
+ this.logger.trace({ ...this.context, ...this.normalizeContext(context) }, message);
76
85
  }
77
86
  /**
78
87
  * Log HTTP request