@eqxjs/nest-logger 3.1.0-beta.9 → 3.1.1-beta.0

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 (122) hide show
  1. package/CHANGELOG +57 -1
  2. package/MIGRATION.md +234 -0
  3. package/PERFORMANCE_IMPROVEMENTS.md +158 -0
  4. package/README.md +2008 -16
  5. package/RESTRUCTURING_SUMMARY.md +272 -0
  6. package/STRUCTURE.md +110 -0
  7. package/dist/constants/action-message.constant.d.ts +187 -0
  8. package/dist/constants/action-message.constant.js +220 -0
  9. package/dist/constants/action-message.constant.js.map +1 -0
  10. package/dist/constants/index.d.ts +2 -0
  11. package/dist/constants/index.js +9 -0
  12. package/dist/constants/index.js.map +1 -0
  13. package/dist/constants/logger.constants.d.ts +17 -0
  14. package/dist/constants/logger.constants.js +20 -0
  15. package/dist/constants/logger.constants.js.map +1 -0
  16. package/dist/core/formatters/index.d.ts +1 -0
  17. package/dist/core/formatters/index.js +6 -0
  18. package/dist/core/formatters/index.js.map +1 -0
  19. package/dist/core/formatters/logger.formatter.d.ts +141 -0
  20. package/dist/core/formatters/logger.formatter.js +268 -0
  21. package/dist/core/formatters/logger.formatter.js.map +1 -0
  22. package/dist/core/loggers/app.logger.d.ts +46 -0
  23. package/dist/core/loggers/app.logger.js +92 -0
  24. package/dist/core/loggers/app.logger.js.map +1 -0
  25. package/dist/core/loggers/base-app.logger.d.ts +299 -0
  26. package/dist/core/loggers/base-app.logger.js +517 -0
  27. package/dist/core/loggers/base-app.logger.js.map +1 -0
  28. package/dist/core/loggers/custom.logger.d.ts +127 -0
  29. package/dist/core/loggers/custom.logger.js +260 -0
  30. package/dist/core/loggers/custom.logger.js.map +1 -0
  31. package/dist/core/loggers/index.d.ts +3 -0
  32. package/dist/core/loggers/index.js +10 -0
  33. package/dist/core/loggers/index.js.map +1 -0
  34. package/dist/helpers/datetime.helper.d.ts +24 -0
  35. package/dist/helpers/datetime.helper.js +36 -0
  36. package/dist/helpers/datetime.helper.js.map +1 -0
  37. package/dist/helpers/index.d.ts +5 -0
  38. package/dist/helpers/index.js +17 -0
  39. package/dist/helpers/index.js.map +1 -0
  40. package/dist/helpers/log.helper.d.ts +84 -0
  41. package/dist/helpers/log.helper.js +109 -0
  42. package/dist/helpers/log.helper.js.map +1 -0
  43. package/dist/helpers/logger-builder.helper.d.ts +242 -0
  44. package/dist/helpers/logger-builder.helper.js +345 -0
  45. package/dist/helpers/logger-builder.helper.js.map +1 -0
  46. package/dist/helpers/message-formatter.helper.d.ts +88 -0
  47. package/dist/helpers/message-formatter.helper.js +159 -0
  48. package/dist/helpers/message-formatter.helper.js.map +1 -0
  49. package/dist/helpers/time-performance.helper.d.ts +68 -0
  50. package/dist/helpers/time-performance.helper.js +82 -0
  51. package/dist/helpers/time-performance.helper.js.map +1 -0
  52. package/dist/index.d.ts +13 -5
  53. package/dist/index.js +24 -9
  54. package/dist/index.js.map +1 -1
  55. package/dist/interfaces/data-header.interface.d.ts +21 -0
  56. package/dist/{dto/m2.dto.js → interfaces/data-header.interface.js} +1 -1
  57. package/dist/interfaces/data-header.interface.js.map +1 -0
  58. package/dist/interfaces/data-protocol.interface.d.ts +14 -0
  59. package/dist/interfaces/data-protocol.interface.js +3 -0
  60. package/dist/interfaces/data-protocol.interface.js.map +1 -0
  61. package/dist/interfaces/data-service.interface.d.ts +21 -0
  62. package/dist/{dto/m3.dto.js → interfaces/data-service.interface.js} +1 -1
  63. package/dist/interfaces/data-service.interface.js.map +1 -0
  64. package/dist/{types.d.ts → interfaces/data.interface.d.ts} +4 -4
  65. package/dist/{dto/m1.dto.js → interfaces/data.interface.js} +1 -1
  66. package/dist/interfaces/data.interface.js.map +1 -0
  67. package/dist/interfaces/index.d.ts +5 -0
  68. package/dist/{types.js → interfaces/index.js} +1 -1
  69. package/dist/interfaces/index.js.map +1 -0
  70. package/dist/{dto/header.dto.js → interfaces/logger-opt.interface.js} +1 -1
  71. package/dist/interfaces/logger-opt.interface.js.map +1 -0
  72. package/dist/logger.module.js +4 -4
  73. package/dist/logger.module.js.map +1 -1
  74. package/dist/models/index.d.ts +1 -0
  75. package/dist/models/index.js +6 -0
  76. package/dist/models/index.js.map +1 -0
  77. package/dist/models/logger.dto.d.ts +71 -0
  78. package/dist/models/logger.dto.js +76 -0
  79. package/dist/models/logger.dto.js.map +1 -0
  80. package/package.json +30 -33
  81. package/dist/dto/header.dto.d.ts +0 -21
  82. package/dist/dto/header.dto.js.map +0 -1
  83. package/dist/dto/logger.dto.d.ts +0 -28
  84. package/dist/dto/logger.dto.js +0 -33
  85. package/dist/dto/logger.dto.js.map +0 -1
  86. package/dist/dto/m1.dto.d.ts +0 -7
  87. package/dist/dto/m1.dto.js.map +0 -1
  88. package/dist/dto/m2.dto.d.ts +0 -5
  89. package/dist/dto/m2.dto.js.map +0 -1
  90. package/dist/dto/m3.dto.d.ts +0 -5
  91. package/dist/dto/m3.dto.js.map +0 -1
  92. package/dist/dto/protocol.dto.d.ts +0 -14
  93. package/dist/dto/protocol.dto.js +0 -3
  94. package/dist/dto/protocol.dto.js.map +0 -1
  95. package/dist/dto/service.dto.d.ts +0 -25
  96. package/dist/dto/service.dto.js +0 -3
  97. package/dist/dto/service.dto.js.map +0 -1
  98. package/dist/logger.app.d.ts +0 -62
  99. package/dist/logger.app.js +0 -504
  100. package/dist/logger.app.js.map +0 -1
  101. package/dist/logger.service.d.ts +0 -15
  102. package/dist/logger.service.js +0 -158
  103. package/dist/logger.service.js.map +0 -1
  104. package/dist/logger.util.d.ts +0 -3
  105. package/dist/logger.util.js +0 -28
  106. package/dist/logger.util.js.map +0 -1
  107. package/dist/types.js.map +0 -1
  108. package/dist/utils/action.common.d.ts +0 -14
  109. package/dist/utils/action.common.js +0 -43
  110. package/dist/utils/action.common.js.map +0 -1
  111. package/dist/utils/datetime.util.d.ts +0 -1
  112. package/dist/utils/datetime.util.js +0 -13
  113. package/dist/utils/datetime.util.js.map +0 -1
  114. package/dist/utils/logger.opt.js +0 -3
  115. package/dist/utils/logger.opt.js.map +0 -1
  116. package/dist/utils/m1.utils.d.ts +0 -3
  117. package/dist/utils/m1.utils.js +0 -79
  118. package/dist/utils/m1.utils.js.map +0 -1
  119. package/dist/utils/time.performance.d.ts +0 -6
  120. package/dist/utils/time.performance.js +0 -18
  121. package/dist/utils/time.performance.js.map +0 -1
  122. /package/dist/{utils/logger.opt.d.ts → interfaces/logger-opt.interface.d.ts} +0 -0
@@ -0,0 +1,109 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.isLevelEnable = isLevelEnable;
4
+ exports.maskMessageReplacer = maskMessageReplacer;
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
+ */
30
+ function isLevelEnable(level) {
31
+ const configLevel = process.env.LOG_LEVEL?.split(',') ?? [];
32
+ return configLevel.includes(level);
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
+ */
60
+ function maskMessageReplacer(key, value) {
61
+ const maskConfig = process.env.LOG_MASK_KEYS?.split(',') ?? [];
62
+ if (maskConfig.includes(key)) {
63
+ return '*****';
64
+ }
65
+ return value;
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
+ */
98
+ function logStringify(message) {
99
+ if (typeof message === 'string') {
100
+ return message;
101
+ }
102
+ try {
103
+ return JSON.stringify(message, maskMessageReplacer);
104
+ }
105
+ catch {
106
+ return String(message);
107
+ }
108
+ }
109
+ //# sourceMappingURL=log.helper.js.map
@@ -0,0 +1 @@
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"}
@@ -0,0 +1,242 @@
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
+ */
23
+ export declare class LoggerDtoBuilder {
24
+ private dto;
25
+ /**
26
+ * Creates a new LoggerDtoBuilder instance with an empty LoggerDto.
27
+ */
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
+ */
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
+ */
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
+ */
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
+ */
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
+ */
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
+ */
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
+ */
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
+ */
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
+ */
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
+ */
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
+ */
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
+ */
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
+ */
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
+ */
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
+ */
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
+ */
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
+ */
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
+ */
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
+ */
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
+ */
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
+ */
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
+ */
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
+ */
191
+ setStack(stack?: string[]): this;
192
+ /**
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
+ * ```
208
+ */
209
+ normalizeEmptyFields(): this;
210
+ /**
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
+ * ```
226
+ */
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
+ */
241
+ build(): LoggerDto;
242
+ }
@@ -0,0 +1,345 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.LoggerDtoBuilder = void 0;
4
+ const logger_dto_1 = require("../models/logger.dto");
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
+ */
27
+ class LoggerDtoBuilder {
28
+ dto;
29
+ /**
30
+ * Creates a new LoggerDtoBuilder instance with an empty LoggerDto.
31
+ */
32
+ constructor() {
33
+ this.dto = new logger_dto_1.LoggerDto();
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
+ */
41
+ setLevel(level) {
42
+ this.dto.level = level;
43
+ return this;
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
+ */
51
+ setTimestamp(timestamp) {
52
+ this.dto.timestamp = timestamp;
53
+ return this;
54
+ }
55
+ /**
56
+ * Sets the application name.
57
+ *
58
+ * @param appName - Name of the application
59
+ * @returns This builder instance for method chaining
60
+ */
61
+ setAppName(appName) {
62
+ this.dto.appName = appName;
63
+ return this;
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
+ */
72
+ setComponentName(componentName) {
73
+ if (componentName) {
74
+ this.dto.componentName = componentName;
75
+ }
76
+ return this;
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
+ */
84
+ setAction(action) {
85
+ this.dto.action = action;
86
+ return this;
87
+ }
88
+ /**
89
+ * Sets the log message.
90
+ *
91
+ * @param message - The log message content
92
+ * @returns This builder instance for method chaining
93
+ */
94
+ setMessage(message) {
95
+ this.dto.message = message;
96
+ return this;
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
+ */
104
+ setInstance(instance) {
105
+ this.dto.instance = instance;
106
+ return this;
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
+ */
114
+ setOriginateServiceName(originateServiceName) {
115
+ this.dto.originateServiceName = originateServiceName;
116
+ return this;
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
+ */
124
+ setRecordName(recordName) {
125
+ this.dto.recordName = recordName;
126
+ return this;
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
+ */
134
+ setRecordType(recordType) {
135
+ this.dto.recordType = recordType;
136
+ return this;
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
+ */
144
+ setSessionId(sessionId) {
145
+ this.dto.sessionId = sessionId;
146
+ return this;
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
+ */
154
+ setTransactionId(transactionId) {
155
+ this.dto.transactionId = transactionId;
156
+ return this;
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
+ */
164
+ setChannel(channel) {
165
+ this.dto.channel = channel;
166
+ return this;
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
+ */
174
+ setComponentVersion(componentVersion) {
175
+ this.dto.componentVersion = componentVersion;
176
+ return this;
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
+ */
184
+ setUseCase(useCase) {
185
+ this.dto.useCase = useCase;
186
+ return this;
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
+ */
194
+ setUseCaseStep(useCaseStep) {
195
+ this.dto.useCaseStep = useCaseStep;
196
+ return this;
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
+ */
204
+ setUser(user) {
205
+ this.dto.user = user;
206
+ return this;
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
+ */
214
+ setDevice(device) {
215
+ this.dto.device = device;
216
+ return this;
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
+ */
224
+ setPublic(public_) {
225
+ this.dto.public = public_;
226
+ return this;
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
+ */
234
+ setAppResult(appResult) {
235
+ this.dto.appResult = appResult;
236
+ return this;
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
+ */
244
+ setAppResultCode(appResultCode) {
245
+ this.dto.appResultCode = appResultCode;
246
+ return this;
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
+ */
254
+ setServiceTime(serviceTime) {
255
+ this.dto.serviceTime = serviceTime;
256
+ return this;
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
+ */
265
+ setStack(stack) {
266
+ if (stack) {
267
+ this.dto.stack = stack;
268
+ }
269
+ return this;
270
+ }
271
+ /**
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
+ * ```
287
+ */
288
+ normalizeEmptyFields() {
289
+ Object.keys(this.dto).forEach((key) => {
290
+ const value = this.dto[key];
291
+ if (typeof value === 'string' && value === '') {
292
+ this.dto[key] = logger_constants_1.DEFAULT_VALUES.NONE;
293
+ }
294
+ });
295
+ return this;
296
+ }
297
+ /**
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
+ * ```
313
+ */
314
+ mergeOptions(opt) {
315
+ if (opt) {
316
+ const normalizedOpt = { ...opt };
317
+ Object.keys(normalizedOpt).forEach((key) => {
318
+ if (typeof normalizedOpt[key] === 'string' &&
319
+ normalizedOpt[key] === '') {
320
+ normalizedOpt[key] = logger_constants_1.DEFAULT_VALUES.NONE;
321
+ }
322
+ });
323
+ Object.assign(this.dto, normalizedOpt);
324
+ }
325
+ return this;
326
+ }
327
+ /**
328
+ * Builds and returns the final LoggerDto instance.
329
+ *
330
+ * @returns The constructed LoggerDto object
331
+ *
332
+ * @example
333
+ * ```typescript
334
+ * const dto = new LoggerDtoBuilder()
335
+ * .setLevel('info')
336
+ * .setMessage('Test message')
337
+ * .build();
338
+ * ```
339
+ */
340
+ build() {
341
+ return this.dto;
342
+ }
343
+ }
344
+ exports.LoggerDtoBuilder = LoggerDtoBuilder;
345
+ //# sourceMappingURL=logger-builder.helper.js.map