@wgtechlabs/log-engine 1.3.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 -661
- 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 -63
- package/dist/formatter.d.ts +0 -49
- package/dist/formatter.d.ts.map +0 -1
- package/dist/formatter.js +0 -140
- package/dist/logger.d.ts +0 -128
- package/dist/logger.d.ts.map +0 -1
- package/dist/logger.js +0 -265
package/dist/logger.d.ts.map
DELETED
|
@@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AKG;IACH,OAAO,CAAC,OAAO,EAAE,MAAM,EAAE,IAAI,CAAC,EAAE,GAAG,GAAG,IAAI;IAO1C;;;;;OAKG;IACH,QAAQ,CAAC,OAAO,EAAE,MAAM,EAAE,IAAI,CAAC,EAAE,GAAG,GAAG,IAAI;IAO3C;;;;;OAKG;IACH,MAAM,CAAC,OAAO,EAAE,MAAM,EAAE,IAAI,CAAC,EAAE,GAAG,GAAG,IAAI;CAM5C"}
|
package/dist/logger.js
DELETED
|
@@ -1,265 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
/**
|
|
3
|
-
* Core Logger class that handles log message output with configurable levels
|
|
4
|
-
* Supports DEBUG, INFO, WARN, ERROR, and LOG levels with intelligent filtering
|
|
5
|
-
* LOG level always outputs regardless of configuration
|
|
6
|
-
* Uses colorized console output with timestamps for better readability
|
|
7
|
-
* Includes automatic data redaction for sensitive information
|
|
8
|
-
*/
|
|
9
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
10
|
-
exports.Logger = void 0;
|
|
11
|
-
const types_1 = require("./types");
|
|
12
|
-
const formatter_1 = require("./formatter");
|
|
13
|
-
const redaction_1 = require("./redaction");
|
|
14
|
-
/**
|
|
15
|
-
* Logger class responsible for managing log output and configuration
|
|
16
|
-
* Provides mode-based filtering and formatted console output
|
|
17
|
-
*/
|
|
18
|
-
class Logger {
|
|
19
|
-
/**
|
|
20
|
-
* Logger constructor - sets up environment-based auto-configuration
|
|
21
|
-
*/
|
|
22
|
-
constructor() {
|
|
23
|
-
// Internal configuration state with sensible defaults
|
|
24
|
-
this.config = {
|
|
25
|
-
mode: types_1.LogMode.INFO
|
|
26
|
-
};
|
|
27
|
-
// Set initial mode based on NODE_ENV for auto-configuration
|
|
28
|
-
this.config.mode = this.getEnvironmentMode();
|
|
29
|
-
}
|
|
30
|
-
/**
|
|
31
|
-
* Determines the appropriate log mode based on NODE_ENV
|
|
32
|
-
* @returns LogMode appropriate for current environment
|
|
33
|
-
*/
|
|
34
|
-
getEnvironmentMode() {
|
|
35
|
-
const nodeEnv = process.env.NODE_ENV;
|
|
36
|
-
switch (nodeEnv) {
|
|
37
|
-
case 'development':
|
|
38
|
-
return types_1.LogMode.DEBUG; // Verbose logging for development
|
|
39
|
-
case 'production':
|
|
40
|
-
return types_1.LogMode.INFO; // Important info and above for production
|
|
41
|
-
case 'staging':
|
|
42
|
-
return types_1.LogMode.WARN; // Focused logging for staging
|
|
43
|
-
case 'test':
|
|
44
|
-
return types_1.LogMode.ERROR; // Minimal logging during tests
|
|
45
|
-
default:
|
|
46
|
-
return types_1.LogMode.INFO; // Default fallback for unknown environments
|
|
47
|
-
}
|
|
48
|
-
}
|
|
49
|
-
/**
|
|
50
|
-
* Updates logger configuration with new settings
|
|
51
|
-
* Merges provided config with existing settings (partial update)
|
|
52
|
-
* Supports backwards compatibility by mapping level to mode with deprecation warnings
|
|
53
|
-
* Also updates redaction configuration based on environment
|
|
54
|
-
* @param config - Partial configuration object to apply
|
|
55
|
-
*/
|
|
56
|
-
configure(config) {
|
|
57
|
-
// Handle backwards compatibility - if level is provided but mode is not
|
|
58
|
-
if (config.level !== undefined && config.mode === undefined) {
|
|
59
|
-
// Only show deprecation warning in non-test environments
|
|
60
|
-
if (process.env.NODE_ENV !== 'test') {
|
|
61
|
-
console.warn(formatter_1.LogFormatter.formatSystemMessage('⚠️ DEPRECATION WARNING: The "level" configuration is deprecated and will be removed in v2.0.0. Please use "mode" instead.'));
|
|
62
|
-
console.warn(formatter_1.LogFormatter.formatSystemMessage(' Migration: LogEngine.configure({ level: LogLevel.DEBUG }) → LogEngine.configure({ mode: LogMode.DEBUG })'));
|
|
63
|
-
console.warn(formatter_1.LogFormatter.formatSystemMessage(' See: https://github.com/wgtechlabs/log-engine#migration-guide-loglevel--logmode'));
|
|
64
|
-
}
|
|
65
|
-
// Map legacy level values to new LogMode values (including SILENT=4, OFF=5)
|
|
66
|
-
// This provides backwards compatibility for all legacy values
|
|
67
|
-
const levelValue = config.level;
|
|
68
|
-
const levelToModeMap = {
|
|
69
|
-
[types_1.LogLevel.DEBUG]: types_1.LogMode.DEBUG, // 0 -> 0
|
|
70
|
-
[types_1.LogLevel.INFO]: types_1.LogMode.INFO, // 1 -> 1
|
|
71
|
-
[types_1.LogLevel.WARN]: types_1.LogMode.WARN, // 2 -> 2
|
|
72
|
-
[types_1.LogLevel.ERROR]: types_1.LogMode.ERROR, // 3 -> 3
|
|
73
|
-
[types_1.LogLevel.LOG]: types_1.LogMode.SILENT, // 99 -> 4 (preserves critical-only behavior)
|
|
74
|
-
4: types_1.LogMode.SILENT, // Legacy SILENT -> 4
|
|
75
|
-
5: types_1.LogMode.OFF // Legacy OFF -> 5
|
|
76
|
-
};
|
|
77
|
-
const mappedMode = levelToModeMap[levelValue];
|
|
78
|
-
if (mappedMode === undefined) {
|
|
79
|
-
throw new Error(`Invalid LogLevel value: ${config.level}. Valid values are: DEBUG(0), INFO(1), WARN(2), ERROR(3), LOG(99), or use LogMode instead.`);
|
|
80
|
-
}
|
|
81
|
-
this.config = { ...this.config, mode: mappedMode };
|
|
82
|
-
}
|
|
83
|
-
else {
|
|
84
|
-
// Normal configuration update
|
|
85
|
-
this.config = { ...this.config, ...config };
|
|
86
|
-
}
|
|
87
|
-
// Update redaction configuration based on current environment
|
|
88
|
-
redaction_1.DataRedactor.updateConfig({
|
|
89
|
-
...redaction_1.defaultRedactionConfig,
|
|
90
|
-
...redaction_1.RedactionController.getEnvironmentConfig()
|
|
91
|
-
});
|
|
92
|
-
}
|
|
93
|
-
/**
|
|
94
|
-
* Determines if a message should be logged based on current log mode
|
|
95
|
-
* Messages are shown only if their level is appropriate for the configured mode
|
|
96
|
-
* LOG level is special - it always outputs regardless of configured mode (except when OFF is set)
|
|
97
|
-
* OFF mode disables all logging including LOG level messages
|
|
98
|
-
* @param level - The log level of the message to check
|
|
99
|
-
* @returns true if message should be logged, false otherwise
|
|
100
|
-
*/
|
|
101
|
-
shouldLog(level) {
|
|
102
|
-
const currentMode = this.config.mode !== undefined ? this.config.mode : types_1.LogMode.INFO;
|
|
103
|
-
// Get the severity rank for the message level
|
|
104
|
-
const messageSeverity = Logger.SEVERITY_RANKS[level];
|
|
105
|
-
// Get the minimum severity threshold for the current mode
|
|
106
|
-
const modeThreshold = Logger.MODE_THRESHOLDS[currentMode];
|
|
107
|
-
// Allow the message if its severity meets or exceeds the mode threshold
|
|
108
|
-
return messageSeverity >= modeThreshold;
|
|
109
|
-
}
|
|
110
|
-
/**
|
|
111
|
-
* Log a debug message with DEBUG level formatting
|
|
112
|
-
* Uses console.log for output with purple/magenta coloring
|
|
113
|
-
* Automatically redacts sensitive data when provided
|
|
114
|
-
* @param message - The debug message to log
|
|
115
|
-
* @param data - Optional data object to log (will be redacted)
|
|
116
|
-
*/
|
|
117
|
-
debug(message, data) {
|
|
118
|
-
if (this.shouldLog(types_1.LogLevel.DEBUG)) {
|
|
119
|
-
const processedData = redaction_1.DataRedactor.redactData(data);
|
|
120
|
-
const formatted = formatter_1.LogFormatter.format(types_1.LogLevel.DEBUG, message, processedData);
|
|
121
|
-
console.log(formatted);
|
|
122
|
-
}
|
|
123
|
-
}
|
|
124
|
-
/**
|
|
125
|
-
* Log an informational message with INFO level formatting
|
|
126
|
-
* Uses console.log for output with blue coloring
|
|
127
|
-
* Automatically redacts sensitive data when provided
|
|
128
|
-
* @param message - The info message to log
|
|
129
|
-
* @param data - Optional data object to log (will be redacted)
|
|
130
|
-
*/
|
|
131
|
-
info(message, data) {
|
|
132
|
-
if (this.shouldLog(types_1.LogLevel.INFO)) {
|
|
133
|
-
const processedData = redaction_1.DataRedactor.redactData(data);
|
|
134
|
-
const formatted = formatter_1.LogFormatter.format(types_1.LogLevel.INFO, message, processedData);
|
|
135
|
-
console.log(formatted);
|
|
136
|
-
}
|
|
137
|
-
}
|
|
138
|
-
/**
|
|
139
|
-
* Log a warning message with WARN level formatting
|
|
140
|
-
* Uses console.warn for output with yellow coloring
|
|
141
|
-
* Automatically redacts sensitive data when provided
|
|
142
|
-
* @param message - The warning message to log
|
|
143
|
-
* @param data - Optional data object to log (will be redacted)
|
|
144
|
-
*/
|
|
145
|
-
warn(message, data) {
|
|
146
|
-
if (this.shouldLog(types_1.LogLevel.WARN)) {
|
|
147
|
-
const processedData = redaction_1.DataRedactor.redactData(data);
|
|
148
|
-
const formatted = formatter_1.LogFormatter.format(types_1.LogLevel.WARN, message, processedData);
|
|
149
|
-
console.warn(formatted);
|
|
150
|
-
}
|
|
151
|
-
}
|
|
152
|
-
/**
|
|
153
|
-
* Log an error message with ERROR level formatting
|
|
154
|
-
* Uses console.error for output with red coloring
|
|
155
|
-
* Automatically redacts sensitive data when provided
|
|
156
|
-
* @param message - The error message to log
|
|
157
|
-
* @param data - Optional data object to log (will be redacted)
|
|
158
|
-
*/
|
|
159
|
-
error(message, data) {
|
|
160
|
-
if (this.shouldLog(types_1.LogLevel.ERROR)) {
|
|
161
|
-
const processedData = redaction_1.DataRedactor.redactData(data);
|
|
162
|
-
const formatted = formatter_1.LogFormatter.format(types_1.LogLevel.ERROR, message, processedData);
|
|
163
|
-
console.error(formatted);
|
|
164
|
-
}
|
|
165
|
-
}
|
|
166
|
-
/**
|
|
167
|
-
* Log a critical message that always outputs (LOG level)
|
|
168
|
-
* Uses console.log for output with green coloring
|
|
169
|
-
* Always shown regardless of configured log level
|
|
170
|
-
* Automatically redacts sensitive data when provided
|
|
171
|
-
* @param message - The critical log message to log
|
|
172
|
-
* @param data - Optional data object to log (will be redacted)
|
|
173
|
-
*/
|
|
174
|
-
log(message, data) {
|
|
175
|
-
if (this.shouldLog(types_1.LogLevel.LOG)) {
|
|
176
|
-
const processedData = redaction_1.DataRedactor.redactData(data);
|
|
177
|
-
const formatted = formatter_1.LogFormatter.format(types_1.LogLevel.LOG, message, processedData);
|
|
178
|
-
console.log(formatted);
|
|
179
|
-
}
|
|
180
|
-
}
|
|
181
|
-
/**
|
|
182
|
-
* Log a debug message without redaction (use with caution)
|
|
183
|
-
* Bypasses automatic data redaction for debugging purposes
|
|
184
|
-
* @param message - The debug message to log
|
|
185
|
-
* @param data - Optional data object to log (no redaction applied)
|
|
186
|
-
*/
|
|
187
|
-
debugRaw(message, data) {
|
|
188
|
-
if (this.shouldLog(types_1.LogLevel.DEBUG)) {
|
|
189
|
-
const formatted = formatter_1.LogFormatter.format(types_1.LogLevel.DEBUG, message, data);
|
|
190
|
-
console.log(formatted);
|
|
191
|
-
}
|
|
192
|
-
}
|
|
193
|
-
/**
|
|
194
|
-
* Log an info message without redaction (use with caution)
|
|
195
|
-
* Bypasses automatic data redaction for debugging purposes
|
|
196
|
-
* @param message - The info message to log
|
|
197
|
-
* @param data - Optional data object to log (no redaction applied)
|
|
198
|
-
*/
|
|
199
|
-
infoRaw(message, data) {
|
|
200
|
-
if (this.shouldLog(types_1.LogLevel.INFO)) {
|
|
201
|
-
const formatted = formatter_1.LogFormatter.format(types_1.LogLevel.INFO, message, data);
|
|
202
|
-
console.log(formatted);
|
|
203
|
-
}
|
|
204
|
-
}
|
|
205
|
-
/**
|
|
206
|
-
* Log a warning message without redaction (use with caution)
|
|
207
|
-
* Bypasses automatic data redaction for debugging purposes
|
|
208
|
-
* @param message - The warning message to log
|
|
209
|
-
* @param data - Optional data object to log (no redaction applied)
|
|
210
|
-
*/
|
|
211
|
-
warnRaw(message, data) {
|
|
212
|
-
if (this.shouldLog(types_1.LogLevel.WARN)) {
|
|
213
|
-
const formatted = formatter_1.LogFormatter.format(types_1.LogLevel.WARN, message, data);
|
|
214
|
-
console.warn(formatted);
|
|
215
|
-
}
|
|
216
|
-
}
|
|
217
|
-
/**
|
|
218
|
-
* Log an error message without redaction (use with caution)
|
|
219
|
-
* Bypasses automatic data redaction for debugging purposes
|
|
220
|
-
* @param message - The error message to log
|
|
221
|
-
* @param data - Optional data object to log (no redaction applied)
|
|
222
|
-
*/
|
|
223
|
-
errorRaw(message, data) {
|
|
224
|
-
if (this.shouldLog(types_1.LogLevel.ERROR)) {
|
|
225
|
-
const formatted = formatter_1.LogFormatter.format(types_1.LogLevel.ERROR, message, data);
|
|
226
|
-
console.error(formatted);
|
|
227
|
-
}
|
|
228
|
-
}
|
|
229
|
-
/**
|
|
230
|
-
* Log a critical message without redaction (use with caution)
|
|
231
|
-
* Bypasses automatic data redaction for debugging purposes
|
|
232
|
-
* @param message - The critical log message to log
|
|
233
|
-
* @param data - Optional data object to log (no redaction applied)
|
|
234
|
-
*/
|
|
235
|
-
logRaw(message, data) {
|
|
236
|
-
if (this.shouldLog(types_1.LogLevel.LOG)) {
|
|
237
|
-
const formatted = formatter_1.LogFormatter.format(types_1.LogLevel.LOG, message, data);
|
|
238
|
-
console.log(formatted);
|
|
239
|
-
}
|
|
240
|
-
}
|
|
241
|
-
}
|
|
242
|
-
exports.Logger = Logger;
|
|
243
|
-
/**
|
|
244
|
-
* Maps LogLevel values to severity ranks for consistent comparison
|
|
245
|
-
* This prevents issues if enum numeric values change in the future
|
|
246
|
-
*/
|
|
247
|
-
Logger.SEVERITY_RANKS = {
|
|
248
|
-
[types_1.LogLevel.DEBUG]: 0,
|
|
249
|
-
[types_1.LogLevel.INFO]: 1,
|
|
250
|
-
[types_1.LogLevel.WARN]: 2,
|
|
251
|
-
[types_1.LogLevel.ERROR]: 3,
|
|
252
|
-
[types_1.LogLevel.LOG]: 99 // Special case - always outputs (except when OFF)
|
|
253
|
-
};
|
|
254
|
-
/**
|
|
255
|
-
* Maps LogMode values to minimum severity rank required for output
|
|
256
|
-
* This defines the filtering threshold for each mode
|
|
257
|
-
*/
|
|
258
|
-
Logger.MODE_THRESHOLDS = {
|
|
259
|
-
[types_1.LogMode.DEBUG]: 0, // Shows DEBUG and above
|
|
260
|
-
[types_1.LogMode.INFO]: 1, // Shows INFO and above
|
|
261
|
-
[types_1.LogMode.WARN]: 2, // Shows WARN and above
|
|
262
|
-
[types_1.LogMode.ERROR]: 3, // Shows ERROR and above
|
|
263
|
-
[types_1.LogMode.SILENT]: 99, // Only shows LOG messages
|
|
264
|
-
[types_1.LogMode.OFF]: 100 // Shows nothing
|
|
265
|
-
};
|