@wgtechlabs/log-engine 1.2.1 → 2.0.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 +279 -14
- package/dist/formatter/colors.d.ts +32 -0
- package/dist/formatter/colors.d.ts.map +1 -0
- package/dist/formatter/colors.js +34 -0
- package/dist/formatter/data-formatter.d.ts +25 -0
- package/dist/formatter/data-formatter.d.ts.map +1 -0
- package/dist/formatter/data-formatter.js +53 -0
- package/dist/formatter/index.d.ts +10 -0
- package/dist/formatter/index.d.ts.map +1 -0
- package/dist/formatter/index.js +21 -0
- package/dist/{formatter.d.ts → formatter/message-formatter.d.ts} +10 -10
- package/dist/formatter/message-formatter.d.ts.map +1 -0
- package/dist/formatter/message-formatter.js +87 -0
- package/dist/formatter/timestamp.d.ts +27 -0
- package/dist/formatter/timestamp.d.ts.map +1 -0
- package/dist/formatter/timestamp.js +39 -0
- package/dist/index.d.ts +143 -41
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +155 -71
- package/dist/logger/config.d.ts +42 -0
- package/dist/logger/config.d.ts.map +1 -0
- package/dist/logger/config.js +101 -0
- package/dist/logger/core.d.ts +108 -0
- package/dist/logger/core.d.ts.map +1 -0
- package/dist/logger/core.js +185 -0
- package/dist/logger/environment.d.ts +36 -0
- package/dist/logger/environment.d.ts.map +1 -0
- package/dist/logger/environment.js +61 -0
- package/dist/logger/filtering.d.ts +36 -0
- package/dist/logger/filtering.d.ts.map +1 -0
- package/dist/logger/filtering.js +65 -0
- package/dist/logger/index.d.ts +10 -0
- package/dist/logger/index.d.ts.map +1 -0
- package/dist/logger/index.js +18 -0
- package/dist/redaction/config.d.ts +29 -0
- package/dist/redaction/config.d.ts.map +1 -0
- package/dist/redaction/config.js +95 -0
- package/dist/redaction/index.d.ts +8 -0
- package/dist/redaction/index.d.ts.map +1 -0
- package/dist/redaction/index.js +12 -0
- package/dist/redaction/redactor.d.ts +99 -0
- package/dist/redaction/redactor.d.ts.map +1 -0
- package/dist/redaction/redactor.js +257 -0
- package/dist/types/index.d.ts +164 -0
- package/dist/types/index.d.ts.map +1 -1
- package/package.json +17 -5
- package/dist/formatter.d.ts.map +0 -1
- package/dist/formatter.js +0 -103
- package/dist/logger.d.ts +0 -72
- package/dist/logger.d.ts.map +0 -1
- package/dist/logger.js +0 -158
package/dist/index.js
CHANGED
|
@@ -1,117 +1,201 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
/**
|
|
3
|
-
* Main
|
|
4
|
-
*
|
|
3
|
+
* Main LogEngine module - provides a comprehensive logging solution
|
|
4
|
+
* with mode-based filtering, colorized output, and automatic data redaction
|
|
5
|
+
*
|
|
6
|
+
* Features a modular architecture with separate modules for:
|
|
7
|
+
* - Logger: Core logging functionality with environment-based configuration
|
|
8
|
+
* - Formatter: Message formatting with ANSI colors and timestamps
|
|
9
|
+
* - Redaction: Automatic sensitive data protection with customizable patterns
|
|
10
|
+
*
|
|
11
|
+
* @example
|
|
12
|
+
* ```typescript
|
|
13
|
+
* import { LogEngine, LogMode } from '@wgtechlabs/log-engine';
|
|
14
|
+
*
|
|
15
|
+
* // Configure logging mode
|
|
16
|
+
* LogEngine.configure({ mode: LogMode.DEBUG });
|
|
17
|
+
*
|
|
18
|
+
* // Log with automatic redaction
|
|
19
|
+
* LogEngine.info('User login', { username: 'john', password: 'secret123' });
|
|
20
|
+
* // Output: [2025-06-18T...][3:45PM][INFO]: User login { username: 'john', password: '[REDACTED]' }
|
|
21
|
+
* ```
|
|
5
22
|
*/
|
|
6
23
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
7
|
-
exports.
|
|
24
|
+
exports.RedactionController = exports.defaultRedactionConfig = exports.DataRedactor = exports.LogLevel = exports.LogMode = exports.LogEngine = void 0;
|
|
8
25
|
const logger_1 = require("./logger");
|
|
9
|
-
const
|
|
10
|
-
// Create singleton logger instance
|
|
26
|
+
const redaction_1 = require("./redaction");
|
|
27
|
+
// Create a singleton logger instance
|
|
11
28
|
const logger = new logger_1.Logger();
|
|
12
29
|
/**
|
|
13
|
-
*
|
|
14
|
-
*
|
|
15
|
-
* - production: INFO (balanced - shows info, warn, error, log)
|
|
16
|
-
* - staging: WARN (focused - shows warn, error, log only)
|
|
17
|
-
* - test: ERROR (minimal - shows error and log only)
|
|
18
|
-
* - default: INFO (balanced logging for other environments)
|
|
19
|
-
* @returns The appropriate LogMode for the current environment
|
|
20
|
-
*/
|
|
21
|
-
const getDefaultLogMode = () => {
|
|
22
|
-
const nodeEnv = process.env.NODE_ENV;
|
|
23
|
-
switch (nodeEnv) {
|
|
24
|
-
case 'development':
|
|
25
|
-
return types_1.LogMode.DEBUG;
|
|
26
|
-
case 'production':
|
|
27
|
-
return types_1.LogMode.INFO;
|
|
28
|
-
case 'staging':
|
|
29
|
-
return types_1.LogMode.WARN;
|
|
30
|
-
case 'test':
|
|
31
|
-
return types_1.LogMode.ERROR;
|
|
32
|
-
default:
|
|
33
|
-
return types_1.LogMode.INFO;
|
|
34
|
-
}
|
|
35
|
-
};
|
|
36
|
-
// Initialize logger with environment-appropriate default mode
|
|
37
|
-
logger.configure({ mode: getDefaultLogMode() });
|
|
38
|
-
/**
|
|
39
|
-
* Main LogEngine API - provides all logging functionality with a clean interface
|
|
40
|
-
* Auto-configured based on NODE_ENV, but can be reconfigured at runtime
|
|
30
|
+
* LogEngine - The main interface for logging operations
|
|
31
|
+
* Provides a simple, intuitive API for all logging needs with security-first design
|
|
41
32
|
*/
|
|
42
33
|
exports.LogEngine = {
|
|
43
34
|
/**
|
|
44
|
-
* Configure the logger with
|
|
45
|
-
* @param config -
|
|
35
|
+
* Configure the logger with new settings
|
|
36
|
+
* @param config - Configuration object containing logger settings
|
|
46
37
|
* @example
|
|
47
38
|
* ```typescript
|
|
48
|
-
* LogEngine.configure({
|
|
49
|
-
* LogEngine.configure({ level: LogLevel.WARN, environment: 'staging' });
|
|
39
|
+
* LogEngine.configure({ mode: LogMode.PRODUCTION });
|
|
50
40
|
* ```
|
|
51
41
|
*/
|
|
52
42
|
configure: (config) => logger.configure(config),
|
|
43
|
+
// Standard logging methods with automatic redaction
|
|
53
44
|
/**
|
|
54
|
-
* Log a debug message
|
|
55
|
-
* Only shown
|
|
56
|
-
* Useful for detailed diagnostic information during development
|
|
45
|
+
* Log a debug message with automatic data redaction
|
|
46
|
+
* Only shown in DEVELOPMENT mode
|
|
57
47
|
* @param message - The debug message to log
|
|
48
|
+
* @param data - Optional data object to log (sensitive data will be redacted)
|
|
58
49
|
* @example
|
|
59
50
|
* ```typescript
|
|
60
|
-
* LogEngine.debug('
|
|
61
|
-
* LogEngine.debug(`Processing ${items.length} items`);
|
|
51
|
+
* LogEngine.debug('Processing user data', { userId: 123, email: 'user@example.com' });
|
|
62
52
|
* ```
|
|
63
53
|
*/
|
|
64
|
-
debug: (message) => logger.debug(message),
|
|
54
|
+
debug: (message, data) => logger.debug(message, data),
|
|
65
55
|
/**
|
|
66
|
-
* Log an
|
|
67
|
-
*
|
|
68
|
-
* Shown when log level is INFO or lower
|
|
56
|
+
* Log an info message with automatic data redaction
|
|
57
|
+
* Shown in DEVELOPMENT and PRODUCTION modes
|
|
69
58
|
* @param message - The info message to log
|
|
59
|
+
* @param data - Optional data object to log (sensitive data will be redacted)
|
|
70
60
|
* @example
|
|
71
61
|
* ```typescript
|
|
72
|
-
* LogEngine.info('
|
|
73
|
-
* LogEngine.info('User logged in: john@example.com');
|
|
62
|
+
* LogEngine.info('User login successful', { username: 'john' });
|
|
74
63
|
* ```
|
|
75
64
|
*/
|
|
76
|
-
info: (message) => logger.info(message),
|
|
65
|
+
info: (message, data) => logger.info(message, data),
|
|
77
66
|
/**
|
|
78
|
-
* Log a warning message
|
|
79
|
-
*
|
|
80
|
-
* Shown when log level is WARN or lower
|
|
67
|
+
* Log a warning message with automatic data redaction
|
|
68
|
+
* Shown in DEVELOPMENT and PRODUCTION modes
|
|
81
69
|
* @param message - The warning message to log
|
|
70
|
+
* @param data - Optional data object to log (sensitive data will be redacted)
|
|
82
71
|
* @example
|
|
83
72
|
* ```typescript
|
|
84
|
-
* LogEngine.warn('API rate limit approaching');
|
|
85
|
-
* LogEngine.warn('Deprecated function called');
|
|
73
|
+
* LogEngine.warn('API rate limit approaching', { requestsRemaining: 10 });
|
|
86
74
|
* ```
|
|
87
75
|
*/
|
|
88
|
-
warn: (message) => logger.warn(message),
|
|
76
|
+
warn: (message, data) => logger.warn(message, data),
|
|
89
77
|
/**
|
|
90
|
-
* Log an error message
|
|
91
|
-
*
|
|
92
|
-
* Always shown unless log level is SILENT
|
|
78
|
+
* Log an error message with automatic data redaction
|
|
79
|
+
* Shown in DEVELOPMENT and PRODUCTION modes
|
|
93
80
|
* @param message - The error message to log
|
|
81
|
+
* @param data - Optional data object to log (sensitive data will be redacted)
|
|
94
82
|
* @example
|
|
95
83
|
* ```typescript
|
|
96
|
-
* LogEngine.error('Database connection failed');
|
|
97
|
-
* LogEngine.error('Authentication token expired');
|
|
84
|
+
* LogEngine.error('Database connection failed', { host: 'localhost', port: 5432 });
|
|
98
85
|
* ```
|
|
99
86
|
*/
|
|
100
|
-
error: (message) => logger.error(message),
|
|
87
|
+
error: (message, data) => logger.error(message, data),
|
|
101
88
|
/**
|
|
102
|
-
* Log a critical message
|
|
103
|
-
*
|
|
104
|
-
* Always shown no matter what log mode is configured (except OFF mode)
|
|
89
|
+
* Log a critical message with automatic data redaction
|
|
90
|
+
* Always shown regardless of mode (except OFF)
|
|
105
91
|
* @param message - The critical log message to log
|
|
92
|
+
* @param data - Optional data object to log (sensitive data will be redacted)
|
|
93
|
+
* @example
|
|
94
|
+
* ```typescript
|
|
95
|
+
* LogEngine.log('Application starting', { version: '1.0.0' });
|
|
96
|
+
* ```
|
|
97
|
+
*/
|
|
98
|
+
log: (message, data) => logger.log(message, data),
|
|
99
|
+
// Raw methods that bypass redaction (use with caution)
|
|
100
|
+
/**
|
|
101
|
+
* Log a debug message without redaction (use with caution)
|
|
102
|
+
* Bypasses automatic data redaction for debugging purposes
|
|
103
|
+
* @param message - The debug message to log
|
|
104
|
+
* @param data - Optional data object to log (no redaction applied)
|
|
105
|
+
*/
|
|
106
|
+
debugRaw: (message, data) => logger.debugRaw(message, data),
|
|
107
|
+
/**
|
|
108
|
+
* Log an info message without redaction (use with caution)
|
|
109
|
+
* Bypasses automatic data redaction for debugging purposes
|
|
110
|
+
* @param message - The info message to log
|
|
111
|
+
* @param data - Optional data object to log (no redaction applied)
|
|
112
|
+
*/
|
|
113
|
+
infoRaw: (message, data) => logger.infoRaw(message, data),
|
|
114
|
+
/**
|
|
115
|
+
* Log a warning message without redaction (use with caution)
|
|
116
|
+
* Bypasses automatic data redaction for debugging purposes
|
|
117
|
+
* @param message - The warning message to log
|
|
118
|
+
* @param data - Optional data object to log (no redaction applied)
|
|
119
|
+
*/
|
|
120
|
+
warnRaw: (message, data) => logger.warnRaw(message, data),
|
|
121
|
+
/**
|
|
122
|
+
* Log an error message without redaction (use with caution)
|
|
123
|
+
* Bypasses automatic data redaction for debugging purposes
|
|
124
|
+
* @param message - The error message to log
|
|
125
|
+
* @param data - Optional data object to log (no redaction applied)
|
|
126
|
+
*/
|
|
127
|
+
errorRaw: (message, data) => logger.errorRaw(message, data),
|
|
128
|
+
/**
|
|
129
|
+
* Log a critical message without redaction (use with caution)
|
|
130
|
+
* Bypasses automatic data redaction for debugging purposes
|
|
131
|
+
* @param message - The critical log message to log
|
|
132
|
+
* @param data - Optional data object to log (no redaction applied)
|
|
133
|
+
*/
|
|
134
|
+
logRaw: (message, data) => logger.logRaw(message, data),
|
|
135
|
+
// Redaction configuration methods
|
|
136
|
+
/**
|
|
137
|
+
* Configure data redaction settings
|
|
138
|
+
* @param config - Partial redaction configuration to apply
|
|
139
|
+
*/
|
|
140
|
+
configureRedaction: (config) => redaction_1.DataRedactor.updateConfig(config),
|
|
141
|
+
/**
|
|
142
|
+
* Refresh redaction configuration from environment variables
|
|
143
|
+
* Useful for picking up runtime environment changes
|
|
144
|
+
*/
|
|
145
|
+
refreshRedactionConfig: () => redaction_1.DataRedactor.refreshConfig(),
|
|
146
|
+
/**
|
|
147
|
+
* Reset redaction configuration to defaults
|
|
148
|
+
*/
|
|
149
|
+
resetRedactionConfig: () => redaction_1.DataRedactor.updateConfig(redaction_1.defaultRedactionConfig),
|
|
150
|
+
/**
|
|
151
|
+
* Get current redaction configuration
|
|
152
|
+
* @returns Current redaction configuration
|
|
153
|
+
*/
|
|
154
|
+
getRedactionConfig: () => redaction_1.DataRedactor.getConfig(),
|
|
155
|
+
// Advanced redaction methods (Phase 3)
|
|
156
|
+
/**
|
|
157
|
+
* Add custom regex patterns for advanced field detection
|
|
158
|
+
* @param patterns - Array of regex patterns to add
|
|
159
|
+
*/
|
|
160
|
+
addCustomRedactionPatterns: (patterns) => redaction_1.DataRedactor.addCustomPatterns(patterns),
|
|
161
|
+
/**
|
|
162
|
+
* Clear all custom redaction patterns
|
|
163
|
+
*/
|
|
164
|
+
clearCustomRedactionPatterns: () => redaction_1.DataRedactor.clearCustomPatterns(),
|
|
165
|
+
/**
|
|
166
|
+
* Add custom sensitive field names to the existing list
|
|
167
|
+
* @param fields - Array of field names to add
|
|
168
|
+
*/
|
|
169
|
+
addSensitiveFields: (fields) => redaction_1.DataRedactor.addSensitiveFields(fields),
|
|
170
|
+
/**
|
|
171
|
+
* Test if a field name would be redacted with current configuration
|
|
172
|
+
* @param fieldName - Field name to test
|
|
173
|
+
* @returns true if field would be redacted, false otherwise
|
|
174
|
+
*/
|
|
175
|
+
testFieldRedaction: (fieldName) => redaction_1.DataRedactor.testFieldRedaction(fieldName),
|
|
176
|
+
/**
|
|
177
|
+
* Temporarily disable redaction for a specific logging call
|
|
178
|
+
* @returns LogEngine instance with redaction bypassed
|
|
106
179
|
* @example
|
|
107
180
|
* ```typescript
|
|
108
|
-
* LogEngine.
|
|
109
|
-
* LogEngine.log('Server listening on port 3000');
|
|
110
|
-
* LogEngine.log('Graceful shutdown initiated');
|
|
181
|
+
* LogEngine.withoutRedaction().info('Debug data', sensitiveObject);
|
|
111
182
|
* ```
|
|
112
183
|
*/
|
|
113
|
-
|
|
184
|
+
withoutRedaction: () => ({
|
|
185
|
+
debug: (message, data) => logger.debugRaw(message, data),
|
|
186
|
+
info: (message, data) => logger.infoRaw(message, data),
|
|
187
|
+
warn: (message, data) => logger.warnRaw(message, data),
|
|
188
|
+
error: (message, data) => logger.errorRaw(message, data),
|
|
189
|
+
log: (message, data) => logger.logRaw(message, data)
|
|
190
|
+
})
|
|
114
191
|
};
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
Object.defineProperty(exports, "LogMode", { enumerable: true, get: function () { return
|
|
192
|
+
// Re-export types and utilities for external use
|
|
193
|
+
var types_1 = require("./types");
|
|
194
|
+
Object.defineProperty(exports, "LogMode", { enumerable: true, get: function () { return types_1.LogMode; } });
|
|
195
|
+
Object.defineProperty(exports, "LogLevel", { enumerable: true, get: function () { return types_1.LogLevel; } });
|
|
196
|
+
var redaction_2 = require("./redaction");
|
|
197
|
+
Object.defineProperty(exports, "DataRedactor", { enumerable: true, get: function () { return redaction_2.DataRedactor; } });
|
|
198
|
+
Object.defineProperty(exports, "defaultRedactionConfig", { enumerable: true, get: function () { return redaction_2.defaultRedactionConfig; } });
|
|
199
|
+
Object.defineProperty(exports, "RedactionController", { enumerable: true, get: function () { return redaction_2.RedactionController; } });
|
|
200
|
+
// Default export for convenience
|
|
201
|
+
exports.default = exports.LogEngine;
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Logger configuration management
|
|
3
|
+
* Handles logger settings and configuration updates
|
|
4
|
+
*/
|
|
5
|
+
import { LoggerConfig } from '../types';
|
|
6
|
+
/**
|
|
7
|
+
* Configuration manager for logger settings
|
|
8
|
+
* Handles configuration validation, updates, and backward compatibility
|
|
9
|
+
*/
|
|
10
|
+
export declare class LoggerConfigManager {
|
|
11
|
+
private config;
|
|
12
|
+
constructor();
|
|
13
|
+
/**
|
|
14
|
+
* Get current configuration
|
|
15
|
+
* @returns Current logger configuration
|
|
16
|
+
*/
|
|
17
|
+
getConfig(): LoggerConfig;
|
|
18
|
+
/**
|
|
19
|
+
* Updates logger configuration with new settings
|
|
20
|
+
* Merges provided config with existing settings (partial update)
|
|
21
|
+
* Supports backwards compatibility by mapping level to mode with deprecation warnings
|
|
22
|
+
* @param config - Partial configuration object to apply
|
|
23
|
+
*/
|
|
24
|
+
updateConfig(config: Partial<LoggerConfig>): void;
|
|
25
|
+
/**
|
|
26
|
+
* Handle legacy level-based configuration with deprecation warnings
|
|
27
|
+
* @param config - Configuration containing legacy level property
|
|
28
|
+
*/
|
|
29
|
+
private handleLegacyLevelConfig;
|
|
30
|
+
/**
|
|
31
|
+
* Map legacy LogLevel values to LogMode values
|
|
32
|
+
* @param levelValue - Legacy level value
|
|
33
|
+
* @returns Corresponding LogMode or undefined if invalid
|
|
34
|
+
*/
|
|
35
|
+
private mapLevelToMode;
|
|
36
|
+
/**
|
|
37
|
+
* Create deprecation warning message using LogFormatter
|
|
38
|
+
* Outputs formatted deprecation warning messages to console
|
|
39
|
+
*/
|
|
40
|
+
private createDeprecationWarning;
|
|
41
|
+
}
|
|
42
|
+
//# sourceMappingURL=config.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"config.d.ts","sourceRoot":"","sources":["../../src/logger/config.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EAAE,YAAY,EAAqB,MAAM,UAAU,CAAC;AAG3D;;;GAGG;AACH,qBAAa,mBAAmB;IAC5B,OAAO,CAAC,MAAM,CAAe;;IAS7B;;;OAGG;IACH,SAAS,IAAI,YAAY;IAIzB;;;;;OAKG;IACH,YAAY,CAAC,MAAM,EAAE,OAAO,CAAC,YAAY,CAAC,GAAG,IAAI;IAgBjD;;;OAGG;IACH,OAAO,CAAC,uBAAuB;IAqB/B;;;;OAIG;IACH,OAAO,CAAC,cAAc;IActB;;;OAGG;IACH,OAAO,CAAC,wBAAwB;CAQnC"}
|
|
@@ -0,0 +1,101 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Logger configuration management
|
|
4
|
+
* Handles logger settings and configuration updates
|
|
5
|
+
*/
|
|
6
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
7
|
+
exports.LoggerConfigManager = void 0;
|
|
8
|
+
const types_1 = require("../types");
|
|
9
|
+
const environment_1 = require("./environment");
|
|
10
|
+
/**
|
|
11
|
+
* Configuration manager for logger settings
|
|
12
|
+
* Handles configuration validation, updates, and backward compatibility
|
|
13
|
+
*/
|
|
14
|
+
class LoggerConfigManager {
|
|
15
|
+
constructor() {
|
|
16
|
+
// Set initial configuration with environment-based auto-configuration
|
|
17
|
+
this.config = {
|
|
18
|
+
mode: environment_1.EnvironmentDetector.getEnvironmentMode()
|
|
19
|
+
};
|
|
20
|
+
}
|
|
21
|
+
/**
|
|
22
|
+
* Get current configuration
|
|
23
|
+
* @returns Current logger configuration
|
|
24
|
+
*/
|
|
25
|
+
getConfig() {
|
|
26
|
+
return { ...this.config };
|
|
27
|
+
}
|
|
28
|
+
/**
|
|
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
|
+
updateConfig(config) {
|
|
35
|
+
// Handle backwards compatibility - if level is provided but mode is not
|
|
36
|
+
if (config.level !== undefined && config.mode === undefined) {
|
|
37
|
+
this.handleLegacyLevelConfig(config);
|
|
38
|
+
}
|
|
39
|
+
else {
|
|
40
|
+
// Normal configuration update
|
|
41
|
+
// If mode is present, remove legacy level property to avoid conflicts
|
|
42
|
+
if (config.mode !== undefined && config.level !== undefined) {
|
|
43
|
+
const { level, ...configWithoutLevel } = config;
|
|
44
|
+
this.config = { ...this.config, ...configWithoutLevel };
|
|
45
|
+
}
|
|
46
|
+
else {
|
|
47
|
+
this.config = { ...this.config, ...config };
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
/**
|
|
52
|
+
* Handle legacy level-based configuration with deprecation warnings
|
|
53
|
+
* @param config - Configuration containing legacy level property
|
|
54
|
+
*/
|
|
55
|
+
handleLegacyLevelConfig(config) {
|
|
56
|
+
// Map legacy level values to new LogMode values and validate first
|
|
57
|
+
const levelValue = config.level;
|
|
58
|
+
const mappedMode = this.mapLevelToMode(levelValue);
|
|
59
|
+
// Fail fast if the level value is invalid
|
|
60
|
+
if (mappedMode === undefined) {
|
|
61
|
+
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.`);
|
|
62
|
+
}
|
|
63
|
+
// Only show deprecation warning after confirming the level is valid and in non-test environments
|
|
64
|
+
if (!environment_1.EnvironmentDetector.isTestEnvironment()) {
|
|
65
|
+
this.createDeprecationWarning();
|
|
66
|
+
}
|
|
67
|
+
// Merge existing config with all keys from the passed config, and override mode with mapped value
|
|
68
|
+
// Remove the legacy 'level' property to avoid conflicts with the new 'mode' property
|
|
69
|
+
const { level, ...configWithoutLevel } = config;
|
|
70
|
+
this.config = { ...this.config, ...configWithoutLevel, mode: mappedMode };
|
|
71
|
+
}
|
|
72
|
+
/**
|
|
73
|
+
* Map legacy LogLevel values to LogMode values
|
|
74
|
+
* @param levelValue - Legacy level value
|
|
75
|
+
* @returns Corresponding LogMode or undefined if invalid
|
|
76
|
+
*/
|
|
77
|
+
mapLevelToMode(levelValue) {
|
|
78
|
+
const levelToModeMap = {
|
|
79
|
+
[types_1.LogLevel.DEBUG]: types_1.LogMode.DEBUG, // 0 -> 0
|
|
80
|
+
[types_1.LogLevel.INFO]: types_1.LogMode.INFO, // 1 -> 1
|
|
81
|
+
[types_1.LogLevel.WARN]: types_1.LogMode.WARN, // 2 -> 2
|
|
82
|
+
[types_1.LogLevel.ERROR]: types_1.LogMode.ERROR, // 3 -> 3
|
|
83
|
+
[types_1.LogLevel.LOG]: types_1.LogMode.SILENT, // 99 -> 4 (preserves critical-only behavior)
|
|
84
|
+
4: types_1.LogMode.SILENT, // Legacy SILENT -> 4
|
|
85
|
+
5: types_1.LogMode.OFF // Legacy OFF -> 5
|
|
86
|
+
};
|
|
87
|
+
return levelToModeMap[levelValue];
|
|
88
|
+
}
|
|
89
|
+
/**
|
|
90
|
+
* Create deprecation warning message using LogFormatter
|
|
91
|
+
* Outputs formatted deprecation warning messages to console
|
|
92
|
+
*/
|
|
93
|
+
createDeprecationWarning() {
|
|
94
|
+
// Import LogFormatter to format system messages properly
|
|
95
|
+
const { LogFormatter } = require('../formatter');
|
|
96
|
+
console.warn(LogFormatter.formatSystemMessage('⚠️ DEPRECATION WARNING: The "level" configuration is deprecated and will be removed in v2.0.0. Please use "mode" instead.'));
|
|
97
|
+
console.warn(LogFormatter.formatSystemMessage(' Migration: LogEngine.configure({ level: LogLevel.DEBUG }) → LogEngine.configure({ mode: LogMode.DEBUG })'));
|
|
98
|
+
console.warn(LogFormatter.formatSystemMessage(' See: https://github.com/wgtechlabs/log-engine#migration-guide-loglevel--logmode'));
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
exports.LoggerConfigManager = LoggerConfigManager;
|
|
@@ -0,0 +1,108 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Core Logger class that handles log message output with configurable levels
|
|
3
|
+
* Supports DEBUG, INFO, WARN, ERROR, and LOG levels with intelligent filtering
|
|
4
|
+
* LOG level always outputs regardless of configuration
|
|
5
|
+
* Uses colorized console output with timestamps for better readability
|
|
6
|
+
* Includes automatic data redaction for sensitive information
|
|
7
|
+
*/
|
|
8
|
+
import { LoggerConfig } from '../types';
|
|
9
|
+
/**
|
|
10
|
+
* Logger class responsible for managing log output and configuration
|
|
11
|
+
* Provides mode-based filtering and formatted console output
|
|
12
|
+
*/
|
|
13
|
+
export declare class Logger {
|
|
14
|
+
private configManager;
|
|
15
|
+
/**
|
|
16
|
+
* Logger constructor - sets up environment-based auto-configuration
|
|
17
|
+
*/
|
|
18
|
+
constructor();
|
|
19
|
+
/**
|
|
20
|
+
* Updates logger configuration with new settings
|
|
21
|
+
* Also updates redaction configuration based on environment
|
|
22
|
+
* @param config - Partial configuration object to apply
|
|
23
|
+
*/
|
|
24
|
+
configure(config: Partial<LoggerConfig>): void;
|
|
25
|
+
/**
|
|
26
|
+
* Get current logger configuration
|
|
27
|
+
* @returns Current logger configuration
|
|
28
|
+
*/
|
|
29
|
+
getConfig(): LoggerConfig;
|
|
30
|
+
/**
|
|
31
|
+
* Determines if a message should be logged based on current log mode
|
|
32
|
+
* @param level - The log level of the message to check
|
|
33
|
+
* @returns true if message should be logged, false otherwise
|
|
34
|
+
*/
|
|
35
|
+
private shouldLog;
|
|
36
|
+
/**
|
|
37
|
+
* Log a debug message with DEBUG level formatting
|
|
38
|
+
* Uses console.log for output with purple/magenta coloring
|
|
39
|
+
* Automatically redacts sensitive data when provided
|
|
40
|
+
* @param message - The debug message to log
|
|
41
|
+
* @param data - Optional data object to log (will be redacted)
|
|
42
|
+
*/
|
|
43
|
+
debug(message: string, data?: any): void;
|
|
44
|
+
/**
|
|
45
|
+
* Log an informational message with INFO level formatting
|
|
46
|
+
* Uses console.log for output with blue coloring
|
|
47
|
+
* Automatically redacts sensitive data when provided
|
|
48
|
+
* @param message - The info message to log
|
|
49
|
+
* @param data - Optional data object to log (will be redacted)
|
|
50
|
+
*/
|
|
51
|
+
info(message: string, data?: any): void;
|
|
52
|
+
/**
|
|
53
|
+
* Log a warning message with WARN level formatting
|
|
54
|
+
* Uses console.warn for output with yellow coloring
|
|
55
|
+
* Automatically redacts sensitive data when provided
|
|
56
|
+
* @param message - The warning message to log
|
|
57
|
+
* @param data - Optional data object to log (will be redacted)
|
|
58
|
+
*/
|
|
59
|
+
warn(message: string, data?: any): void;
|
|
60
|
+
/**
|
|
61
|
+
* Log an error message with ERROR level formatting
|
|
62
|
+
* Uses console.error for output with red coloring
|
|
63
|
+
* Automatically redacts sensitive data when provided
|
|
64
|
+
* @param message - The error message to log
|
|
65
|
+
* @param data - Optional data object to log (will be redacted)
|
|
66
|
+
*/
|
|
67
|
+
error(message: string, data?: any): void;
|
|
68
|
+
/**
|
|
69
|
+
* Log a message with LOG level formatting (always outputs unless mode is OFF)
|
|
70
|
+
* Uses console.log for output with green coloring
|
|
71
|
+
* LOG level bypasses normal filtering and always outputs (except when OFF is set)
|
|
72
|
+
* Automatically redacts sensitive data when provided
|
|
73
|
+
* @param message - The log message to output
|
|
74
|
+
* @param data - Optional data object to log (will be redacted)
|
|
75
|
+
*/
|
|
76
|
+
log(message: string, data?: any): void;
|
|
77
|
+
/**
|
|
78
|
+
* Log a debug message without data redaction
|
|
79
|
+
* @param message - The debug message to log
|
|
80
|
+
* @param data - Optional data object to log (no redaction applied)
|
|
81
|
+
*/
|
|
82
|
+
debugRaw(message: string, data?: any): void;
|
|
83
|
+
/**
|
|
84
|
+
* Log an info message without data redaction
|
|
85
|
+
* @param message - The info message to log
|
|
86
|
+
* @param data - Optional data object to log (no redaction applied)
|
|
87
|
+
*/
|
|
88
|
+
infoRaw(message: string, data?: any): void;
|
|
89
|
+
/**
|
|
90
|
+
* Log a warning message without data redaction
|
|
91
|
+
* @param message - The warning message to log
|
|
92
|
+
* @param data - Optional data object to log (no redaction applied)
|
|
93
|
+
*/
|
|
94
|
+
warnRaw(message: string, data?: any): void;
|
|
95
|
+
/**
|
|
96
|
+
* Log an error message without data redaction
|
|
97
|
+
* @param message - The error message to log
|
|
98
|
+
* @param data - Optional data object to log (no redaction applied)
|
|
99
|
+
*/
|
|
100
|
+
errorRaw(message: string, data?: any): void;
|
|
101
|
+
/**
|
|
102
|
+
* Log a message without data redaction (always outputs unless mode is OFF)
|
|
103
|
+
* @param message - The log message to output
|
|
104
|
+
* @param data - Optional data object to log (no redaction applied)
|
|
105
|
+
*/
|
|
106
|
+
logRaw(message: string, data?: any): void;
|
|
107
|
+
}
|
|
108
|
+
//# sourceMappingURL=core.d.ts.map
|
|
@@ -0,0 +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;AAM3D;;;GAGG;AACH,qBAAa,MAAM;IACf,OAAO,CAAC,aAAa,CAAsB;IAE3C;;OAEG;;IAKH;;;;OAIG;IACH,SAAS,CAAC,MAAM,EAAE,OAAO,CAAC,YAAY,CAAC,GAAG,IAAI;IAU9C;;;OAGG;IACH,SAAS,IAAI,YAAY;IAIzB;;;;OAIG;IACH,OAAO,CAAC,SAAS;IAMjB;;;;;;OAMG;IACH,KAAK,CAAC,OAAO,EAAE,MAAM,EAAE,IAAI,CAAC,EAAE,GAAG,GAAG,IAAI;IAQxC;;;;;;OAMG;IACH,IAAI,CAAC,OAAO,EAAE,MAAM,EAAE,IAAI,CAAC,EAAE,GAAG,GAAG,IAAI;IAQvC;;;;;;OAMG;IACH,IAAI,CAAC,OAAO,EAAE,MAAM,EAAE,IAAI,CAAC,EAAE,GAAG,GAAG,IAAI;IAQvC;;;;;;OAMG;IACH,KAAK,CAAC,OAAO,EAAE,MAAM,EAAE,IAAI,CAAC,EAAE,GAAG,GAAG,IAAI;IAQxC;;;;;;;OAOG;IACH,GAAG,CAAC,OAAO,EAAE,MAAM,EAAE,IAAI,CAAC,EAAE,GAAG,GAAG,IAAI;IAStC;;;;OAIG;IACH,QAAQ,CAAC,OAAO,EAAE,MAAM,EAAE,IAAI,CAAC,EAAE,GAAG,GAAG,IAAI;IAO3C;;;;OAIG;IACH,OAAO,CAAC,OAAO,EAAE,MAAM,EAAE,IAAI,CAAC,EAAE,GAAG,GAAG,IAAI;IAO1C;;;;OAIG;IACH,OAAO,CAAC,OAAO,EAAE,MAAM,EAAE,IAAI,CAAC,EAAE,GAAG,GAAG,IAAI;IAO1C;;;;OAIG;IACH,QAAQ,CAAC,OAAO,EAAE,MAAM,EAAE,IAAI,CAAC,EAAE,GAAG,GAAG,IAAI;IAO3C;;;;OAIG;IACH,MAAM,CAAC,OAAO,EAAE,MAAM,EAAE,IAAI,CAAC,EAAE,GAAG,GAAG,IAAI;CAM5C"}
|