@takentrade/takentrade-libs 4.1.11 → 4.1.12
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/logging/index.d.ts
CHANGED
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
export interface LogContext {
|
|
2
|
+
correlationId?: string;
|
|
3
|
+
userId?: string;
|
|
4
|
+
service?: string;
|
|
5
|
+
[key: string]: any;
|
|
6
|
+
}
|
|
7
|
+
export type LoggerContext = string | LogContext;
|
|
8
|
+
export interface TntLogger {
|
|
9
|
+
setContext(context: LogContext): void;
|
|
10
|
+
log(message: string, context?: LoggerContext): void;
|
|
11
|
+
error(message: string, trace?: string, context?: LoggerContext): void;
|
|
12
|
+
warn(message: string, context?: LoggerContext): void;
|
|
13
|
+
debug(message: string, context?: LoggerContext): void;
|
|
14
|
+
verbose(message: string, context?: LoggerContext): void;
|
|
15
|
+
logRequest(req: any, context?: LogContext): void;
|
|
16
|
+
logResponse(req: any, res: any, responseTime: number, context?: LogContext): void;
|
|
17
|
+
}
|
|
@@ -1,16 +1,10 @@
|
|
|
1
1
|
import { LoggerService as NestLoggerService } from '@nestjs/common';
|
|
2
|
-
|
|
3
|
-
correlationId?: string;
|
|
4
|
-
userId?: string;
|
|
5
|
-
service?: string;
|
|
6
|
-
[key: string]: any;
|
|
7
|
-
}
|
|
8
|
-
type LoggerContext = string | LogContext;
|
|
2
|
+
import { LogContext, LoggerContext, TntLogger } from './logger.interface';
|
|
9
3
|
/**
|
|
10
4
|
* TNT Logger Service - Pino-based structured JSON logger
|
|
11
5
|
* Provides consistent logging across all microservices
|
|
12
6
|
*/
|
|
13
|
-
export declare class TntLoggerService implements NestLoggerService {
|
|
7
|
+
export declare class TntLoggerService implements NestLoggerService, TntLogger {
|
|
14
8
|
private logger;
|
|
15
9
|
private context;
|
|
16
10
|
constructor(context?: LogContext);
|
|
@@ -19,6 +13,7 @@ export declare class TntLoggerService implements NestLoggerService {
|
|
|
19
13
|
*/
|
|
20
14
|
setContext(context: LogContext): void;
|
|
21
15
|
private normalizeContext;
|
|
16
|
+
private formatMessage;
|
|
22
17
|
/**
|
|
23
18
|
* Log info message
|
|
24
19
|
*/
|
|
@@ -48,4 +43,3 @@ export declare class TntLoggerService implements NestLoggerService {
|
|
|
48
43
|
*/
|
|
49
44
|
logResponse(req: any, res: any, responseTime: number, context?: LogContext): void;
|
|
50
45
|
}
|
|
51
|
-
export {};
|
|
@@ -49,39 +49,45 @@ let TntLoggerService = class TntLoggerService {
|
|
|
49
49
|
return {};
|
|
50
50
|
}
|
|
51
51
|
if (typeof context === 'string') {
|
|
52
|
-
return {
|
|
52
|
+
return {};
|
|
53
53
|
}
|
|
54
54
|
return context;
|
|
55
55
|
}
|
|
56
|
+
formatMessage(message, context) {
|
|
57
|
+
if (typeof context === 'string' && context.trim().length > 0) {
|
|
58
|
+
return `[${context.trim()}] ${message}`;
|
|
59
|
+
}
|
|
60
|
+
return message;
|
|
61
|
+
}
|
|
56
62
|
/**
|
|
57
63
|
* Log info message
|
|
58
64
|
*/
|
|
59
65
|
log(message, context) {
|
|
60
|
-
this.logger.info({ ...this.context, ...this.normalizeContext(context) }, message);
|
|
66
|
+
this.logger.info({ ...this.context, ...this.normalizeContext(context) }, this.formatMessage(message, context));
|
|
61
67
|
}
|
|
62
68
|
/**
|
|
63
69
|
* Log error message
|
|
64
70
|
*/
|
|
65
71
|
error(message, trace, context) {
|
|
66
|
-
this.logger.error({ ...this.context, ...this.normalizeContext(context), trace }, message);
|
|
72
|
+
this.logger.error({ ...this.context, ...this.normalizeContext(context), trace }, this.formatMessage(message, context));
|
|
67
73
|
}
|
|
68
74
|
/**
|
|
69
75
|
* Log warning message
|
|
70
76
|
*/
|
|
71
77
|
warn(message, context) {
|
|
72
|
-
this.logger.warn({ ...this.context, ...this.normalizeContext(context) }, message);
|
|
78
|
+
this.logger.warn({ ...this.context, ...this.normalizeContext(context) }, this.formatMessage(message, context));
|
|
73
79
|
}
|
|
74
80
|
/**
|
|
75
81
|
* Log debug message
|
|
76
82
|
*/
|
|
77
83
|
debug(message, context) {
|
|
78
|
-
this.logger.debug({ ...this.context, ...this.normalizeContext(context) }, message);
|
|
84
|
+
this.logger.debug({ ...this.context, ...this.normalizeContext(context) }, this.formatMessage(message, context));
|
|
79
85
|
}
|
|
80
86
|
/**
|
|
81
87
|
* Log verbose message
|
|
82
88
|
*/
|
|
83
89
|
verbose(message, context) {
|
|
84
|
-
this.logger.trace({ ...this.context, ...this.normalizeContext(context) }, message);
|
|
90
|
+
this.logger.trace({ ...this.context, ...this.normalizeContext(context) }, this.formatMessage(message, context));
|
|
85
91
|
}
|
|
86
92
|
/**
|
|
87
93
|
* Log HTTP request
|