@wgtechlabs/log-engine 2.0.0 → 2.1.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.
- package/LICENSE +21 -21
- package/README.md +869 -608
- package/dist/formatter/data-formatter.d.ts +2 -1
- package/dist/formatter/data-formatter.d.ts.map +1 -1
- package/dist/formatter/data-formatter.js +1 -1
- package/dist/formatter/message-formatter.d.ts +23 -23
- package/dist/formatter/message-formatter.d.ts.map +1 -1
- package/dist/formatter/message-formatter.js +23 -23
- package/dist/formatter/timestamp.d.ts.map +1 -1
- package/dist/index.d.ts +130 -136
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +108 -108
- package/dist/logger/advanced-outputs.d.ts +159 -0
- package/dist/logger/advanced-outputs.d.ts.map +1 -0
- package/dist/logger/advanced-outputs.js +586 -0
- package/dist/logger/config.d.ts +18 -18
- package/dist/logger/config.d.ts.map +1 -1
- package/dist/logger/config.js +32 -29
- package/dist/logger/core.d.ts +128 -84
- package/dist/logger/core.d.ts.map +1 -1
- package/dist/logger/core.js +259 -74
- package/dist/logger/environment.d.ts +15 -15
- package/dist/logger/environment.d.ts.map +1 -1
- package/dist/logger/environment.js +15 -15
- package/dist/logger/filtering.d.ts +16 -16
- package/dist/logger/filtering.d.ts.map +1 -1
- package/dist/logger/filtering.js +37 -22
- package/dist/redaction/config.d.ts +8 -8
- package/dist/redaction/config.d.ts.map +1 -1
- package/dist/redaction/config.js +8 -8
- package/dist/redaction/redactor.d.ts +60 -60
- package/dist/redaction/redactor.d.ts.map +1 -1
- package/dist/redaction/redactor.js +101 -96
- package/dist/types/index.d.ts +98 -16
- package/dist/types/index.d.ts.map +1 -1
- package/package.json +80 -68
package/dist/logger/core.js
CHANGED
|
@@ -13,22 +13,146 @@ const formatter_1 = require("../formatter");
|
|
|
13
13
|
const redaction_1 = require("../redaction");
|
|
14
14
|
const config_1 = require("./config");
|
|
15
15
|
const filtering_1 = require("./filtering");
|
|
16
|
+
const advanced_outputs_1 = require("./advanced-outputs");
|
|
16
17
|
/**
|
|
17
18
|
* Logger class responsible for managing log output and configuration
|
|
18
19
|
* Provides mode-based filtering and formatted console output
|
|
19
20
|
*/
|
|
20
21
|
class Logger {
|
|
21
22
|
/**
|
|
22
|
-
|
|
23
|
-
|
|
23
|
+
* Logger constructor - sets up environment-based auto-configuration
|
|
24
|
+
*/
|
|
24
25
|
constructor() {
|
|
25
26
|
this.configManager = new config_1.LoggerConfigManager();
|
|
26
27
|
}
|
|
27
28
|
/**
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
29
|
+
* Built-in output handlers for common use cases
|
|
30
|
+
*/
|
|
31
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
32
|
+
getBuiltInHandler(type, config) {
|
|
33
|
+
switch (type) {
|
|
34
|
+
case 'console':
|
|
35
|
+
return (level, message, data) => {
|
|
36
|
+
// Use appropriate console method based on level
|
|
37
|
+
if (level === 'error') {
|
|
38
|
+
if (data !== undefined) {
|
|
39
|
+
console.error(message, data);
|
|
40
|
+
}
|
|
41
|
+
else {
|
|
42
|
+
console.error(message);
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
else if (level === 'warn') {
|
|
46
|
+
if (data !== undefined) {
|
|
47
|
+
console.warn(message, data);
|
|
48
|
+
}
|
|
49
|
+
else {
|
|
50
|
+
console.warn(message);
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
else {
|
|
54
|
+
if (data !== undefined) {
|
|
55
|
+
console.log(message, data);
|
|
56
|
+
}
|
|
57
|
+
else {
|
|
58
|
+
console.log(message);
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
};
|
|
62
|
+
case 'silent':
|
|
63
|
+
return () => {
|
|
64
|
+
// Do nothing - silent output
|
|
65
|
+
};
|
|
66
|
+
case 'file':
|
|
67
|
+
case 'http':
|
|
68
|
+
// Use advanced output handlers for file and http
|
|
69
|
+
return (0, advanced_outputs_1.createBuiltInHandler)(type, config);
|
|
70
|
+
default:
|
|
71
|
+
return null;
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
/**
|
|
75
|
+
* Process a single output target with error handling
|
|
76
|
+
* @param output - Single output target to process
|
|
77
|
+
* @param level - Log level
|
|
78
|
+
* @param rawMessage - Original unformatted message
|
|
79
|
+
* @param formattedMessage - Formatted message for console-based outputs
|
|
80
|
+
* @param data - Optional data
|
|
81
|
+
* @param isEnhanced - Whether this is an enhanced output (supports configured handler objects)
|
|
82
|
+
*/
|
|
83
|
+
processSingleOutput(output, level, rawMessage, formattedMessage, data, isEnhanced = false) {
|
|
84
|
+
const config = this.configManager.getConfig();
|
|
85
|
+
try {
|
|
86
|
+
if (typeof output === 'string') {
|
|
87
|
+
// Built-in handler - get config if available
|
|
88
|
+
const outputConfig = config.advancedOutputConfig?.[output];
|
|
89
|
+
const handler = this.getBuiltInHandler(output, outputConfig);
|
|
90
|
+
if (handler) {
|
|
91
|
+
// Advanced handlers (file, http) get raw message, console gets formatted
|
|
92
|
+
const messageToUse = (output === 'file' || output === 'http') ? rawMessage : formattedMessage;
|
|
93
|
+
handler(level, messageToUse, data);
|
|
94
|
+
}
|
|
95
|
+
else {
|
|
96
|
+
console.error('[LogEngine] Unknown built-in output handler:', JSON.stringify(output));
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
else if (typeof output === 'function') {
|
|
100
|
+
// Custom function handler gets formatted message for backward compatibility
|
|
101
|
+
output(level, formattedMessage, data);
|
|
102
|
+
}
|
|
103
|
+
else if (isEnhanced && typeof output === 'object' && output.type && output.config) {
|
|
104
|
+
// Configured handler object (only available for enhanced outputs)
|
|
105
|
+
const handler = this.getBuiltInHandler(output.type, output.config);
|
|
106
|
+
if (handler) {
|
|
107
|
+
// Advanced configured handlers get raw message
|
|
108
|
+
handler(level, rawMessage, data);
|
|
109
|
+
}
|
|
110
|
+
else {
|
|
111
|
+
console.error('[LogEngine] Unknown enhanced output handler type:', JSON.stringify(output));
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
else {
|
|
115
|
+
const outputType = isEnhanced ? 'enhanced output target' : 'output target';
|
|
116
|
+
console.error(`[LogEngine] Invalid ${outputType}:`, output);
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
catch (error) {
|
|
120
|
+
// Continue processing other outputs even if one fails
|
|
121
|
+
const handlerType = isEnhanced ? 'Enhanced output' : 'Output';
|
|
122
|
+
console.error(`[LogEngine] ${handlerType} handler failed: ${error}`);
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
/**
|
|
126
|
+
* Process multiple output targets
|
|
127
|
+
* @param outputs - Array of output targets to process
|
|
128
|
+
* @param level - Log level
|
|
129
|
+
* @param rawMessage - Original unformatted message
|
|
130
|
+
* @param formattedMessage - Formatted message for console-based outputs
|
|
131
|
+
* @param data - Optional data
|
|
132
|
+
*/
|
|
133
|
+
processOutputs(outputs, level, rawMessage, formattedMessage, data) {
|
|
134
|
+
for (const output of outputs) {
|
|
135
|
+
this.processSingleOutput(output, level, rawMessage, formattedMessage, data, false);
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
/**
|
|
139
|
+
* Process enhanced output targets
|
|
140
|
+
* @param enhancedOutputs - Array of enhanced output targets to process
|
|
141
|
+
* @param level - Log level
|
|
142
|
+
* @param rawMessage - Original unformatted message
|
|
143
|
+
* @param formattedMessage - Formatted message for console-based outputs
|
|
144
|
+
* @param data - Optional data
|
|
145
|
+
*/
|
|
146
|
+
processEnhancedOutputs(enhancedOutputs, level, rawMessage, formattedMessage, data) {
|
|
147
|
+
for (const output of enhancedOutputs) {
|
|
148
|
+
this.processSingleOutput(output, level, rawMessage, formattedMessage, data, true);
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
/**
|
|
152
|
+
* Updates logger configuration with new settings
|
|
153
|
+
* Also updates redaction configuration based on environment
|
|
154
|
+
* @param config - Partial configuration object to apply
|
|
155
|
+
*/
|
|
32
156
|
configure(config) {
|
|
33
157
|
this.configManager.updateConfig(config);
|
|
34
158
|
// Update redaction configuration based on current environment
|
|
@@ -38,147 +162,208 @@ class Logger {
|
|
|
38
162
|
});
|
|
39
163
|
}
|
|
40
164
|
/**
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
165
|
+
* Get current logger configuration
|
|
166
|
+
* @returns Current logger configuration
|
|
167
|
+
*/
|
|
44
168
|
getConfig() {
|
|
45
169
|
return this.configManager.getConfig();
|
|
46
170
|
}
|
|
47
171
|
/**
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
172
|
+
* Determines if a message should be logged based on current log mode
|
|
173
|
+
* @param level - The log level of the message to check
|
|
174
|
+
* @returns true if message should be logged, false otherwise
|
|
175
|
+
*/
|
|
52
176
|
shouldLog(level) {
|
|
53
177
|
const currentConfig = this.configManager.getConfig();
|
|
54
178
|
const currentMode = currentConfig.mode !== undefined ? currentConfig.mode : types_1.LogMode.INFO;
|
|
55
179
|
return filtering_1.LogFilter.shouldLog(level, currentMode);
|
|
56
180
|
}
|
|
57
181
|
/**
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
182
|
+
* Writes log output using configured output handler or default console methods
|
|
183
|
+
* Supports single output handler, multiple outputs, and enhanced outputs
|
|
184
|
+
* Priority: outputs > enhancedOutputs > outputHandler > default console
|
|
185
|
+
* @param level - The log level as a string
|
|
186
|
+
* @param rawMessage - The original unformatted message
|
|
187
|
+
* @param formattedMessage - The pre-formatted message to output
|
|
188
|
+
* @param data - Optional data object that was logged
|
|
189
|
+
* @param isError - Whether this is an error level message (for console.error)
|
|
190
|
+
* @param isWarn - Whether this is a warning level message (for console.warn)
|
|
191
|
+
*/
|
|
192
|
+
writeToOutput(level, rawMessage, formattedMessage, data, isError = false, isWarn = false) {
|
|
193
|
+
const config = this.configManager.getConfig();
|
|
194
|
+
// Multiple outputs support (highest priority - newer API)
|
|
195
|
+
if (config.outputs !== undefined) {
|
|
196
|
+
if (config.outputs.length > 0) {
|
|
197
|
+
// Process outputs array when it has actual outputs
|
|
198
|
+
this.processOutputs(config.outputs, level, rawMessage, formattedMessage, data);
|
|
199
|
+
}
|
|
200
|
+
// If outputs is explicitly set to empty array, disable all logging
|
|
201
|
+
return;
|
|
202
|
+
}
|
|
203
|
+
// Enhanced outputs with advanced configuration (second priority)
|
|
204
|
+
if (config.enhancedOutputs !== undefined && config.enhancedOutputs.length > 0) {
|
|
205
|
+
this.processEnhancedOutputs(config.enhancedOutputs, level, rawMessage, formattedMessage, data);
|
|
206
|
+
return;
|
|
207
|
+
}
|
|
208
|
+
// Single output handler (third priority - legacy compatibility)
|
|
209
|
+
if (config.outputHandler) {
|
|
210
|
+
try {
|
|
211
|
+
config.outputHandler(level, formattedMessage, data);
|
|
212
|
+
}
|
|
213
|
+
catch (error) {
|
|
214
|
+
// Fallback to console if custom handler fails
|
|
215
|
+
console.error(`[LogEngine] Output handler failed: ${error}. Falling back to console.`);
|
|
216
|
+
if (isError) {
|
|
217
|
+
console.error(formattedMessage);
|
|
218
|
+
}
|
|
219
|
+
else if (isWarn) {
|
|
220
|
+
console.warn(formattedMessage);
|
|
221
|
+
}
|
|
222
|
+
else {
|
|
223
|
+
console.log(formattedMessage);
|
|
224
|
+
}
|
|
225
|
+
}
|
|
226
|
+
return;
|
|
227
|
+
}
|
|
228
|
+
// Default: Console output (unless suppressed)
|
|
229
|
+
if (!config.suppressConsoleOutput) {
|
|
230
|
+
if (isError) {
|
|
231
|
+
console.error(formattedMessage);
|
|
232
|
+
}
|
|
233
|
+
else if (isWarn) {
|
|
234
|
+
console.warn(formattedMessage);
|
|
235
|
+
}
|
|
236
|
+
else {
|
|
237
|
+
console.log(formattedMessage);
|
|
238
|
+
}
|
|
239
|
+
}
|
|
240
|
+
// If suppressConsoleOutput is true and no outputHandler/outputs, do nothing (silent)
|
|
241
|
+
}
|
|
242
|
+
/**
|
|
243
|
+
* Log a debug message with DEBUG level formatting
|
|
244
|
+
* Uses console.log for output with purple/magenta coloring
|
|
245
|
+
* Automatically redacts sensitive data when provided
|
|
246
|
+
* @param message - The debug message to log
|
|
247
|
+
* @param data - Optional data object to log (will be redacted)
|
|
248
|
+
*/
|
|
64
249
|
debug(message, data) {
|
|
65
250
|
if (this.shouldLog(types_1.LogLevel.DEBUG)) {
|
|
66
251
|
const processedData = redaction_1.DataRedactor.redactData(data);
|
|
67
252
|
const formatted = formatter_1.LogFormatter.format(types_1.LogLevel.DEBUG, message, processedData);
|
|
68
|
-
|
|
253
|
+
this.writeToOutput('debug', message, formatted, processedData);
|
|
69
254
|
}
|
|
70
255
|
}
|
|
71
256
|
/**
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
257
|
+
* Log an informational message with INFO level formatting
|
|
258
|
+
* Uses console.log for output with blue coloring
|
|
259
|
+
* Automatically redacts sensitive data when provided
|
|
260
|
+
* @param message - The info message to log
|
|
261
|
+
* @param data - Optional data object to log (will be redacted)
|
|
262
|
+
*/
|
|
78
263
|
info(message, data) {
|
|
79
264
|
if (this.shouldLog(types_1.LogLevel.INFO)) {
|
|
80
265
|
const processedData = redaction_1.DataRedactor.redactData(data);
|
|
81
266
|
const formatted = formatter_1.LogFormatter.format(types_1.LogLevel.INFO, message, processedData);
|
|
82
|
-
|
|
267
|
+
this.writeToOutput('info', message, formatted, processedData);
|
|
83
268
|
}
|
|
84
269
|
}
|
|
85
270
|
/**
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
271
|
+
* Log a warning message with WARN level formatting
|
|
272
|
+
* Uses console.warn for output with yellow coloring
|
|
273
|
+
* Automatically redacts sensitive data when provided
|
|
274
|
+
* @param message - The warning message to log
|
|
275
|
+
* @param data - Optional data object to log (will be redacted)
|
|
276
|
+
*/
|
|
92
277
|
warn(message, data) {
|
|
93
278
|
if (this.shouldLog(types_1.LogLevel.WARN)) {
|
|
94
279
|
const processedData = redaction_1.DataRedactor.redactData(data);
|
|
95
280
|
const formatted = formatter_1.LogFormatter.format(types_1.LogLevel.WARN, message, processedData);
|
|
96
|
-
|
|
281
|
+
this.writeToOutput('warn', message, formatted, processedData, false, true);
|
|
97
282
|
}
|
|
98
283
|
}
|
|
99
284
|
/**
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
285
|
+
* Log an error message with ERROR level formatting
|
|
286
|
+
* Uses console.error for output with red coloring
|
|
287
|
+
* Automatically redacts sensitive data when provided
|
|
288
|
+
* @param message - The error message to log
|
|
289
|
+
* @param data - Optional data object to log (will be redacted)
|
|
290
|
+
*/
|
|
106
291
|
error(message, data) {
|
|
107
292
|
if (this.shouldLog(types_1.LogLevel.ERROR)) {
|
|
108
293
|
const processedData = redaction_1.DataRedactor.redactData(data);
|
|
109
294
|
const formatted = formatter_1.LogFormatter.format(types_1.LogLevel.ERROR, message, processedData);
|
|
110
|
-
|
|
295
|
+
this.writeToOutput('error', message, formatted, processedData, true, false);
|
|
111
296
|
}
|
|
112
297
|
}
|
|
113
298
|
/**
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
299
|
+
* Log a message with LOG level formatting (always outputs unless mode is OFF)
|
|
300
|
+
* Uses console.log for output with green coloring
|
|
301
|
+
* LOG level bypasses normal filtering and always outputs (except when OFF is set)
|
|
302
|
+
* Automatically redacts sensitive data when provided
|
|
303
|
+
* @param message - The log message to output
|
|
304
|
+
* @param data - Optional data object to log (will be redacted)
|
|
305
|
+
*/
|
|
121
306
|
log(message, data) {
|
|
122
307
|
if (this.shouldLog(types_1.LogLevel.LOG)) {
|
|
123
308
|
const processedData = redaction_1.DataRedactor.redactData(data);
|
|
124
309
|
const formatted = formatter_1.LogFormatter.format(types_1.LogLevel.LOG, message, processedData);
|
|
125
|
-
|
|
310
|
+
this.writeToOutput('log', message, formatted, processedData);
|
|
126
311
|
}
|
|
127
312
|
}
|
|
128
313
|
// Raw logging methods (bypass redaction for debugging)
|
|
129
314
|
/**
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
315
|
+
* Log a debug message without data redaction
|
|
316
|
+
* @param message - The debug message to log
|
|
317
|
+
* @param data - Optional data object to log (no redaction applied)
|
|
318
|
+
*/
|
|
134
319
|
debugRaw(message, data) {
|
|
135
320
|
if (this.shouldLog(types_1.LogLevel.DEBUG)) {
|
|
136
321
|
const formatted = formatter_1.LogFormatter.format(types_1.LogLevel.DEBUG, message, data);
|
|
137
|
-
|
|
322
|
+
this.writeToOutput('debug', message, formatted, data);
|
|
138
323
|
}
|
|
139
324
|
}
|
|
140
325
|
/**
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
326
|
+
* Log an info message without data redaction
|
|
327
|
+
* @param message - The info message to log
|
|
328
|
+
* @param data - Optional data object to log (no redaction applied)
|
|
329
|
+
*/
|
|
145
330
|
infoRaw(message, data) {
|
|
146
331
|
if (this.shouldLog(types_1.LogLevel.INFO)) {
|
|
147
332
|
const formatted = formatter_1.LogFormatter.format(types_1.LogLevel.INFO, message, data);
|
|
148
|
-
|
|
333
|
+
this.writeToOutput('info', message, formatted, data);
|
|
149
334
|
}
|
|
150
335
|
}
|
|
151
336
|
/**
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
337
|
+
* Log a warning message without data redaction
|
|
338
|
+
* @param message - The warning message to log
|
|
339
|
+
* @param data - Optional data object to log (no redaction applied)
|
|
340
|
+
*/
|
|
156
341
|
warnRaw(message, data) {
|
|
157
342
|
if (this.shouldLog(types_1.LogLevel.WARN)) {
|
|
158
343
|
const formatted = formatter_1.LogFormatter.format(types_1.LogLevel.WARN, message, data);
|
|
159
|
-
|
|
344
|
+
this.writeToOutput('warn', message, formatted, data, false, true);
|
|
160
345
|
}
|
|
161
346
|
}
|
|
162
347
|
/**
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
348
|
+
* Log an error message without data redaction
|
|
349
|
+
* @param message - The error message to log
|
|
350
|
+
* @param data - Optional data object to log (no redaction applied)
|
|
351
|
+
*/
|
|
167
352
|
errorRaw(message, data) {
|
|
168
353
|
if (this.shouldLog(types_1.LogLevel.ERROR)) {
|
|
169
354
|
const formatted = formatter_1.LogFormatter.format(types_1.LogLevel.ERROR, message, data);
|
|
170
|
-
|
|
355
|
+
this.writeToOutput('error', message, formatted, data, true, false);
|
|
171
356
|
}
|
|
172
357
|
}
|
|
173
358
|
/**
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
359
|
+
* Log a message without data redaction (always outputs unless mode is OFF)
|
|
360
|
+
* @param message - The log message to output
|
|
361
|
+
* @param data - Optional data object to log (no redaction applied)
|
|
362
|
+
*/
|
|
178
363
|
logRaw(message, data) {
|
|
179
364
|
if (this.shouldLog(types_1.LogLevel.LOG)) {
|
|
180
365
|
const formatted = formatter_1.LogFormatter.format(types_1.LogLevel.LOG, message, data);
|
|
181
|
-
|
|
366
|
+
this.writeToOutput('log', message, formatted, data);
|
|
182
367
|
}
|
|
183
368
|
}
|
|
184
369
|
}
|
|
@@ -8,29 +8,29 @@ import { LogMode } from '../types';
|
|
|
8
8
|
*/
|
|
9
9
|
export declare class EnvironmentDetector {
|
|
10
10
|
/**
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
11
|
+
* Get the normalized NODE_ENV value
|
|
12
|
+
* @returns Normalized NODE_ENV (trimmed and lowercase)
|
|
13
|
+
*/
|
|
14
14
|
private static getNormalizedNodeEnv;
|
|
15
15
|
/**
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
16
|
+
* Determines the appropriate log mode based on NODE_ENV
|
|
17
|
+
* @returns LogMode appropriate for current environment
|
|
18
|
+
*/
|
|
19
19
|
static getEnvironmentMode(): LogMode;
|
|
20
20
|
/**
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
21
|
+
* Check if we're in a test environment
|
|
22
|
+
* @returns true if NODE_ENV is 'test'
|
|
23
|
+
*/
|
|
24
24
|
static isTestEnvironment(): boolean;
|
|
25
25
|
/**
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
26
|
+
* Check if we're in a development environment
|
|
27
|
+
* @returns true if NODE_ENV is 'development'
|
|
28
|
+
*/
|
|
29
29
|
static isDevelopmentEnvironment(): boolean;
|
|
30
30
|
/**
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
31
|
+
* Check if we're in a production environment
|
|
32
|
+
* @returns true if NODE_ENV is 'production'
|
|
33
|
+
*/
|
|
34
34
|
static isProductionEnvironment(): boolean;
|
|
35
35
|
}
|
|
36
36
|
//# sourceMappingURL=environment.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"environment.d.ts","sourceRoot":"","sources":["../../src/logger/environment.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EAAE,OAAO,EAAE,MAAM,UAAU,CAAC;AAEnC;;GAEG;AACH,qBAAa,mBAAmB;
|
|
1
|
+
{"version":3,"file":"environment.d.ts","sourceRoot":"","sources":["../../src/logger/environment.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EAAE,OAAO,EAAE,MAAM,UAAU,CAAC;AAEnC;;GAEG;AACH,qBAAa,mBAAmB;IAC9B;;;SAGK;IACL,OAAO,CAAC,MAAM,CAAC,oBAAoB;IAInC;;;SAGK;IACL,MAAM,CAAC,kBAAkB,IAAI,OAAO;IAiBpC;;;SAGK;IACL,MAAM,CAAC,iBAAiB,IAAI,OAAO;IAInC;;;SAGK;IACL,MAAM,CAAC,wBAAwB,IAAI,OAAO;IAI1C;;;SAGK;IACL,MAAM,CAAC,uBAAuB,IAAI,OAAO;CAG1C"}
|
|
@@ -11,16 +11,16 @@ const types_1 = require("../types");
|
|
|
11
11
|
*/
|
|
12
12
|
class EnvironmentDetector {
|
|
13
13
|
/**
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
14
|
+
* Get the normalized NODE_ENV value
|
|
15
|
+
* @returns Normalized NODE_ENV (trimmed and lowercase)
|
|
16
|
+
*/
|
|
17
17
|
static getNormalizedNodeEnv() {
|
|
18
18
|
return (process.env.NODE_ENV || '').trim().toLowerCase();
|
|
19
19
|
}
|
|
20
20
|
/**
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
21
|
+
* Determines the appropriate log mode based on NODE_ENV
|
|
22
|
+
* @returns LogMode appropriate for current environment
|
|
23
|
+
*/
|
|
24
24
|
static getEnvironmentMode() {
|
|
25
25
|
const nodeEnv = EnvironmentDetector.getNormalizedNodeEnv();
|
|
26
26
|
switch (nodeEnv) {
|
|
@@ -37,23 +37,23 @@ class EnvironmentDetector {
|
|
|
37
37
|
}
|
|
38
38
|
}
|
|
39
39
|
/**
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
40
|
+
* Check if we're in a test environment
|
|
41
|
+
* @returns true if NODE_ENV is 'test'
|
|
42
|
+
*/
|
|
43
43
|
static isTestEnvironment() {
|
|
44
44
|
return EnvironmentDetector.getNormalizedNodeEnv() === 'test';
|
|
45
45
|
}
|
|
46
46
|
/**
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
47
|
+
* Check if we're in a development environment
|
|
48
|
+
* @returns true if NODE_ENV is 'development'
|
|
49
|
+
*/
|
|
50
50
|
static isDevelopmentEnvironment() {
|
|
51
51
|
return EnvironmentDetector.getNormalizedNodeEnv() === 'development';
|
|
52
52
|
}
|
|
53
53
|
/**
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
54
|
+
* Check if we're in a production environment
|
|
55
|
+
* @returns true if NODE_ENV is 'production'
|
|
56
|
+
*/
|
|
57
57
|
static isProductionEnvironment() {
|
|
58
58
|
return EnvironmentDetector.getNormalizedNodeEnv() === 'production';
|
|
59
59
|
}
|
|
@@ -11,26 +11,26 @@ export declare class LogFilter {
|
|
|
11
11
|
private static readonly SEVERITY_RANKS;
|
|
12
12
|
private static readonly MODE_THRESHOLDS;
|
|
13
13
|
/**
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
14
|
+
* Determines if a message should be logged based on current log mode
|
|
15
|
+
* Messages are shown only if their level is appropriate for the configured mode
|
|
16
|
+
* LOG level is special - it always outputs regardless of configured mode (except when OFF is set)
|
|
17
|
+
* OFF mode disables all logging including LOG level messages
|
|
18
|
+
* @param level - The log level of the message to check
|
|
19
|
+
* @param currentMode - The current logging mode
|
|
20
|
+
* @returns true if message should be logged, false otherwise
|
|
21
|
+
*/
|
|
22
22
|
static shouldLog(level: LogLevel, currentMode: LogMode): boolean;
|
|
23
23
|
/**
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
24
|
+
* Get the severity rank for a log level
|
|
25
|
+
* @param level - The log level to get rank for
|
|
26
|
+
* @returns Numeric severity rank
|
|
27
|
+
*/
|
|
28
28
|
static getSeverityRank(level: LogLevel): number;
|
|
29
29
|
/**
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
30
|
+
* Get the threshold for a log mode
|
|
31
|
+
* @param mode - The log mode to get threshold for
|
|
32
|
+
* @returns Numeric threshold value
|
|
33
|
+
*/
|
|
34
34
|
static getModeThreshold(mode: LogMode): number;
|
|
35
35
|
}
|
|
36
36
|
//# sourceMappingURL=filtering.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"filtering.d.ts","sourceRoot":"","sources":["../../src/logger/filtering.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EAAE,QAAQ,EAAE,OAAO,EAAE,MAAM,UAAU,CAAC;AAE7C;;;GAGG;AACH,qBAAa,SAAS;
|
|
1
|
+
{"version":3,"file":"filtering.d.ts","sourceRoot":"","sources":["../../src/logger/filtering.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EAAE,QAAQ,EAAE,OAAO,EAAE,MAAM,UAAU,CAAC;AAE7C;;;GAGG;AACH,qBAAa,SAAS;IAEpB,OAAO,CAAC,MAAM,CAAC,QAAQ,CAAC,cAAc,CAMpC;IAGF,OAAO,CAAC,MAAM,CAAC,QAAQ,CAAC,eAAe,CAOrC;IAEF;;;;;;;;SAQK;IACL,MAAM,CAAC,SAAS,CAAC,KAAK,EAAE,QAAQ,EAAE,WAAW,EAAE,OAAO,GAAG,OAAO;IAWhE;;;;SAIK;IACL,MAAM,CAAC,eAAe,CAAC,KAAK,EAAE,QAAQ,GAAG,MAAM;IAW/C;;;;SAIK;IACL,MAAM,CAAC,gBAAgB,CAAC,IAAI,EAAE,OAAO,GAAG,MAAM;CAW/C"}
|