@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/config.js
CHANGED
|
@@ -19,18 +19,18 @@ class LoggerConfigManager {
|
|
|
19
19
|
};
|
|
20
20
|
}
|
|
21
21
|
/**
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
22
|
+
* Get current configuration
|
|
23
|
+
* @returns Current logger configuration
|
|
24
|
+
*/
|
|
25
25
|
getConfig() {
|
|
26
26
|
return { ...this.config };
|
|
27
27
|
}
|
|
28
28
|
/**
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
29
|
+
* Updates logger configuration with new settings
|
|
30
|
+
* Merges provided config with existing settings (partial update)
|
|
31
|
+
* Supports backwards compatibility by mapping level to mode with deprecation warnings
|
|
32
|
+
* @param config - Partial configuration object to apply
|
|
33
|
+
*/
|
|
34
34
|
updateConfig(config) {
|
|
35
35
|
// Handle backwards compatibility - if level is provided but mode is not
|
|
36
36
|
if (config.level !== undefined && config.mode === undefined) {
|
|
@@ -40,6 +40,7 @@ class LoggerConfigManager {
|
|
|
40
40
|
// Normal configuration update
|
|
41
41
|
// If mode is present, remove legacy level property to avoid conflicts
|
|
42
42
|
if (config.mode !== undefined && config.level !== undefined) {
|
|
43
|
+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
43
44
|
const { level, ...configWithoutLevel } = config;
|
|
44
45
|
this.config = { ...this.config, ...configWithoutLevel };
|
|
45
46
|
}
|
|
@@ -49,9 +50,9 @@ class LoggerConfigManager {
|
|
|
49
50
|
}
|
|
50
51
|
}
|
|
51
52
|
/**
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
53
|
+
* Handle legacy level-based configuration with deprecation warnings
|
|
54
|
+
* @param config - Configuration containing legacy level property
|
|
55
|
+
*/
|
|
55
56
|
handleLegacyLevelConfig(config) {
|
|
56
57
|
// Map legacy level values to new LogMode values and validate first
|
|
57
58
|
const levelValue = config.level;
|
|
@@ -66,34 +67,36 @@ class LoggerConfigManager {
|
|
|
66
67
|
}
|
|
67
68
|
// Merge existing config with all keys from the passed config, and override mode with mapped value
|
|
68
69
|
// Remove the legacy 'level' property to avoid conflicts with the new 'mode' property
|
|
70
|
+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
69
71
|
const { level, ...configWithoutLevel } = config;
|
|
70
72
|
this.config = { ...this.config, ...configWithoutLevel, mode: mappedMode };
|
|
71
73
|
}
|
|
72
74
|
/**
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
75
|
+
* Map legacy LogLevel values to LogMode values
|
|
76
|
+
* @param levelValue - Legacy level value
|
|
77
|
+
* @returns Corresponding LogMode or undefined if invalid
|
|
78
|
+
*/
|
|
77
79
|
mapLevelToMode(levelValue) {
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
80
|
+
// Use switch statement to avoid object injection
|
|
81
|
+
switch (levelValue) {
|
|
82
|
+
case types_1.LogLevel.DEBUG: return types_1.LogMode.DEBUG; // 0 -> 0
|
|
83
|
+
case types_1.LogLevel.INFO: return types_1.LogMode.INFO; // 1 -> 1
|
|
84
|
+
case types_1.LogLevel.WARN: return types_1.LogMode.WARN; // 2 -> 2
|
|
85
|
+
case types_1.LogLevel.ERROR: return types_1.LogMode.ERROR; // 3 -> 3
|
|
86
|
+
case types_1.LogLevel.LOG: return types_1.LogMode.SILENT; // 99 -> 4 (preserves critical-only behavior)
|
|
87
|
+
case 4: return types_1.LogMode.SILENT; // Legacy SILENT -> 4
|
|
88
|
+
case 5: return types_1.LogMode.OFF; // Legacy OFF -> 5
|
|
89
|
+
default: return undefined;
|
|
90
|
+
}
|
|
88
91
|
}
|
|
89
92
|
/**
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
+
* Create deprecation warning message using LogFormatter
|
|
94
|
+
* Outputs formatted deprecation warning messages to console
|
|
95
|
+
*/
|
|
93
96
|
createDeprecationWarning() {
|
|
94
97
|
// Import LogFormatter to format system messages properly
|
|
95
98
|
const { LogFormatter } = require('../formatter');
|
|
96
|
-
console.warn(LogFormatter.formatSystemMessage('⚠️ DEPRECATION WARNING: The "level" configuration is deprecated and will be removed in
|
|
99
|
+
console.warn(LogFormatter.formatSystemMessage('⚠️ DEPRECATION WARNING: The "level" configuration is deprecated and will be removed in v3.0.0. Please use "mode" instead.'));
|
|
97
100
|
console.warn(LogFormatter.formatSystemMessage(' Migration: LogEngine.configure({ level: LogLevel.DEBUG }) → LogEngine.configure({ mode: LogMode.DEBUG })'));
|
|
98
101
|
console.warn(LogFormatter.formatSystemMessage(' See: https://github.com/wgtechlabs/log-engine#migration-guide-loglevel--logmode'));
|
|
99
102
|
}
|
package/dist/logger/core.d.ts
CHANGED
|
@@ -5,7 +5,7 @@
|
|
|
5
5
|
* Uses colorized console output with timestamps for better readability
|
|
6
6
|
* Includes automatic data redaction for sensitive information
|
|
7
7
|
*/
|
|
8
|
-
import { LoggerConfig } from '../types';
|
|
8
|
+
import { LoggerConfig, LogData } from '../types';
|
|
9
9
|
/**
|
|
10
10
|
* Logger class responsible for managing log output and configuration
|
|
11
11
|
* Provides mode-based filtering and formatted console output
|
|
@@ -13,96 +13,140 @@ import { LoggerConfig } from '../types';
|
|
|
13
13
|
export declare class Logger {
|
|
14
14
|
private configManager;
|
|
15
15
|
/**
|
|
16
|
-
|
|
17
|
-
|
|
16
|
+
* Logger constructor - sets up environment-based auto-configuration
|
|
17
|
+
*/
|
|
18
18
|
constructor();
|
|
19
19
|
/**
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
20
|
+
* Built-in output handlers for common use cases
|
|
21
|
+
*/
|
|
22
|
+
private getBuiltInHandler;
|
|
23
|
+
/**
|
|
24
|
+
* Process a single output target with error handling
|
|
25
|
+
* @param output - Single output target to process
|
|
26
|
+
* @param level - Log level
|
|
27
|
+
* @param rawMessage - Original unformatted message
|
|
28
|
+
* @param formattedMessage - Formatted message for console-based outputs
|
|
29
|
+
* @param data - Optional data
|
|
30
|
+
* @param isEnhanced - Whether this is an enhanced output (supports configured handler objects)
|
|
31
|
+
*/
|
|
32
|
+
private processSingleOutput;
|
|
33
|
+
/**
|
|
34
|
+
* Process multiple output targets
|
|
35
|
+
* @param outputs - Array of output targets to process
|
|
36
|
+
* @param level - Log level
|
|
37
|
+
* @param rawMessage - Original unformatted message
|
|
38
|
+
* @param formattedMessage - Formatted message for console-based outputs
|
|
39
|
+
* @param data - Optional data
|
|
40
|
+
*/
|
|
41
|
+
private processOutputs;
|
|
42
|
+
/**
|
|
43
|
+
* Process enhanced output targets
|
|
44
|
+
* @param enhancedOutputs - Array of enhanced output targets to process
|
|
45
|
+
* @param level - Log level
|
|
46
|
+
* @param rawMessage - Original unformatted message
|
|
47
|
+
* @param formattedMessage - Formatted message for console-based outputs
|
|
48
|
+
* @param data - Optional data
|
|
49
|
+
*/
|
|
50
|
+
private processEnhancedOutputs;
|
|
51
|
+
/**
|
|
52
|
+
* Updates logger configuration with new settings
|
|
53
|
+
* Also updates redaction configuration based on environment
|
|
54
|
+
* @param config - Partial configuration object to apply
|
|
55
|
+
*/
|
|
24
56
|
configure(config: Partial<LoggerConfig>): void;
|
|
25
57
|
/**
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
58
|
+
* Get current logger configuration
|
|
59
|
+
* @returns Current logger configuration
|
|
60
|
+
*/
|
|
29
61
|
getConfig(): LoggerConfig;
|
|
30
62
|
/**
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
63
|
+
* Determines if a message should be logged based on current log mode
|
|
64
|
+
* @param level - The log level of the message to check
|
|
65
|
+
* @returns true if message should be logged, false otherwise
|
|
66
|
+
*/
|
|
35
67
|
private shouldLog;
|
|
36
68
|
/**
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
/**
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
/**
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
/**
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
69
|
+
* Writes log output using configured output handler or default console methods
|
|
70
|
+
* Supports single output handler, multiple outputs, and enhanced outputs
|
|
71
|
+
* Priority: outputs > enhancedOutputs > outputHandler > default console
|
|
72
|
+
* @param level - The log level as a string
|
|
73
|
+
* @param rawMessage - The original unformatted message
|
|
74
|
+
* @param formattedMessage - The pre-formatted message to output
|
|
75
|
+
* @param data - Optional data object that was logged
|
|
76
|
+
* @param isError - Whether this is an error level message (for console.error)
|
|
77
|
+
* @param isWarn - Whether this is a warning level message (for console.warn)
|
|
78
|
+
*/
|
|
79
|
+
private writeToOutput;
|
|
80
|
+
/**
|
|
81
|
+
* Log a debug message with DEBUG level formatting
|
|
82
|
+
* Uses console.log for output with purple/magenta coloring
|
|
83
|
+
* Automatically redacts sensitive data when provided
|
|
84
|
+
* @param message - The debug message to log
|
|
85
|
+
* @param data - Optional data object to log (will be redacted)
|
|
86
|
+
*/
|
|
87
|
+
debug(message: string, data?: LogData): void;
|
|
88
|
+
/**
|
|
89
|
+
* Log an informational message with INFO level formatting
|
|
90
|
+
* Uses console.log for output with blue coloring
|
|
91
|
+
* Automatically redacts sensitive data when provided
|
|
92
|
+
* @param message - The info message to log
|
|
93
|
+
* @param data - Optional data object to log (will be redacted)
|
|
94
|
+
*/
|
|
95
|
+
info(message: string, data?: LogData): void;
|
|
96
|
+
/**
|
|
97
|
+
* Log a warning message with WARN level formatting
|
|
98
|
+
* Uses console.warn for output with yellow coloring
|
|
99
|
+
* Automatically redacts sensitive data when provided
|
|
100
|
+
* @param message - The warning message to log
|
|
101
|
+
* @param data - Optional data object to log (will be redacted)
|
|
102
|
+
*/
|
|
103
|
+
warn(message: string, data?: LogData): void;
|
|
104
|
+
/**
|
|
105
|
+
* Log an error message with ERROR level formatting
|
|
106
|
+
* Uses console.error for output with red coloring
|
|
107
|
+
* Automatically redacts sensitive data when provided
|
|
108
|
+
* @param message - The error message to log
|
|
109
|
+
* @param data - Optional data object to log (will be redacted)
|
|
110
|
+
*/
|
|
111
|
+
error(message: string, data?: LogData): void;
|
|
112
|
+
/**
|
|
113
|
+
* Log a message with LOG level formatting (always outputs unless mode is OFF)
|
|
114
|
+
* Uses console.log for output with green coloring
|
|
115
|
+
* LOG level bypasses normal filtering and always outputs (except when OFF is set)
|
|
116
|
+
* Automatically redacts sensitive data when provided
|
|
117
|
+
* @param message - The log message to output
|
|
118
|
+
* @param data - Optional data object to log (will be redacted)
|
|
119
|
+
*/
|
|
120
|
+
log(message: string, data?: LogData): void;
|
|
121
|
+
/**
|
|
122
|
+
* Log a debug message without data redaction
|
|
123
|
+
* @param message - The debug message to log
|
|
124
|
+
* @param data - Optional data object to log (no redaction applied)
|
|
125
|
+
*/
|
|
126
|
+
debugRaw(message: string, data?: LogData): void;
|
|
127
|
+
/**
|
|
128
|
+
* Log an info message without data redaction
|
|
129
|
+
* @param message - The info message to log
|
|
130
|
+
* @param data - Optional data object to log (no redaction applied)
|
|
131
|
+
*/
|
|
132
|
+
infoRaw(message: string, data?: LogData): void;
|
|
133
|
+
/**
|
|
134
|
+
* Log a warning message without data redaction
|
|
135
|
+
* @param message - The warning message to log
|
|
136
|
+
* @param data - Optional data object to log (no redaction applied)
|
|
137
|
+
*/
|
|
138
|
+
warnRaw(message: string, data?: LogData): void;
|
|
139
|
+
/**
|
|
140
|
+
* Log an error message without data redaction
|
|
141
|
+
* @param message - The error message to log
|
|
142
|
+
* @param data - Optional data object to log (no redaction applied)
|
|
143
|
+
*/
|
|
144
|
+
errorRaw(message: string, data?: LogData): void;
|
|
145
|
+
/**
|
|
146
|
+
* Log a message without data redaction (always outputs unless mode is OFF)
|
|
147
|
+
* @param message - The log message to output
|
|
148
|
+
* @param data - Optional data object to log (no redaction applied)
|
|
149
|
+
*/
|
|
150
|
+
logRaw(message: string, data?: LogData): void;
|
|
107
151
|
}
|
|
108
152
|
//# sourceMappingURL=core.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"core.d.ts","sourceRoot":"","sources":["../../src/logger/core.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,OAAO,EAAqB,YAAY,EAAE,MAAM,UAAU,CAAC;
|
|
1
|
+
{"version":3,"file":"core.d.ts","sourceRoot":"","sources":["../../src/logger/core.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,OAAO,EAAqB,YAAY,EAAwD,OAAO,EAAE,MAAM,UAAU,CAAC;AAO1H;;;GAGG;AACH,qBAAa,MAAM;IACjB,OAAO,CAAC,aAAa,CAAsB;IAE3C;;SAEK;;IAKL;;SAEK;IAEL,OAAO,CAAC,iBAAiB;IAsCzB;;;;;;;;SAQK;IACL,OAAO,CAAC,mBAAmB;IA6C3B;;;;;;;SAOK;IACL,OAAO,CAAC,cAAc;IAMtB;;;;;;;SAOK;IACL,OAAO,CAAC,sBAAsB;IAM9B;;;;SAIK;IACL,SAAS,CAAC,MAAM,EAAE,OAAO,CAAC,YAAY,CAAC,GAAG,IAAI;IAU9C;;;SAGK;IACL,SAAS,IAAI,YAAY;IAIzB;;;;SAIK;IACL,OAAO,CAAC,SAAS;IAMjB;;;;;;;;;;SAUK;IACL,OAAO,CAAC,aAAa;IAkDrB;;;;;;SAMK;IACL,KAAK,CAAC,OAAO,EAAE,MAAM,EAAE,IAAI,CAAC,EAAE,OAAO,GAAG,IAAI;IAQ5C;;;;;;SAMK;IACL,IAAI,CAAC,OAAO,EAAE,MAAM,EAAE,IAAI,CAAC,EAAE,OAAO,GAAG,IAAI;IAQ3C;;;;;;SAMK;IACL,IAAI,CAAC,OAAO,EAAE,MAAM,EAAE,IAAI,CAAC,EAAE,OAAO,GAAG,IAAI;IAQ3C;;;;;;SAMK;IACL,KAAK,CAAC,OAAO,EAAE,MAAM,EAAE,IAAI,CAAC,EAAE,OAAO,GAAG,IAAI;IAQ5C;;;;;;;SAOK;IACL,GAAG,CAAC,OAAO,EAAE,MAAM,EAAE,IAAI,CAAC,EAAE,OAAO,GAAG,IAAI;IAS1C;;;;SAIK;IACL,QAAQ,CAAC,OAAO,EAAE,MAAM,EAAE,IAAI,CAAC,EAAE,OAAO,GAAG,IAAI;IAO/C;;;;SAIK;IACL,OAAO,CAAC,OAAO,EAAE,MAAM,EAAE,IAAI,CAAC,EAAE,OAAO,GAAG,IAAI;IAO9C;;;;SAIK;IACL,OAAO,CAAC,OAAO,EAAE,MAAM,EAAE,IAAI,CAAC,EAAE,OAAO,GAAG,IAAI;IAO9C;;;;SAIK;IACL,QAAQ,CAAC,OAAO,EAAE,MAAM,EAAE,IAAI,CAAC,EAAE,OAAO,GAAG,IAAI;IAO/C;;;;SAIK;IACL,MAAM,CAAC,OAAO,EAAE,MAAM,EAAE,IAAI,CAAC,EAAE,OAAO,GAAG,IAAI;CAM9C"}
|