@eqxjs/nest-logger 3.1.0-beta.13 → 3.1.0-beta.15

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/custom.logger.d.ts +111 -0
  12. package/dist/core/loggers/custom.logger.js +119 -0
  13. package/dist/core/loggers/custom.logger.js.map +1 -1
  14. package/dist/helpers/datetime.helper.d.ts +23 -0
  15. package/dist/helpers/datetime.helper.js +23 -0
  16. package/dist/helpers/datetime.helper.js.map +1 -1
  17. package/dist/helpers/log.helper.d.ts +81 -0
  18. package/dist/helpers/log.helper.js +81 -0
  19. package/dist/helpers/log.helper.js.map +1 -1
  20. package/dist/helpers/logger-builder.helper.d.ts +207 -2
  21. package/dist/helpers/logger-builder.helper.js +207 -2
  22. package/dist/helpers/logger-builder.helper.js.map +1 -1
  23. package/dist/helpers/message-formatter.helper.d.ts +74 -7
  24. package/dist/helpers/message-formatter.helper.js +74 -7
  25. package/dist/helpers/message-formatter.helper.js.map +1 -1
  26. package/dist/helpers/time-performance.helper.d.ts +61 -0
  27. package/dist/helpers/time-performance.helper.js +62 -1
  28. package/dist/helpers/time-performance.helper.js.map +1 -1
  29. package/dist/interfaces/data-service.interface.d.ts +1 -1
  30. package/dist/interfaces/data.interface.d.ts +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
@@ -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,C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I,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
  }
@@ -3,101 +3,265 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.LoggerDtoBuilder = void 0;
4
4
  const logger_dto_1 = require("../models/logger.dto");
5
5
  const logger_constants_1 = require("../constants/logger.constants");
6
+ /**
7
+ * LoggerDtoBuilder - Fluent builder for creating LoggerDto instances.
8
+ *
9
+ * Provides a chainable API for constructing logger data transfer objects with all necessary fields.
10
+ * Each setter method returns 'this' to enable method chaining. The builder pattern ensures
11
+ * consistent and readable construction of complex logger DTOs.
12
+ *
13
+ * @example
14
+ * ```typescript
15
+ * const dto = new LoggerDtoBuilder()
16
+ * .setLevel('info')
17
+ * .setTimestamp('2026-01-12T10:00:00.000Z')
18
+ * .setAppName('MyApp')
19
+ * .setComponentName('UserService')
20
+ * .setAction('[USER_CREATE]')
21
+ * .setMessage('User created successfully')
22
+ * .setSessionId('sess-123')
23
+ * .normalizeEmptyFields()
24
+ * .build();
25
+ * ```
26
+ */
6
27
  class LoggerDtoBuilder {
7
28
  dto;
29
+ /**
30
+ * Creates a new LoggerDtoBuilder instance with an empty LoggerDto.
31
+ */
8
32
  constructor() {
9
33
  this.dto = new logger_dto_1.LoggerDto();
10
34
  }
35
+ /**
36
+ * Sets the log level.
37
+ *
38
+ * @param level - Log level (e.g., 'debug', 'info', 'warn', 'error')
39
+ * @returns This builder instance for method chaining
40
+ */
11
41
  setLevel(level) {
12
42
  this.dto.level = level;
13
43
  return this;
14
44
  }
45
+ /**
46
+ * Sets the timestamp for the log entry.
47
+ *
48
+ * @param timestamp - ISO 8601 formatted timestamp string
49
+ * @returns This builder instance for method chaining
50
+ */
15
51
  setTimestamp(timestamp) {
16
52
  this.dto.timestamp = timestamp;
17
53
  return this;
18
54
  }
55
+ /**
56
+ * Sets the application name.
57
+ *
58
+ * @param appName - Name of the application
59
+ * @returns This builder instance for method chaining
60
+ */
19
61
  setAppName(appName) {
20
62
  this.dto.appName = appName;
21
63
  return this;
22
64
  }
65
+ /**
66
+ * Sets the component name (optional).
67
+ * Only sets the value if componentName is provided.
68
+ *
69
+ * @param componentName - Name of the component or service
70
+ * @returns This builder instance for method chaining
71
+ */
23
72
  setComponentName(componentName) {
24
73
  if (componentName) {
25
74
  this.dto.componentName = componentName;
26
75
  }
27
76
  return this;
28
77
  }
78
+ /**
79
+ * Sets the action tag for the log entry.
80
+ *
81
+ * @param action - Action identifier (e.g., '[HTTP_REQUEST]', '[DB_QUERY]')
82
+ * @returns This builder instance for method chaining
83
+ */
29
84
  setAction(action) {
30
85
  this.dto.action = action;
31
86
  return this;
32
87
  }
88
+ /**
89
+ * Sets the log message.
90
+ *
91
+ * @param message - The log message content
92
+ * @returns This builder instance for method chaining
93
+ */
33
94
  setMessage(message) {
34
95
  this.dto.message = message;
35
96
  return this;
36
97
  }
98
+ /**
99
+ * Sets the instance identifier (typically hostname or container ID).
100
+ *
101
+ * @param instance - Instance identifier
102
+ * @returns This builder instance for method chaining
103
+ */
37
104
  setInstance(instance) {
38
105
  this.dto.instance = instance;
39
106
  return this;
40
107
  }
108
+ /**
109
+ * Sets the originating service name.
110
+ *
111
+ * @param originateServiceName - Name of the service that originated the log
112
+ * @returns This builder instance for method chaining
113
+ */
41
114
  setOriginateServiceName(originateServiceName) {
42
115
  this.dto.originateServiceName = originateServiceName;
43
116
  return this;
44
117
  }
118
+ /**
119
+ * Sets the record name or identifier.
120
+ *
121
+ * @param recordName - Record identifier (e.g., order ID, user ID)
122
+ * @returns This builder instance for method chaining
123
+ */
45
124
  setRecordName(recordName) {
46
125
  this.dto.recordName = recordName;
47
126
  return this;
48
127
  }
128
+ /**
129
+ * Sets the record type (e.g., 'detail', 'summary').
130
+ *
131
+ * @param recordType - Type of the log record
132
+ * @returns This builder instance for method chaining
133
+ */
49
134
  setRecordType(recordType) {
50
135
  this.dto.recordType = recordType;
51
136
  return this;
52
137
  }
138
+ /**
139
+ * Sets the session identifier.
140
+ *
141
+ * @param sessionId - Session ID for tracking user sessions
142
+ * @returns This builder instance for method chaining
143
+ */
53
144
  setSessionId(sessionId) {
54
145
  this.dto.sessionId = sessionId;
55
146
  return this;
56
147
  }
148
+ /**
149
+ * Sets the transaction identifier.
150
+ *
151
+ * @param transactionId - Transaction ID for tracking distributed transactions
152
+ * @returns This builder instance for method chaining
153
+ */
57
154
  setTransactionId(transactionId) {
58
155
  this.dto.transactionId = transactionId;
59
156
  return this;
60
157
  }
158
+ /**
159
+ * Sets the communication channel.
160
+ *
161
+ * @param channel - Channel identifier (e.g., 'web', 'mobile', 'api')
162
+ * @returns This builder instance for method chaining
163
+ */
61
164
  setChannel(channel) {
62
165
  this.dto.channel = channel;
63
166
  return this;
64
167
  }
168
+ /**
169
+ * Sets the component version.
170
+ *
171
+ * @param componentVersion - Version of the component (e.g., '1.0.0')
172
+ * @returns This builder instance for method chaining
173
+ */
65
174
  setComponentVersion(componentVersion) {
66
175
  this.dto.componentVersion = componentVersion;
67
176
  return this;
68
177
  }
178
+ /**
179
+ * Sets the use case name.
180
+ *
181
+ * @param useCase - Name of the use case being executed
182
+ * @returns This builder instance for method chaining
183
+ */
69
184
  setUseCase(useCase) {
70
185
  this.dto.useCase = useCase;
71
186
  return this;
72
187
  }
188
+ /**
189
+ * Sets the use case step.
190
+ *
191
+ * @param useCaseStep - Specific step within the use case
192
+ * @returns This builder instance for method chaining
193
+ */
73
194
  setUseCaseStep(useCaseStep) {
74
195
  this.dto.useCaseStep = useCaseStep;
75
196
  return this;
76
197
  }
198
+ /**
199
+ * Sets the user identifier.
200
+ *
201
+ * @param user - User identifier (e.g., email, username, user ID)
202
+ * @returns This builder instance for method chaining
203
+ */
77
204
  setUser(user) {
78
205
  this.dto.user = user;
79
206
  return this;
80
207
  }
208
+ /**
209
+ * Sets the device identifier(s).
210
+ *
211
+ * @param device - Single device identifier or array of identifiers
212
+ * @returns This builder instance for method chaining
213
+ */
81
214
  setDevice(device) {
82
215
  this.dto.device = device;
83
216
  return this;
84
217
  }
218
+ /**
219
+ * Sets the public identifier(s).
220
+ *
221
+ * @param public_ - Single public identifier or array of identifiers
222
+ * @returns This builder instance for method chaining
223
+ */
85
224
  setPublic(public_) {
86
225
  this.dto.public = public_;
87
226
  return this;
88
227
  }
228
+ /**
229
+ * Sets the application result description.
230
+ *
231
+ * @param appResult - Result description (e.g., 'Success', 'Failed')
232
+ * @returns This builder instance for method chaining
233
+ */
89
234
  setAppResult(appResult) {
90
235
  this.dto.appResult = appResult;
91
236
  return this;
92
237
  }
238
+ /**
239
+ * Sets the application result code.
240
+ *
241
+ * @param appResultCode - Result code (e.g., '200', '500', 'ERR_001')
242
+ * @returns This builder instance for method chaining
243
+ */
93
244
  setAppResultCode(appResultCode) {
94
245
  this.dto.appResultCode = appResultCode;
95
246
  return this;
96
247
  }
248
+ /**
249
+ * Sets the service processing time in milliseconds.
250
+ *
251
+ * @param serviceTime - Processing duration in milliseconds
252
+ * @returns This builder instance for method chaining
253
+ */
97
254
  setServiceTime(serviceTime) {
98
255
  this.dto.serviceTime = serviceTime;
99
256
  return this;
100
257
  }
258
+ /**
259
+ * Sets the error stack trace (optional).
260
+ * Only sets the value if stack is provided and not empty.
261
+ *
262
+ * @param stack - Array of stack trace lines
263
+ * @returns This builder instance for method chaining
264
+ */
101
265
  setStack(stack) {
102
266
  if (stack) {
103
267
  this.dto.stack = stack;
@@ -105,7 +269,21 @@ class LoggerDtoBuilder {
105
269
  return this;
106
270
  }
107
271
  /**
108
- * Replace empty strings with 'none'
272
+ * Normalizes empty string fields by replacing them with DEFAULT_VALUES.NONE ('none').
273
+ *
274
+ * Iterates through all DTO properties and replaces any empty string values
275
+ * with the default 'none' value for consistency in log output.
276
+ *
277
+ * @returns This builder instance for method chaining
278
+ *
279
+ * @example
280
+ * ```typescript
281
+ * const dto = new LoggerDtoBuilder()
282
+ * .setLevel('info')
283
+ * .setMessage('') // Empty string
284
+ * .normalizeEmptyFields() // Converts empty string to 'none'
285
+ * .build();
286
+ * ```
109
287
  */
110
288
  normalizeEmptyFields() {
111
289
  Object.keys(this.dto).forEach((key) => {
@@ -117,7 +295,21 @@ class LoggerDtoBuilder {
117
295
  return this;
118
296
  }
119
297
  /**
120
- * Merge additional options into the DTO
298
+ * Merges additional options into the DTO.
299
+ *
300
+ * Takes an optional object of additional fields and merges them into the DTO.
301
+ * Empty string values in the options are normalized to DEFAULT_VALUES.NONE.
302
+ *
303
+ * @param opt - Optional record of additional fields to merge
304
+ * @returns This builder instance for method chaining
305
+ *
306
+ * @example
307
+ * ```typescript
308
+ * const dto = new LoggerDtoBuilder()
309
+ * .setLevel('info')
310
+ * .mergeOptions({ broker: 'kafka', customField: 'value' })
311
+ * .build();
312
+ * ```
121
313
  */
122
314
  mergeOptions(opt) {
123
315
  if (opt) {
@@ -131,6 +323,19 @@ class LoggerDtoBuilder {
131
323
  }
132
324
  return this;
133
325
  }
326
+ /**
327
+ * Builds and returns the final LoggerDto instance.
328
+ *
329
+ * @returns The constructed LoggerDto object
330
+ *
331
+ * @example
332
+ * ```typescript
333
+ * const dto = new LoggerDtoBuilder()
334
+ * .setLevel('info')
335
+ * .setMessage('Test message')
336
+ * .build();
337
+ * ```
338
+ */
134
339
  build() {
135
340
  return this.dto;
136
341
  }
@@ -1 +1 @@
1
- {"version":3,"file":"logger-builder.helper.js","sourceRoot":"","sources":["../../src/helpers/logger-builder.helper.ts"],"names":[],"mappings":";;;AAAA,qDAAiD;AACjD,oEAA+D;AAE/D,MAAa,gBAAgB;IACnB,GAAG,CAAY;IAEvB;QACE,IAAI,CAAC,GAAG,GAAG,IAAI,sBAAS,EAAE,CAAC;IAC7B,CAAC;IAED,QAAQ,CAAC,KAAa;QACpB,IAAI,CAAC,GAAG,CAAC,KAAK,GAAG,KAAK,CAAC;QACvB,OAAO,IAAI,CAAC;IACd,CAAC;IAED,YAAY,CAAC,SAAiB;QAC5B,IAAI,CAAC,GAAG,CAAC,SAAS,GAAG,SAAS,CAAC;QAC/B,OAAO,IAAI,CAAC;IACd,CAAC;IAED,UAAU,CAAC,OAAe;QACxB,IAAI,CAAC,GAAG,CAAC,OAAO,GAAG,OAAO,CAAC;QAC3B,OAAO,IAAI,CAAC;IACd,CAAC;IAED,gBAAgB,CAAC,aAAsB;QACrC,IAAI,aAAa,EAAE,CAAC;YAClB,IAAI,CAAC,GAAG,CAAC,aAAa,GAAG,aAAa,CAAC;QACzC,CAAC;QACD,OAAO,IAAI,CAAC;IACd,CAAC;IAED,SAAS,CAAC,MAAc;QACtB,IAAI,CAAC,GAAG,CAAC,MAAM,GAA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AAC,GAAG,iCAAc,CAAC,IAAI,CAAC;YACtC,CAAC;QACH,CAAC,CAAC,CAAC;QACH,OAAO,IAAI,CAAC;IACd,CAAC;IAED;;OAEG;IACH,YAAY,CAAC,GAA6B;QACxC,IAAI,GAAG,EAAE,CAAC;YACR,MAAM,aAAa,GAAG,EAAE,GAAG,GAAG,EAAE,CAAC;YACjC,MAAM,CAAC,IAAI,CAAC,aAAa,CAAC,CAAC,OAAO,CAAC,CAAC,GAAG,EAAE,EAAE;gBACzC,IAAI,OAAO,aAAa,CAAC,GAAG,CAAC,KAAK,QAAQ,IAAI,aAAa,CAAC,GAAG,CAAC,KAAK,EAAE,EAAE,CAAC;oBACxE,aAAa,CAAC,GAAG,CAAC,GAAG,iCAAc,CAAC,IAAI,CAAC;gBAC3C,CAAC;YACH,CAAC,CAAC,CAAC;YACH,MAAM,CAAC,MAAM,CAAC,IAAI,CAAC,GAAG,EAAE,aAAa,CAAC,CAAC;QACzC,CAAC;QACD,OAAO,IAAI,CAAC;IACd,CAAC;IAED,KAAK;QACH,OAAO,IAAI,CAAC,GAAG,CAAC;IAClB,CAAC;CACF;AA9JD,4CA8JC"}
1
+ {"version":3,"file":"logger-builder.helper.js","sourceRoot":"","sources":["../../src/helpers/logger-builder.helper.ts"],"names":[],"mappings":";;;AAAA,qDAAiD;AACjD,oEAA+D;AAE/D;;;;;;;;;;;;;;;;;;;;GAoBG;AACH,MAAa,gBAAgB;IACnB,GAAG,CAAY;IAEvB;;OAEG;IACH;QACE,IAAI,CAAC,GAAG,GAAG,IAAI,sBAAS,EAAE,CAAC;IAC7B,CAAC;IAED;;;;;OAKG;IACH,QAAQ,CAAC,KAAa;QACpB,IAAI,CAAC,GAAG,CAAC,KAAK,GAAG,KAAK,CAAC;QACvB,OAAO,IAAI,CAAC;IACd,CAAC;IAED;;;;;OAKG;IACH,YAAY,CAAC,SAAiB;QAC5B,IAAI,CAAC,GAAG,CAAC,SAAS,GAAG,SAAS,CAAC;QAC/B,OAAO,IA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