@eqxjs/nest-logger 3.1.0-beta.12 → 3.1.0-beta.14

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.
Files changed (34) hide show
  1. package/README.md +646 -78
  2. package/dist/constants/action-message.constant.d.ts +171 -0
  3. package/dist/constants/action-message.constant.js +171 -0
  4. package/dist/constants/action-message.constant.js.map +1 -1
  5. package/dist/core/formatters/logger.formatter.d.ts +107 -0
  6. package/dist/core/formatters/logger.formatter.js +107 -0
  7. package/dist/core/formatters/logger.formatter.js.map +1 -1
  8. package/dist/core/loggers/app.logger.d.ts +33 -0
  9. package/dist/core/loggers/app.logger.js +51 -0
  10. package/dist/core/loggers/app.logger.js.map +1 -1
  11. package/dist/core/loggers/base-app.logger.js +2 -3
  12. package/dist/core/loggers/base-app.logger.js.map +1 -1
  13. package/dist/core/loggers/custom.logger.d.ts +111 -0
  14. package/dist/core/loggers/custom.logger.js +119 -0
  15. package/dist/core/loggers/custom.logger.js.map +1 -1
  16. package/dist/helpers/datetime.helper.d.ts +23 -0
  17. package/dist/helpers/datetime.helper.js +23 -0
  18. package/dist/helpers/datetime.helper.js.map +1 -1
  19. package/dist/helpers/log.helper.d.ts +81 -0
  20. package/dist/helpers/log.helper.js +81 -0
  21. package/dist/helpers/log.helper.js.map +1 -1
  22. package/dist/helpers/logger-builder.helper.d.ts +207 -2
  23. package/dist/helpers/logger-builder.helper.js +207 -2
  24. package/dist/helpers/logger-builder.helper.js.map +1 -1
  25. package/dist/helpers/message-formatter.helper.d.ts +74 -7
  26. package/dist/helpers/message-formatter.helper.js +74 -7
  27. package/dist/helpers/message-formatter.helper.js.map +1 -1
  28. package/dist/helpers/time-performance.helper.d.ts +61 -0
  29. package/dist/helpers/time-performance.helper.js +62 -1
  30. package/dist/helpers/time-performance.helper.js.map +1 -1
  31. package/dist/models/logger.dto.d.ts +43 -0
  32. package/dist/models/logger.dto.js +43 -0
  33. package/dist/models/logger.dto.js.map +1 -1
  34. package/package.json +1 -1
@@ -1,3 +1,84 @@
1
+ /**
2
+ * Checks if a specific log level is enabled based on the LOG_LEVEL environment variable.
3
+ *
4
+ * The LOG_LEVEL environment variable should contain a comma-separated list of enabled levels.
5
+ * Common log levels: 'debug', 'info', 'log', 'warn', 'error', 'verbose'
6
+ *
7
+ * @param level - The log level to check (e.g., 'info', 'debug', 'error')
8
+ * @returns True if the level is enabled, false otherwise
9
+ *
10
+ * @example
11
+ * ```typescript
12
+ * process.env.LOG_LEVEL = 'info,error,warn';
13
+ *
14
+ * if (isLevelEnable('debug')) {
15
+ * // Won't execute - debug is not enabled
16
+ * console.log('Debug info');
17
+ * }
18
+ *
19
+ * if (isLevelEnable('info')) {
20
+ * // Will execute - info is enabled
21
+ * console.log('Info message');
22
+ * }
23
+ * ```
24
+ */
1
25
  export declare function isLevelEnable(level: string): boolean;
26
+ /**
27
+ * JSON replacer function that masks sensitive field values.
28
+ *
29
+ * Used with JSON.stringify to automatically replace sensitive field values with '*****'.
30
+ * Sensitive fields are configured via the LOG_MASK_KEYS environment variable.
31
+ *
32
+ * @param key - The property key being stringified
33
+ * @param value - The property value being stringified
34
+ * @returns The original value if not sensitive, or '*****' if the key is in the mask list
35
+ *
36
+ * @example
37
+ * ```typescript
38
+ * process.env.LOG_MASK_KEYS = 'password,apiKey,secret';
39
+ *
40
+ * const data = {
41
+ * username: 'john',
42
+ * password: 'secret123',
43
+ * apiKey: 'abc-def-ghi'
44
+ * };
45
+ *
46
+ * const masked = JSON.stringify(data, maskMessageReplacer);
47
+ * // {"username":"john","password":"*****","apiKey":"*****"}
48
+ * ```
49
+ *
50
+ * @see logStringify
51
+ */
2
52
  export declare function maskMessageReplacer(key: string, value: any): any;
53
+ /**
54
+ * Converts any value to a string with automatic masking of sensitive fields.
55
+ *
56
+ * Handles various input types:
57
+ * - Strings: returned as-is
58
+ * - Objects: JSON stringified with automatic masking via maskMessageReplacer
59
+ * - Others: converted using String()
60
+ *
61
+ * Sensitive fields are masked based on the LOG_MASK_KEYS environment variable.
62
+ *
63
+ * @param message - The value to stringify (can be any type)
64
+ * @returns String representation of the message with sensitive fields masked
65
+ *
66
+ * @example
67
+ * ```typescript
68
+ * process.env.LOG_MASK_KEYS = 'password,token';
69
+ *
70
+ * // String input
71
+ * logStringify('Hello'); // "Hello"
72
+ *
73
+ * // Object with sensitive data
74
+ * const user = { name: 'John', password: 'secret' };
75
+ * logStringify(user); // '{"name":"John","password":"*****"}'
76
+ *
77
+ * // Nested objects
78
+ * const data = { user: { token: 'abc123' }, message: 'test' };
79
+ * logStringify(data); // '{"user":{"token":"*****"},"message":"test"}'
80
+ * ```
81
+ *
82
+ * @see maskMessageReplacer
83
+ */
3
84
  export declare function logStringify(message: any): string;
@@ -3,10 +3,60 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.isLevelEnable = isLevelEnable;
4
4
  exports.maskMessageReplacer = maskMessageReplacer;
5
5
  exports.logStringify = logStringify;
6
+ /**
7
+ * Checks if a specific log level is enabled based on the LOG_LEVEL environment variable.
8
+ *
9
+ * The LOG_LEVEL environment variable should contain a comma-separated list of enabled levels.
10
+ * Common log levels: 'debug', 'info', 'log', 'warn', 'error', 'verbose'
11
+ *
12
+ * @param level - The log level to check (e.g., 'info', 'debug', 'error')
13
+ * @returns True if the level is enabled, false otherwise
14
+ *
15
+ * @example
16
+ * ```typescript
17
+ * process.env.LOG_LEVEL = 'info,error,warn';
18
+ *
19
+ * if (isLevelEnable('debug')) {
20
+ * // Won't execute - debug is not enabled
21
+ * console.log('Debug info');
22
+ * }
23
+ *
24
+ * if (isLevelEnable('info')) {
25
+ * // Will execute - info is enabled
26
+ * console.log('Info message');
27
+ * }
28
+ * ```
29
+ */
6
30
  function isLevelEnable(level) {
7
31
  const configLevel = process.env.LOG_LEVEL?.split(',') ?? [];
8
32
  return configLevel.includes(level);
9
33
  }
34
+ /**
35
+ * JSON replacer function that masks sensitive field values.
36
+ *
37
+ * Used with JSON.stringify to automatically replace sensitive field values with '*****'.
38
+ * Sensitive fields are configured via the LOG_MASK_KEYS environment variable.
39
+ *
40
+ * @param key - The property key being stringified
41
+ * @param value - The property value being stringified
42
+ * @returns The original value if not sensitive, or '*****' if the key is in the mask list
43
+ *
44
+ * @example
45
+ * ```typescript
46
+ * process.env.LOG_MASK_KEYS = 'password,apiKey,secret';
47
+ *
48
+ * const data = {
49
+ * username: 'john',
50
+ * password: 'secret123',
51
+ * apiKey: 'abc-def-ghi'
52
+ * };
53
+ *
54
+ * const masked = JSON.stringify(data, maskMessageReplacer);
55
+ * // {"username":"john","password":"*****","apiKey":"*****"}
56
+ * ```
57
+ *
58
+ * @see logStringify
59
+ */
10
60
  function maskMessageReplacer(key, value) {
11
61
  const maskConfig = process.env.LOG_MASK_KEYS?.split(',') ?? [];
12
62
  if (maskConfig.includes(key)) {
@@ -14,6 +64,37 @@ function maskMessageReplacer(key, value) {
14
64
  }
15
65
  return value;
16
66
  }
67
+ /**
68
+ * Converts any value to a string with automatic masking of sensitive fields.
69
+ *
70
+ * Handles various input types:
71
+ * - Strings: returned as-is
72
+ * - Objects: JSON stringified with automatic masking via maskMessageReplacer
73
+ * - Others: converted using String()
74
+ *
75
+ * Sensitive fields are masked based on the LOG_MASK_KEYS environment variable.
76
+ *
77
+ * @param message - The value to stringify (can be any type)
78
+ * @returns String representation of the message with sensitive fields masked
79
+ *
80
+ * @example
81
+ * ```typescript
82
+ * process.env.LOG_MASK_KEYS = 'password,token';
83
+ *
84
+ * // String input
85
+ * logStringify('Hello'); // "Hello"
86
+ *
87
+ * // Object with sensitive data
88
+ * const user = { name: 'John', password: 'secret' };
89
+ * logStringify(user); // '{"name":"John","password":"*****"}'
90
+ *
91
+ * // Nested objects
92
+ * const data = { user: { token: 'abc123' }, message: 'test' };
93
+ * logStringify(data); // '{"user":{"token":"*****"},"message":"test"}'
94
+ * ```
95
+ *
96
+ * @see maskMessageReplacer
97
+ */
17
98
  function logStringify(message) {
18
99
  if (typeof message === 'string') {
19
100
  return message;
@@ -1 +1 @@
1
- {"version":3,"file":"log.helper.js","sourceRoot":"","sources":["../../src/helpers/log.helper.ts"],"names":[],"mappings":";;AAAA,sCAGC;AAED,kDAMC;AAED,oCASC;AAtBD,SAAgB,aAAa,CAAC,KAAa;IACzC,MAAM,WAAW,GAAG,OAAO,CAAC,GAAG,CAAC,SAAS,EAAE,KAAK,CAAC,GAAG,CAAC,IAAI,EAAE,CAAC;IAC5D,OAAO,WAAW,CAAC,QAAQ,CAAC,KAAK,CAAC,CAAC;AACrC,CAAC;AAED,SAAgB,mBAAmB,CAAC,GAAW,EAAE,KAAU;IACzD,MAAM,UAAU,GAAG,OAAO,CAAC,GAAG,CAAC,aAAa,EAAE,KAAK,CAAC,GAAG,CAAC,IAAI,EAAE,CAAC;IAC/D,IAAI,UAAU,CAAC,QAAQ,CAAC,GAAG,CAAC,EAAE,CAAC;QAC7B,OAAO,OAAO,CAAC;IACjB,CAAC;IACD,OAAO,KAAK,CAAC;AACf,CAAC;AAED,SAAgB,YAAY,CAAC,OAAY;IACvC,IAAI,OAAO,OAAO,KAAK,QAAQ,EAAE,CAAC;QAChC,OAAO,OAAO,CAAC;IACjB,CAAC;IACD,IAAI,CAAC;QACH,OAAO,IAAI,CAAC,SAAS,CAAC,OAAO,EAAE,mBAAmB,CAAC,CAAC;IACtD,CAAC;IAAC,MAAM,CAAC;QACP,OAAO,MAAM,CAAC,OAAO,CAAC,CAAC;IACzB,CAAC;AACH,CAAC"}
1
+ {"version":3,"file":"log.helper.js","sourceRoot":"","sources":["../../src/helpers/log.helper.ts"],"names":[],"mappings":";;AAwBA,sCAGC;AA4BD,kDAMC;AAiCD,oCASC;AAvGD;;;;;;;;;;;;;;;;;;;;;;;GAuBG;AACH,SAAgB,aAAa,CAAC,KAAa;IACzC,MAAM,WAAW,GAAG,OAAO,CAAC,GAAG,CAAC,SAAS,EAAE,KAAK,CAAC,GAAG,CAAC,IAAI,EAAE,CAAC;IAC5D,OAAO,WAAW,CAAC,QAAQ,CAAC,KAAK,CAAC,CAAC;AACrC,CAAC;AAED;;;;;;;;;;;;;;;;;;;;;;;;;GAyBG;AACH,SAAgB,mBAAmB,CAAC,GAAW,EAAE,KAAU;IACzD,MAAM,UAAU,GAAG,OAAO,CAAC,GAAG,CAAC,aAAa,EAAE,KAAK,CAAC,GAAG,CAAC,IAAI,EAAE,CAAC;IAC/D,IAAI,UAAU,CAAC,QAAQ,CAAC,GAAG,CAAC,EAAE,CAAC;QAC7B,OAAO,OAAO,CAAC;IACjB,CAAC;IACD,OAAO,KAAK,CAAC;AACf,CAAC;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA8BG;AACH,SAAgB,YAAY,CAAC,OAAY;IACvC,IAAI,OAAO,OAAO,KAAK,QAAQ,EAAE,CAAC;QAChC,OAAO,OAAO,CAAC;IACjB,CAAC;IACD,IAAI,CAAC;QACH,OAAO,IAAI,CAAC,SAAS,CAAC,OAAO,EAAE,mBAAmB,CAAC,CAAC;IACtD,CAAC;IAAC,MAAM,CAAC;QACP,OAAO,MAAM,CAAC,OAAO,CAAC,CAAC;IACzB,CAAC;AACH,CAAC"}
@@ -1,37 +1,242 @@
1
1
  import { LoggerDto } from '../models/logger.dto';
2
+ /**
3
+ * LoggerDtoBuilder - Fluent builder for creating LoggerDto instances.
4
+ *
5
+ * Provides a chainable API for constructing logger data transfer objects with all necessary fields.
6
+ * Each setter method returns 'this' to enable method chaining. The builder pattern ensures
7
+ * consistent and readable construction of complex logger DTOs.
8
+ *
9
+ * @example
10
+ * ```typescript
11
+ * const dto = new LoggerDtoBuilder()
12
+ * .setLevel('info')
13
+ * .setTimestamp('2026-01-12T10:00:00.000Z')
14
+ * .setAppName('MyApp')
15
+ * .setComponentName('UserService')
16
+ * .setAction('[USER_CREATE]')
17
+ * .setMessage('User created successfully')
18
+ * .setSessionId('sess-123')
19
+ * .normalizeEmptyFields()
20
+ * .build();
21
+ * ```
22
+ */
2
23
  export declare class LoggerDtoBuilder {
3
24
  private dto;
25
+ /**
26
+ * Creates a new LoggerDtoBuilder instance with an empty LoggerDto.
27
+ */
4
28
  constructor();
29
+ /**
30
+ * Sets the log level.
31
+ *
32
+ * @param level - Log level (e.g., 'debug', 'info', 'warn', 'error')
33
+ * @returns This builder instance for method chaining
34
+ */
5
35
  setLevel(level: string): this;
36
+ /**
37
+ * Sets the timestamp for the log entry.
38
+ *
39
+ * @param timestamp - ISO 8601 formatted timestamp string
40
+ * @returns This builder instance for method chaining
41
+ */
6
42
  setTimestamp(timestamp: string): this;
43
+ /**
44
+ * Sets the application name.
45
+ *
46
+ * @param appName - Name of the application
47
+ * @returns This builder instance for method chaining
48
+ */
7
49
  setAppName(appName: string): this;
50
+ /**
51
+ * Sets the component name (optional).
52
+ * Only sets the value if componentName is provided.
53
+ *
54
+ * @param componentName - Name of the component or service
55
+ * @returns This builder instance for method chaining
56
+ */
8
57
  setComponentName(componentName?: string): this;
58
+ /**
59
+ * Sets the action tag for the log entry.
60
+ *
61
+ * @param action - Action identifier (e.g., '[HTTP_REQUEST]', '[DB_QUERY]')
62
+ * @returns This builder instance for method chaining
63
+ */
9
64
  setAction(action: string): this;
65
+ /**
66
+ * Sets the log message.
67
+ *
68
+ * @param message - The log message content
69
+ * @returns This builder instance for method chaining
70
+ */
10
71
  setMessage(message: string): this;
72
+ /**
73
+ * Sets the instance identifier (typically hostname or container ID).
74
+ *
75
+ * @param instance - Instance identifier
76
+ * @returns This builder instance for method chaining
77
+ */
11
78
  setInstance(instance: string): this;
79
+ /**
80
+ * Sets the originating service name.
81
+ *
82
+ * @param originateServiceName - Name of the service that originated the log
83
+ * @returns This builder instance for method chaining
84
+ */
12
85
  setOriginateServiceName(originateServiceName: string): this;
86
+ /**
87
+ * Sets the record name or identifier.
88
+ *
89
+ * @param recordName - Record identifier (e.g., order ID, user ID)
90
+ * @returns This builder instance for method chaining
91
+ */
13
92
  setRecordName(recordName: string): this;
93
+ /**
94
+ * Sets the record type (e.g., 'detail', 'summary').
95
+ *
96
+ * @param recordType - Type of the log record
97
+ * @returns This builder instance for method chaining
98
+ */
14
99
  setRecordType(recordType: string): this;
100
+ /**
101
+ * Sets the session identifier.
102
+ *
103
+ * @param sessionId - Session ID for tracking user sessions
104
+ * @returns This builder instance for method chaining
105
+ */
15
106
  setSessionId(sessionId: string): this;
107
+ /**
108
+ * Sets the transaction identifier.
109
+ *
110
+ * @param transactionId - Transaction ID for tracking distributed transactions
111
+ * @returns This builder instance for method chaining
112
+ */
16
113
  setTransactionId(transactionId: string): this;
114
+ /**
115
+ * Sets the communication channel.
116
+ *
117
+ * @param channel - Channel identifier (e.g., 'web', 'mobile', 'api')
118
+ * @returns This builder instance for method chaining
119
+ */
17
120
  setChannel(channel: string): this;
121
+ /**
122
+ * Sets the component version.
123
+ *
124
+ * @param componentVersion - Version of the component (e.g., '1.0.0')
125
+ * @returns This builder instance for method chaining
126
+ */
18
127
  setComponentVersion(componentVersion: string): this;
128
+ /**
129
+ * Sets the use case name.
130
+ *
131
+ * @param useCase - Name of the use case being executed
132
+ * @returns This builder instance for method chaining
133
+ */
19
134
  setUseCase(useCase: string): this;
135
+ /**
136
+ * Sets the use case step.
137
+ *
138
+ * @param useCaseStep - Specific step within the use case
139
+ * @returns This builder instance for method chaining
140
+ */
20
141
  setUseCaseStep(useCaseStep: string): this;
142
+ /**
143
+ * Sets the user identifier.
144
+ *
145
+ * @param user - User identifier (e.g., email, username, user ID)
146
+ * @returns This builder instance for method chaining
147
+ */
21
148
  setUser(user: string): this;
149
+ /**
150
+ * Sets the device identifier(s).
151
+ *
152
+ * @param device - Single device identifier or array of identifiers
153
+ * @returns This builder instance for method chaining
154
+ */
22
155
  setDevice(device: string | string[]): this;
156
+ /**
157
+ * Sets the public identifier(s).
158
+ *
159
+ * @param public_ - Single public identifier or array of identifiers
160
+ * @returns This builder instance for method chaining
161
+ */
23
162
  setPublic(public_: string | string[]): this;
163
+ /**
164
+ * Sets the application result description.
165
+ *
166
+ * @param appResult - Result description (e.g., 'Success', 'Failed')
167
+ * @returns This builder instance for method chaining
168
+ */
24
169
  setAppResult(appResult: string): this;
170
+ /**
171
+ * Sets the application result code.
172
+ *
173
+ * @param appResultCode - Result code (e.g., '200', '500', 'ERR_001')
174
+ * @returns This builder instance for method chaining
175
+ */
25
176
  setAppResultCode(appResultCode: string): this;
177
+ /**
178
+ * Sets the service processing time in milliseconds.
179
+ *
180
+ * @param serviceTime - Processing duration in milliseconds
181
+ * @returns This builder instance for method chaining
182
+ */
26
183
  setServiceTime(serviceTime: number): this;
184
+ /**
185
+ * Sets the error stack trace (optional).
186
+ * Only sets the value if stack is provided and not empty.
187
+ *
188
+ * @param stack - Array of stack trace lines
189
+ * @returns This builder instance for method chaining
190
+ */
27
191
  setStack(stack?: string[]): this;
28
192
  /**
29
- * Replace empty strings with 'none'
193
+ * Normalizes empty string fields by replacing them with DEFAULT_VALUES.NONE ('none').
194
+ *
195
+ * Iterates through all DTO properties and replaces any empty string values
196
+ * with the default 'none' value for consistency in log output.
197
+ *
198
+ * @returns This builder instance for method chaining
199
+ *
200
+ * @example
201
+ * ```typescript
202
+ * const dto = new LoggerDtoBuilder()
203
+ * .setLevel('info')
204
+ * .setMessage('') // Empty string
205
+ * .normalizeEmptyFields() // Converts empty string to 'none'
206
+ * .build();
207
+ * ```
30
208
  */
31
209
  normalizeEmptyFields(): this;
32
210
  /**
33
- * Merge additional options into the DTO
211
+ * Merges additional options into the DTO.
212
+ *
213
+ * Takes an optional object of additional fields and merges them into the DTO.
214
+ * Empty string values in the options are normalized to DEFAULT_VALUES.NONE.
215
+ *
216
+ * @param opt - Optional record of additional fields to merge
217
+ * @returns This builder instance for method chaining
218
+ *
219
+ * @example
220
+ * ```typescript
221
+ * const dto = new LoggerDtoBuilder()
222
+ * .setLevel('info')
223
+ * .mergeOptions({ broker: 'kafka', customField: 'value' })
224
+ * .build();
225
+ * ```
34
226
  */
35
227
  mergeOptions(opt?: Record<string, unknown>): this;
228
+ /**
229
+ * Builds and returns the final LoggerDto instance.
230
+ *
231
+ * @returns The constructed LoggerDto object
232
+ *
233
+ * @example
234
+ * ```typescript
235
+ * const dto = new LoggerDtoBuilder()
236
+ * .setLevel('info')
237
+ * .setMessage('Test message')
238
+ * .build();
239
+ * ```
240
+ */
36
241
  build(): LoggerDto;
37
242
  }