@wgtechlabs/log-engine 2.1.0 → 2.2.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/README.md +67 -1
- package/dist/cjs/__tests__/async-test-utils.cjs +276 -0
- package/dist/cjs/__tests__/async-test-utils.d.ts +51 -0
- package/dist/cjs/__tests__/async-test-utils.d.ts.map +1 -0
- package/dist/cjs/__tests__/async-test-utils.js.map +1 -0
- package/dist/cjs/__tests__/redaction/test-utils.cjs +72 -0
- package/dist/cjs/__tests__/redaction/test-utils.d.ts +33 -0
- package/dist/cjs/__tests__/redaction/test-utils.d.ts.map +1 -0
- package/dist/cjs/__tests__/redaction/test-utils.js.map +1 -0
- package/dist/cjs/__tests__/test-utils.cjs +49 -0
- package/dist/cjs/__tests__/test-utils.d.ts +41 -0
- package/dist/cjs/__tests__/test-utils.d.ts.map +1 -0
- package/dist/cjs/__tests__/test-utils.js.map +1 -0
- package/dist/{formatter/colors.js → cjs/formatter/colors.cjs} +1 -0
- package/dist/cjs/formatter/colors.d.ts.map +1 -0
- package/dist/cjs/formatter/colors.js.map +1 -0
- package/dist/{formatter/data-formatter.js → cjs/formatter/data-formatter.cjs} +1 -0
- package/dist/cjs/formatter/data-formatter.d.ts.map +1 -0
- package/dist/cjs/formatter/data-formatter.js.map +1 -0
- package/dist/{formatter/index.js → cjs/formatter/index.cjs} +6 -5
- package/dist/cjs/formatter/index.d.ts.map +1 -0
- package/dist/cjs/formatter/index.js.map +1 -0
- package/dist/{formatter/message-formatter.js → cjs/formatter/message-formatter.cjs} +61 -11
- package/dist/{formatter → cjs/formatter}/message-formatter.d.ts +9 -3
- package/dist/cjs/formatter/message-formatter.d.ts.map +1 -0
- package/dist/cjs/formatter/message-formatter.js.map +1 -0
- package/dist/{formatter/timestamp.js → cjs/formatter/timestamp.cjs} +1 -0
- package/dist/cjs/formatter/timestamp.d.ts.map +1 -0
- package/dist/cjs/formatter/timestamp.js.map +1 -0
- package/dist/{index.js → cjs/index.cjs} +5 -4
- package/dist/{index.d.ts → cjs/index.d.ts} +1 -1
- package/dist/cjs/index.d.ts.map +1 -0
- package/dist/cjs/index.js.map +1 -0
- package/dist/{logger/advanced-outputs.js → cjs/logger/advanced-outputs.cjs} +1 -0
- package/dist/cjs/logger/advanced-outputs.d.ts.map +1 -0
- package/dist/cjs/logger/advanced-outputs.js.map +1 -0
- package/dist/{logger/config.js → cjs/logger/config.cjs} +4 -3
- package/dist/cjs/logger/config.d.ts.map +1 -0
- package/dist/cjs/logger/config.js.map +1 -0
- package/dist/{logger/core.js → cjs/logger/core.cjs} +48 -16
- package/dist/{logger → cjs/logger}/core.d.ts +19 -0
- package/dist/cjs/logger/core.d.ts.map +1 -0
- package/dist/cjs/logger/core.js.map +1 -0
- package/dist/{logger/environment.js → cjs/logger/environment.cjs} +2 -1
- package/dist/cjs/logger/environment.d.ts.map +1 -0
- package/dist/cjs/logger/environment.js.map +1 -0
- package/dist/{logger/filtering.js → cjs/logger/filtering.cjs} +2 -1
- package/dist/cjs/logger/filtering.d.ts.map +1 -0
- package/dist/cjs/logger/filtering.js.map +1 -0
- package/dist/{logger/index.js → cjs/logger/index.cjs} +6 -5
- package/dist/cjs/logger/index.d.ts.map +1 -0
- package/dist/cjs/logger/index.js.map +1 -0
- package/dist/cjs/package.json +3 -0
- package/dist/{redaction/config.js → cjs/redaction/config.cjs} +1 -0
- package/dist/cjs/redaction/config.d.ts.map +1 -0
- package/dist/cjs/redaction/config.js.map +1 -0
- package/dist/{redaction/index.js → cjs/redaction/index.cjs} +3 -2
- package/dist/cjs/redaction/index.d.ts.map +1 -0
- package/dist/cjs/redaction/index.js.map +1 -0
- package/dist/{redaction/redactor.js → cjs/redaction/redactor.cjs} +2 -1
- package/dist/cjs/redaction/redactor.d.ts.map +1 -0
- package/dist/cjs/redaction/redactor.js.map +1 -0
- package/dist/{types/index.js → cjs/types/index.cjs} +1 -0
- package/dist/{types → cjs/types}/index.d.ts +12 -0
- package/dist/cjs/types/index.d.ts.map +1 -0
- package/dist/cjs/types/index.js.map +1 -0
- package/dist/esm/__tests__/async-test-utils.d.ts +51 -0
- package/dist/esm/__tests__/async-test-utils.d.ts.map +1 -0
- package/dist/esm/__tests__/async-test-utils.js +231 -0
- package/dist/esm/__tests__/async-test-utils.js.map +1 -0
- package/dist/esm/__tests__/redaction/test-utils.d.ts +33 -0
- package/dist/esm/__tests__/redaction/test-utils.d.ts.map +1 -0
- package/dist/esm/__tests__/redaction/test-utils.js +65 -0
- package/dist/esm/__tests__/redaction/test-utils.js.map +1 -0
- package/dist/esm/__tests__/test-utils.d.ts +41 -0
- package/dist/esm/__tests__/test-utils.d.ts.map +1 -0
- package/dist/esm/__tests__/test-utils.js +42 -0
- package/dist/esm/__tests__/test-utils.js.map +1 -0
- package/dist/esm/formatter/colors.d.ts +32 -0
- package/dist/esm/formatter/colors.d.ts.map +1 -0
- package/dist/esm/formatter/colors.js +32 -0
- package/dist/esm/formatter/colors.js.map +1 -0
- package/dist/esm/formatter/data-formatter.d.ts +26 -0
- package/dist/esm/formatter/data-formatter.d.ts.map +1 -0
- package/dist/esm/formatter/data-formatter.js +50 -0
- package/dist/esm/formatter/data-formatter.js.map +1 -0
- package/dist/esm/formatter/index.d.ts +10 -0
- package/dist/esm/formatter/index.d.ts.map +1 -0
- package/dist/esm/formatter/index.js +11 -0
- package/dist/esm/formatter/index.js.map +1 -0
- package/dist/esm/formatter/message-formatter.d.ts +47 -0
- package/dist/esm/formatter/message-formatter.d.ts.map +1 -0
- package/dist/esm/formatter/message-formatter.js +133 -0
- package/dist/esm/formatter/message-formatter.js.map +1 -0
- package/dist/esm/formatter/timestamp.d.ts +27 -0
- package/dist/esm/formatter/timestamp.d.ts.map +1 -0
- package/dist/esm/formatter/timestamp.js +36 -0
- package/dist/esm/formatter/timestamp.js.map +1 -0
- package/dist/esm/index.d.ts +180 -0
- package/dist/esm/index.d.ts.map +1 -0
- package/dist/esm/index.js +194 -0
- package/dist/esm/index.js.map +1 -0
- package/dist/esm/logger/advanced-outputs.d.ts +159 -0
- package/dist/esm/logger/advanced-outputs.d.ts.map +1 -0
- package/dist/esm/logger/advanced-outputs.js +542 -0
- package/dist/esm/logger/advanced-outputs.js.map +1 -0
- package/dist/esm/logger/config.d.ts +42 -0
- package/dist/esm/logger/config.d.ts.map +1 -0
- package/dist/esm/logger/config.js +101 -0
- package/dist/esm/logger/config.js.map +1 -0
- package/dist/esm/logger/core.d.ts +171 -0
- package/dist/esm/logger/core.d.ts.map +1 -0
- package/dist/esm/logger/core.js +398 -0
- package/dist/esm/logger/core.js.map +1 -0
- package/dist/esm/logger/environment.d.ts +36 -0
- package/dist/esm/logger/environment.d.ts.map +1 -0
- package/dist/esm/logger/environment.js +58 -0
- package/dist/esm/logger/environment.js.map +1 -0
- package/dist/esm/logger/filtering.d.ts +36 -0
- package/dist/esm/logger/filtering.d.ts.map +1 -0
- package/dist/esm/logger/filtering.js +77 -0
- package/dist/esm/logger/filtering.js.map +1 -0
- package/dist/esm/logger/index.d.ts +10 -0
- package/dist/esm/logger/index.d.ts.map +1 -0
- package/dist/esm/logger/index.js +11 -0
- package/dist/esm/logger/index.js.map +1 -0
- package/dist/esm/redaction/config.d.ts +29 -0
- package/dist/esm/redaction/config.d.ts.map +1 -0
- package/dist/esm/redaction/config.js +92 -0
- package/dist/esm/redaction/config.js.map +1 -0
- package/dist/esm/redaction/index.d.ts +8 -0
- package/dist/esm/redaction/index.d.ts.map +1 -0
- package/dist/esm/redaction/index.js +7 -0
- package/dist/esm/redaction/index.js.map +1 -0
- package/dist/esm/redaction/redactor.d.ts +99 -0
- package/dist/esm/redaction/redactor.d.ts.map +1 -0
- package/dist/esm/redaction/redactor.js +259 -0
- package/dist/esm/redaction/redactor.js.map +1 -0
- package/dist/esm/types/index.d.ts +322 -0
- package/dist/esm/types/index.d.ts.map +1 -0
- package/dist/esm/types/index.js +41 -0
- package/dist/esm/types/index.js.map +1 -0
- package/package.json +59 -10
- package/dist/formatter/colors.d.ts.map +0 -1
- package/dist/formatter/data-formatter.d.ts.map +0 -1
- package/dist/formatter/index.d.ts.map +0 -1
- package/dist/formatter/message-formatter.d.ts.map +0 -1
- package/dist/formatter/timestamp.d.ts.map +0 -1
- package/dist/index.d.ts.map +0 -1
- package/dist/logger/advanced-outputs.d.ts.map +0 -1
- package/dist/logger/config.d.ts.map +0 -1
- package/dist/logger/core.d.ts.map +0 -1
- package/dist/logger/environment.d.ts.map +0 -1
- package/dist/logger/filtering.d.ts.map +0 -1
- package/dist/logger/index.d.ts.map +0 -1
- package/dist/redaction/config.d.ts.map +0 -1
- package/dist/redaction/index.d.ts.map +0 -1
- package/dist/redaction/redactor.d.ts.map +0 -1
- package/dist/types/index.d.ts.map +0 -1
- /package/dist/{formatter → cjs/formatter}/colors.d.ts +0 -0
- /package/dist/{formatter → cjs/formatter}/data-formatter.d.ts +0 -0
- /package/dist/{formatter → cjs/formatter}/index.d.ts +0 -0
- /package/dist/{formatter → cjs/formatter}/timestamp.d.ts +0 -0
- /package/dist/{logger → cjs/logger}/advanced-outputs.d.ts +0 -0
- /package/dist/{logger → cjs/logger}/config.d.ts +0 -0
- /package/dist/{logger → cjs/logger}/environment.d.ts +0 -0
- /package/dist/{logger → cjs/logger}/filtering.d.ts +0 -0
- /package/dist/{logger → cjs/logger}/index.d.ts +0 -0
- /package/dist/{redaction → cjs/redaction}/config.d.ts +0 -0
- /package/dist/{redaction → cjs/redaction}/index.d.ts +0 -0
- /package/dist/{redaction → cjs/redaction}/redactor.d.ts +0 -0
|
@@ -0,0 +1,101 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Logger configuration management
|
|
3
|
+
* Handles logger settings and configuration updates
|
|
4
|
+
*/
|
|
5
|
+
import { LogLevel, LogMode } from '../types/index.js';
|
|
6
|
+
import { EnvironmentDetector } from './environment.js';
|
|
7
|
+
/**
|
|
8
|
+
* Configuration manager for logger settings
|
|
9
|
+
* Handles configuration validation, updates, and backward compatibility
|
|
10
|
+
*/
|
|
11
|
+
export class LoggerConfigManager {
|
|
12
|
+
constructor() {
|
|
13
|
+
// Set initial configuration with environment-based auto-configuration
|
|
14
|
+
this.config = {
|
|
15
|
+
mode: EnvironmentDetector.getEnvironmentMode()
|
|
16
|
+
};
|
|
17
|
+
}
|
|
18
|
+
/**
|
|
19
|
+
* Get current configuration
|
|
20
|
+
* @returns Current logger configuration
|
|
21
|
+
*/
|
|
22
|
+
getConfig() {
|
|
23
|
+
return { ...this.config };
|
|
24
|
+
}
|
|
25
|
+
/**
|
|
26
|
+
* Updates logger configuration with new settings
|
|
27
|
+
* Merges provided config with existing settings (partial update)
|
|
28
|
+
* Supports backwards compatibility by mapping level to mode with deprecation warnings
|
|
29
|
+
* @param config - Partial configuration object to apply
|
|
30
|
+
*/
|
|
31
|
+
updateConfig(config) {
|
|
32
|
+
// Handle backwards compatibility - if level is provided but mode is not
|
|
33
|
+
if (config.level !== undefined && config.mode === undefined) {
|
|
34
|
+
this.handleLegacyLevelConfig(config);
|
|
35
|
+
}
|
|
36
|
+
else {
|
|
37
|
+
// Normal configuration update
|
|
38
|
+
// If mode is present, remove legacy level property to avoid conflicts
|
|
39
|
+
if (config.mode !== undefined && config.level !== undefined) {
|
|
40
|
+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
41
|
+
const { level, ...configWithoutLevel } = config;
|
|
42
|
+
this.config = { ...this.config, ...configWithoutLevel };
|
|
43
|
+
}
|
|
44
|
+
else {
|
|
45
|
+
this.config = { ...this.config, ...config };
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
/**
|
|
50
|
+
* Handle legacy level-based configuration with deprecation warnings
|
|
51
|
+
* @param config - Configuration containing legacy level property
|
|
52
|
+
*/
|
|
53
|
+
handleLegacyLevelConfig(config) {
|
|
54
|
+
// Map legacy level values to new LogMode values and validate first
|
|
55
|
+
const levelValue = config.level;
|
|
56
|
+
const mappedMode = this.mapLevelToMode(levelValue);
|
|
57
|
+
// Fail fast if the level value is invalid
|
|
58
|
+
if (mappedMode === undefined) {
|
|
59
|
+
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.`);
|
|
60
|
+
}
|
|
61
|
+
// Only show deprecation warning after confirming the level is valid and in non-test environments
|
|
62
|
+
if (!EnvironmentDetector.isTestEnvironment()) {
|
|
63
|
+
this.createDeprecationWarning();
|
|
64
|
+
}
|
|
65
|
+
// Merge existing config with all keys from the passed config, and override mode with mapped value
|
|
66
|
+
// Remove the legacy 'level' property to avoid conflicts with the new 'mode' property
|
|
67
|
+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
68
|
+
const { level, ...configWithoutLevel } = config;
|
|
69
|
+
this.config = { ...this.config, ...configWithoutLevel, mode: mappedMode };
|
|
70
|
+
}
|
|
71
|
+
/**
|
|
72
|
+
* Map legacy LogLevel values to LogMode values
|
|
73
|
+
* @param levelValue - Legacy level value
|
|
74
|
+
* @returns Corresponding LogMode or undefined if invalid
|
|
75
|
+
*/
|
|
76
|
+
mapLevelToMode(levelValue) {
|
|
77
|
+
// Use switch statement to avoid object injection
|
|
78
|
+
switch (levelValue) {
|
|
79
|
+
case LogLevel.DEBUG: return LogMode.DEBUG; // 0 -> 0
|
|
80
|
+
case LogLevel.INFO: return LogMode.INFO; // 1 -> 1
|
|
81
|
+
case LogLevel.WARN: return LogMode.WARN; // 2 -> 2
|
|
82
|
+
case LogLevel.ERROR: return LogMode.ERROR; // 3 -> 3
|
|
83
|
+
case LogLevel.LOG: return LogMode.SILENT; // 99 -> 4 (preserves critical-only behavior)
|
|
84
|
+
case 4: return LogMode.SILENT; // Legacy SILENT -> 4
|
|
85
|
+
case 5: return LogMode.OFF; // Legacy OFF -> 5
|
|
86
|
+
default: return undefined;
|
|
87
|
+
}
|
|
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 v3.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
|
+
//# sourceMappingURL=config.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"config.js","sourceRoot":"","sources":["../../../src/logger/config.ts"],"names":[],"mappings":"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"}
|
|
@@ -0,0 +1,171 @@
|
|
|
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, LogData } 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
|
+
private cachedConfig;
|
|
16
|
+
/**
|
|
17
|
+
* Logger constructor - sets up environment-based auto-configuration
|
|
18
|
+
*/
|
|
19
|
+
constructor();
|
|
20
|
+
/**
|
|
21
|
+
* Get cached configuration or refresh cache if needed
|
|
22
|
+
* This avoids repeated getConfig() calls for better performance
|
|
23
|
+
*/
|
|
24
|
+
private getCachedConfig;
|
|
25
|
+
/**
|
|
26
|
+
* Invalidate the configuration cache when configuration changes
|
|
27
|
+
*/
|
|
28
|
+
private invalidateConfigCache;
|
|
29
|
+
/**
|
|
30
|
+
* Helper method to format log messages with cached configuration
|
|
31
|
+
* Reduces code duplication across all log methods
|
|
32
|
+
* @param level - The log level to format for
|
|
33
|
+
* @param message - The message content to format
|
|
34
|
+
* @param data - Optional data object to include in the log output
|
|
35
|
+
* @returns Formatted string with appropriate configuration applied
|
|
36
|
+
*/
|
|
37
|
+
private formatMessage;
|
|
38
|
+
/**
|
|
39
|
+
* Built-in output handlers for common use cases
|
|
40
|
+
*/
|
|
41
|
+
private getBuiltInHandler;
|
|
42
|
+
/**
|
|
43
|
+
* Process a single output target with error handling
|
|
44
|
+
* @param output - Single output target 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
|
+
* @param isEnhanced - Whether this is an enhanced output (supports configured handler objects)
|
|
50
|
+
*/
|
|
51
|
+
private processSingleOutput;
|
|
52
|
+
/**
|
|
53
|
+
* Process multiple output targets
|
|
54
|
+
* @param outputs - Array of output targets to process
|
|
55
|
+
* @param level - Log level
|
|
56
|
+
* @param rawMessage - Original unformatted message
|
|
57
|
+
* @param formattedMessage - Formatted message for console-based outputs
|
|
58
|
+
* @param data - Optional data
|
|
59
|
+
*/
|
|
60
|
+
private processOutputs;
|
|
61
|
+
/**
|
|
62
|
+
* Process enhanced output targets
|
|
63
|
+
* @param enhancedOutputs - Array of enhanced output targets to process
|
|
64
|
+
* @param level - Log level
|
|
65
|
+
* @param rawMessage - Original unformatted message
|
|
66
|
+
* @param formattedMessage - Formatted message for console-based outputs
|
|
67
|
+
* @param data - Optional data
|
|
68
|
+
*/
|
|
69
|
+
private processEnhancedOutputs;
|
|
70
|
+
/**
|
|
71
|
+
* Updates logger configuration with new settings
|
|
72
|
+
* Also updates redaction configuration based on environment
|
|
73
|
+
* @param config - Partial configuration object to apply
|
|
74
|
+
*/
|
|
75
|
+
configure(config: Partial<LoggerConfig>): void;
|
|
76
|
+
/**
|
|
77
|
+
* Get current logger configuration
|
|
78
|
+
* @returns Current logger configuration
|
|
79
|
+
*/
|
|
80
|
+
getConfig(): LoggerConfig;
|
|
81
|
+
/**
|
|
82
|
+
* Determines if a message should be logged based on current log mode
|
|
83
|
+
* @param level - The log level of the message to check
|
|
84
|
+
* @returns true if message should be logged, false otherwise
|
|
85
|
+
*/
|
|
86
|
+
private shouldLog;
|
|
87
|
+
/**
|
|
88
|
+
* Writes log output using configured output handler or default console methods
|
|
89
|
+
* Supports single output handler, multiple outputs, and enhanced outputs
|
|
90
|
+
* Priority: outputs > enhancedOutputs > outputHandler > default console
|
|
91
|
+
* @param level - The log level as a string
|
|
92
|
+
* @param rawMessage - The original unformatted message
|
|
93
|
+
* @param formattedMessage - The pre-formatted message to output
|
|
94
|
+
* @param data - Optional data object that was logged
|
|
95
|
+
* @param isError - Whether this is an error level message (for console.error)
|
|
96
|
+
* @param isWarn - Whether this is a warning level message (for console.warn)
|
|
97
|
+
*/
|
|
98
|
+
private writeToOutput;
|
|
99
|
+
/**
|
|
100
|
+
* Log a debug message with DEBUG level formatting
|
|
101
|
+
* Uses console.log for output with purple/magenta coloring
|
|
102
|
+
* Automatically redacts sensitive data when provided
|
|
103
|
+
* @param message - The debug message to log
|
|
104
|
+
* @param data - Optional data object to log (will be redacted)
|
|
105
|
+
*/
|
|
106
|
+
debug(message: string, data?: LogData): void;
|
|
107
|
+
/**
|
|
108
|
+
* Log an informational message with INFO level formatting
|
|
109
|
+
* Uses console.log for output with blue coloring
|
|
110
|
+
* Automatically redacts sensitive data when provided
|
|
111
|
+
* @param message - The info message to log
|
|
112
|
+
* @param data - Optional data object to log (will be redacted)
|
|
113
|
+
*/
|
|
114
|
+
info(message: string, data?: LogData): void;
|
|
115
|
+
/**
|
|
116
|
+
* Log a warning message with WARN level formatting
|
|
117
|
+
* Uses console.warn for output with yellow coloring
|
|
118
|
+
* Automatically redacts sensitive data when provided
|
|
119
|
+
* @param message - The warning message to log
|
|
120
|
+
* @param data - Optional data object to log (will be redacted)
|
|
121
|
+
*/
|
|
122
|
+
warn(message: string, data?: LogData): void;
|
|
123
|
+
/**
|
|
124
|
+
* Log an error message with ERROR level formatting
|
|
125
|
+
* Uses console.error for output with red coloring
|
|
126
|
+
* Automatically redacts sensitive data when provided
|
|
127
|
+
* @param message - The error message to log
|
|
128
|
+
* @param data - Optional data object to log (will be redacted)
|
|
129
|
+
*/
|
|
130
|
+
error(message: string, data?: LogData): void;
|
|
131
|
+
/**
|
|
132
|
+
* Log a message with LOG level formatting (always outputs unless mode is OFF)
|
|
133
|
+
* Uses console.log for output with green coloring
|
|
134
|
+
* LOG level bypasses normal filtering and always outputs (except when OFF is set)
|
|
135
|
+
* Automatically redacts sensitive data when provided
|
|
136
|
+
* @param message - The log message to output
|
|
137
|
+
* @param data - Optional data object to log (will be redacted)
|
|
138
|
+
*/
|
|
139
|
+
log(message: string, data?: LogData): void;
|
|
140
|
+
/**
|
|
141
|
+
* Log a debug message without data redaction
|
|
142
|
+
* @param message - The debug message to log
|
|
143
|
+
* @param data - Optional data object to log (no redaction applied)
|
|
144
|
+
*/
|
|
145
|
+
debugRaw(message: string, data?: LogData): void;
|
|
146
|
+
/**
|
|
147
|
+
* Log an info message without data redaction
|
|
148
|
+
* @param message - The info message to log
|
|
149
|
+
* @param data - Optional data object to log (no redaction applied)
|
|
150
|
+
*/
|
|
151
|
+
infoRaw(message: string, data?: LogData): void;
|
|
152
|
+
/**
|
|
153
|
+
* Log a warning message without data redaction
|
|
154
|
+
* @param message - The warning message to log
|
|
155
|
+
* @param data - Optional data object to log (no redaction applied)
|
|
156
|
+
*/
|
|
157
|
+
warnRaw(message: string, data?: LogData): void;
|
|
158
|
+
/**
|
|
159
|
+
* Log an error message without data redaction
|
|
160
|
+
* @param message - The error message to log
|
|
161
|
+
* @param data - Optional data object to log (no redaction applied)
|
|
162
|
+
*/
|
|
163
|
+
errorRaw(message: string, data?: LogData): void;
|
|
164
|
+
/**
|
|
165
|
+
* Log a message without data redaction (always outputs unless mode is OFF)
|
|
166
|
+
* @param message - The log message to output
|
|
167
|
+
* @param data - Optional data object to log (no redaction applied)
|
|
168
|
+
*/
|
|
169
|
+
logRaw(message: string, data?: LogData): void;
|
|
170
|
+
}
|
|
171
|
+
//# 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,EAAwD,OAAO,EAAE,MAAM,UAAU,CAAC;AAO1H;;;GAGG;AACH,qBAAa,MAAM;IACjB,OAAO,CAAC,aAAa,CAAsB;IAC3C,OAAO,CAAC,YAAY,CAA6B;IAEjD;;SAEK;;IAKL;;;OAGG;IACH,OAAO,CAAC,eAAe;IAOvB;;OAEG;IACH,OAAO,CAAC,qBAAqB;IAI7B;;;;;;;OAOG;IACH,OAAO,CAAC,aAAa;IAKrB;;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;IAa9C;;;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"}
|
|
@@ -0,0 +1,398 @@
|
|
|
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 { LogLevel, LogMode } from '../types/index.js';
|
|
9
|
+
import { LogFormatter } from '../formatter/index.js';
|
|
10
|
+
import { DataRedactor, RedactionController, defaultRedactionConfig } from '../redaction/index.js';
|
|
11
|
+
import { LoggerConfigManager } from './config.js';
|
|
12
|
+
import { LogFilter } from './filtering.js';
|
|
13
|
+
import { createBuiltInHandler } from './advanced-outputs.js';
|
|
14
|
+
/**
|
|
15
|
+
* Logger class responsible for managing log output and configuration
|
|
16
|
+
* Provides mode-based filtering and formatted console output
|
|
17
|
+
*/
|
|
18
|
+
export class Logger {
|
|
19
|
+
/**
|
|
20
|
+
* Logger constructor - sets up environment-based auto-configuration
|
|
21
|
+
*/
|
|
22
|
+
constructor() {
|
|
23
|
+
this.cachedConfig = null;
|
|
24
|
+
this.configManager = new LoggerConfigManager();
|
|
25
|
+
}
|
|
26
|
+
/**
|
|
27
|
+
* Get cached configuration or refresh cache if needed
|
|
28
|
+
* This avoids repeated getConfig() calls for better performance
|
|
29
|
+
*/
|
|
30
|
+
getCachedConfig() {
|
|
31
|
+
if (this.cachedConfig === null) {
|
|
32
|
+
this.cachedConfig = this.configManager.getConfig();
|
|
33
|
+
}
|
|
34
|
+
return this.cachedConfig;
|
|
35
|
+
}
|
|
36
|
+
/**
|
|
37
|
+
* Invalidate the configuration cache when configuration changes
|
|
38
|
+
*/
|
|
39
|
+
invalidateConfigCache() {
|
|
40
|
+
this.cachedConfig = null;
|
|
41
|
+
}
|
|
42
|
+
/**
|
|
43
|
+
* Helper method to format log messages with cached configuration
|
|
44
|
+
* Reduces code duplication across all log methods
|
|
45
|
+
* @param level - The log level to format for
|
|
46
|
+
* @param message - The message content to format
|
|
47
|
+
* @param data - Optional data object to include in the log output
|
|
48
|
+
* @returns Formatted string with appropriate configuration applied
|
|
49
|
+
*/
|
|
50
|
+
formatMessage(level, message, data) {
|
|
51
|
+
const cachedConfig = this.getCachedConfig();
|
|
52
|
+
return LogFormatter.format(level, message, data, cachedConfig.format);
|
|
53
|
+
}
|
|
54
|
+
/**
|
|
55
|
+
* Built-in output handlers for common use cases
|
|
56
|
+
*/
|
|
57
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
58
|
+
getBuiltInHandler(type, config) {
|
|
59
|
+
switch (type) {
|
|
60
|
+
case 'console':
|
|
61
|
+
return (level, message, data) => {
|
|
62
|
+
// Use appropriate console method based on level
|
|
63
|
+
if (level === 'error') {
|
|
64
|
+
if (data !== undefined) {
|
|
65
|
+
console.error(message, data);
|
|
66
|
+
}
|
|
67
|
+
else {
|
|
68
|
+
console.error(message);
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
else if (level === 'warn') {
|
|
72
|
+
if (data !== undefined) {
|
|
73
|
+
console.warn(message, data);
|
|
74
|
+
}
|
|
75
|
+
else {
|
|
76
|
+
console.warn(message);
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
else {
|
|
80
|
+
if (data !== undefined) {
|
|
81
|
+
console.log(message, data);
|
|
82
|
+
}
|
|
83
|
+
else {
|
|
84
|
+
console.log(message);
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
};
|
|
88
|
+
case 'silent':
|
|
89
|
+
return () => {
|
|
90
|
+
// Do nothing - silent output
|
|
91
|
+
};
|
|
92
|
+
case 'file':
|
|
93
|
+
case 'http':
|
|
94
|
+
// Use advanced output handlers for file and http
|
|
95
|
+
return createBuiltInHandler(type, config);
|
|
96
|
+
default:
|
|
97
|
+
return null;
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
/**
|
|
101
|
+
* Process a single output target with error handling
|
|
102
|
+
* @param output - Single output target to process
|
|
103
|
+
* @param level - Log level
|
|
104
|
+
* @param rawMessage - Original unformatted message
|
|
105
|
+
* @param formattedMessage - Formatted message for console-based outputs
|
|
106
|
+
* @param data - Optional data
|
|
107
|
+
* @param isEnhanced - Whether this is an enhanced output (supports configured handler objects)
|
|
108
|
+
*/
|
|
109
|
+
processSingleOutput(output, level, rawMessage, formattedMessage, data, isEnhanced = false) {
|
|
110
|
+
const config = this.configManager.getConfig();
|
|
111
|
+
try {
|
|
112
|
+
if (typeof output === 'string') {
|
|
113
|
+
// Built-in handler - get config if available
|
|
114
|
+
const outputConfig = config.advancedOutputConfig?.[output];
|
|
115
|
+
const handler = this.getBuiltInHandler(output, outputConfig);
|
|
116
|
+
if (handler) {
|
|
117
|
+
// Advanced handlers (file, http) get raw message, console gets formatted
|
|
118
|
+
const messageToUse = (output === 'file' || output === 'http') ? rawMessage : formattedMessage;
|
|
119
|
+
handler(level, messageToUse, data);
|
|
120
|
+
}
|
|
121
|
+
else {
|
|
122
|
+
console.error('[LogEngine] Unknown built-in output handler:', JSON.stringify(output));
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
else if (typeof output === 'function') {
|
|
126
|
+
// Custom function handler gets formatted message for backward compatibility
|
|
127
|
+
output(level, formattedMessage, data);
|
|
128
|
+
}
|
|
129
|
+
else if (isEnhanced && typeof output === 'object' && output.type && output.config) {
|
|
130
|
+
// Configured handler object (only available for enhanced outputs)
|
|
131
|
+
const handler = this.getBuiltInHandler(output.type, output.config);
|
|
132
|
+
if (handler) {
|
|
133
|
+
// Advanced configured handlers get raw message
|
|
134
|
+
handler(level, rawMessage, data);
|
|
135
|
+
}
|
|
136
|
+
else {
|
|
137
|
+
console.error('[LogEngine] Unknown enhanced output handler type:', JSON.stringify(output));
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
else {
|
|
141
|
+
const outputType = isEnhanced ? 'enhanced output target' : 'output target';
|
|
142
|
+
console.error(`[LogEngine] Invalid ${outputType}:`, output);
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
catch (error) {
|
|
146
|
+
// Continue processing other outputs even if one fails
|
|
147
|
+
const handlerType = isEnhanced ? 'Enhanced output' : 'Output';
|
|
148
|
+
console.error(`[LogEngine] ${handlerType} handler failed: ${error}`);
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
/**
|
|
152
|
+
* Process multiple output targets
|
|
153
|
+
* @param outputs - Array of output targets to process
|
|
154
|
+
* @param level - Log level
|
|
155
|
+
* @param rawMessage - Original unformatted message
|
|
156
|
+
* @param formattedMessage - Formatted message for console-based outputs
|
|
157
|
+
* @param data - Optional data
|
|
158
|
+
*/
|
|
159
|
+
processOutputs(outputs, level, rawMessage, formattedMessage, data) {
|
|
160
|
+
for (const output of outputs) {
|
|
161
|
+
this.processSingleOutput(output, level, rawMessage, formattedMessage, data, false);
|
|
162
|
+
}
|
|
163
|
+
}
|
|
164
|
+
/**
|
|
165
|
+
* Process enhanced output targets
|
|
166
|
+
* @param enhancedOutputs - Array of enhanced output targets to process
|
|
167
|
+
* @param level - Log level
|
|
168
|
+
* @param rawMessage - Original unformatted message
|
|
169
|
+
* @param formattedMessage - Formatted message for console-based outputs
|
|
170
|
+
* @param data - Optional data
|
|
171
|
+
*/
|
|
172
|
+
processEnhancedOutputs(enhancedOutputs, level, rawMessage, formattedMessage, data) {
|
|
173
|
+
for (const output of enhancedOutputs) {
|
|
174
|
+
this.processSingleOutput(output, level, rawMessage, formattedMessage, data, true);
|
|
175
|
+
}
|
|
176
|
+
}
|
|
177
|
+
/**
|
|
178
|
+
* Updates logger configuration with new settings
|
|
179
|
+
* Also updates redaction configuration based on environment
|
|
180
|
+
* @param config - Partial configuration object to apply
|
|
181
|
+
*/
|
|
182
|
+
configure(config) {
|
|
183
|
+
this.configManager.updateConfig(config);
|
|
184
|
+
// Invalidate configuration cache since config has changed
|
|
185
|
+
this.invalidateConfigCache();
|
|
186
|
+
// Update redaction configuration based on current environment
|
|
187
|
+
DataRedactor.updateConfig({
|
|
188
|
+
...defaultRedactionConfig,
|
|
189
|
+
...RedactionController.getEnvironmentConfig()
|
|
190
|
+
});
|
|
191
|
+
}
|
|
192
|
+
/**
|
|
193
|
+
* Get current logger configuration
|
|
194
|
+
* @returns Current logger configuration
|
|
195
|
+
*/
|
|
196
|
+
getConfig() {
|
|
197
|
+
return this.configManager.getConfig();
|
|
198
|
+
}
|
|
199
|
+
/**
|
|
200
|
+
* Determines if a message should be logged based on current log mode
|
|
201
|
+
* @param level - The log level of the message to check
|
|
202
|
+
* @returns true if message should be logged, false otherwise
|
|
203
|
+
*/
|
|
204
|
+
shouldLog(level) {
|
|
205
|
+
const currentConfig = this.configManager.getConfig();
|
|
206
|
+
const currentMode = currentConfig.mode !== undefined ? currentConfig.mode : LogMode.INFO;
|
|
207
|
+
return LogFilter.shouldLog(level, currentMode);
|
|
208
|
+
}
|
|
209
|
+
/**
|
|
210
|
+
* Writes log output using configured output handler or default console methods
|
|
211
|
+
* Supports single output handler, multiple outputs, and enhanced outputs
|
|
212
|
+
* Priority: outputs > enhancedOutputs > outputHandler > default console
|
|
213
|
+
* @param level - The log level as a string
|
|
214
|
+
* @param rawMessage - The original unformatted message
|
|
215
|
+
* @param formattedMessage - The pre-formatted message to output
|
|
216
|
+
* @param data - Optional data object that was logged
|
|
217
|
+
* @param isError - Whether this is an error level message (for console.error)
|
|
218
|
+
* @param isWarn - Whether this is a warning level message (for console.warn)
|
|
219
|
+
*/
|
|
220
|
+
writeToOutput(level, rawMessage, formattedMessage, data, isError = false, isWarn = false) {
|
|
221
|
+
const config = this.configManager.getConfig();
|
|
222
|
+
// Multiple outputs support (highest priority - newer API)
|
|
223
|
+
if (config.outputs !== undefined) {
|
|
224
|
+
if (config.outputs.length > 0) {
|
|
225
|
+
// Process outputs array when it has actual outputs
|
|
226
|
+
this.processOutputs(config.outputs, level, rawMessage, formattedMessage, data);
|
|
227
|
+
}
|
|
228
|
+
// If outputs is explicitly set to empty array, disable all logging
|
|
229
|
+
return;
|
|
230
|
+
}
|
|
231
|
+
// Enhanced outputs with advanced configuration (second priority)
|
|
232
|
+
if (config.enhancedOutputs !== undefined && config.enhancedOutputs.length > 0) {
|
|
233
|
+
this.processEnhancedOutputs(config.enhancedOutputs, level, rawMessage, formattedMessage, data);
|
|
234
|
+
return;
|
|
235
|
+
}
|
|
236
|
+
// Single output handler (third priority - legacy compatibility)
|
|
237
|
+
if (config.outputHandler) {
|
|
238
|
+
try {
|
|
239
|
+
config.outputHandler(level, formattedMessage, data);
|
|
240
|
+
}
|
|
241
|
+
catch (error) {
|
|
242
|
+
// Fallback to console if custom handler fails
|
|
243
|
+
console.error(`[LogEngine] Output handler failed: ${error}. Falling back to console.`);
|
|
244
|
+
if (isError) {
|
|
245
|
+
console.error(formattedMessage);
|
|
246
|
+
}
|
|
247
|
+
else if (isWarn) {
|
|
248
|
+
console.warn(formattedMessage);
|
|
249
|
+
}
|
|
250
|
+
else {
|
|
251
|
+
console.log(formattedMessage);
|
|
252
|
+
}
|
|
253
|
+
}
|
|
254
|
+
return;
|
|
255
|
+
}
|
|
256
|
+
// Default: Console output (unless suppressed)
|
|
257
|
+
if (!config.suppressConsoleOutput) {
|
|
258
|
+
if (isError) {
|
|
259
|
+
console.error(formattedMessage);
|
|
260
|
+
}
|
|
261
|
+
else if (isWarn) {
|
|
262
|
+
console.warn(formattedMessage);
|
|
263
|
+
}
|
|
264
|
+
else {
|
|
265
|
+
console.log(formattedMessage);
|
|
266
|
+
}
|
|
267
|
+
}
|
|
268
|
+
// If suppressConsoleOutput is true and no outputHandler/outputs, do nothing (silent)
|
|
269
|
+
}
|
|
270
|
+
/**
|
|
271
|
+
* Log a debug message with DEBUG level formatting
|
|
272
|
+
* Uses console.log for output with purple/magenta coloring
|
|
273
|
+
* Automatically redacts sensitive data when provided
|
|
274
|
+
* @param message - The debug message to log
|
|
275
|
+
* @param data - Optional data object to log (will be redacted)
|
|
276
|
+
*/
|
|
277
|
+
debug(message, data) {
|
|
278
|
+
if (this.shouldLog(LogLevel.DEBUG)) {
|
|
279
|
+
const processedData = DataRedactor.redactData(data);
|
|
280
|
+
const formatted = this.formatMessage(LogLevel.DEBUG, message, processedData);
|
|
281
|
+
this.writeToOutput('debug', message, formatted, processedData);
|
|
282
|
+
}
|
|
283
|
+
}
|
|
284
|
+
/**
|
|
285
|
+
* Log an informational message with INFO level formatting
|
|
286
|
+
* Uses console.log for output with blue coloring
|
|
287
|
+
* Automatically redacts sensitive data when provided
|
|
288
|
+
* @param message - The info message to log
|
|
289
|
+
* @param data - Optional data object to log (will be redacted)
|
|
290
|
+
*/
|
|
291
|
+
info(message, data) {
|
|
292
|
+
if (this.shouldLog(LogLevel.INFO)) {
|
|
293
|
+
const processedData = DataRedactor.redactData(data);
|
|
294
|
+
const formatted = this.formatMessage(LogLevel.INFO, message, processedData);
|
|
295
|
+
this.writeToOutput('info', message, formatted, processedData);
|
|
296
|
+
}
|
|
297
|
+
}
|
|
298
|
+
/**
|
|
299
|
+
* Log a warning message with WARN level formatting
|
|
300
|
+
* Uses console.warn for output with yellow coloring
|
|
301
|
+
* Automatically redacts sensitive data when provided
|
|
302
|
+
* @param message - The warning message to log
|
|
303
|
+
* @param data - Optional data object to log (will be redacted)
|
|
304
|
+
*/
|
|
305
|
+
warn(message, data) {
|
|
306
|
+
if (this.shouldLog(LogLevel.WARN)) {
|
|
307
|
+
const processedData = DataRedactor.redactData(data);
|
|
308
|
+
const formatted = this.formatMessage(LogLevel.WARN, message, processedData);
|
|
309
|
+
this.writeToOutput('warn', message, formatted, processedData, false, true);
|
|
310
|
+
}
|
|
311
|
+
}
|
|
312
|
+
/**
|
|
313
|
+
* Log an error message with ERROR level formatting
|
|
314
|
+
* Uses console.error for output with red coloring
|
|
315
|
+
* Automatically redacts sensitive data when provided
|
|
316
|
+
* @param message - The error message to log
|
|
317
|
+
* @param data - Optional data object to log (will be redacted)
|
|
318
|
+
*/
|
|
319
|
+
error(message, data) {
|
|
320
|
+
if (this.shouldLog(LogLevel.ERROR)) {
|
|
321
|
+
const processedData = DataRedactor.redactData(data);
|
|
322
|
+
const formatted = this.formatMessage(LogLevel.ERROR, message, processedData);
|
|
323
|
+
this.writeToOutput('error', message, formatted, processedData, true, false);
|
|
324
|
+
}
|
|
325
|
+
}
|
|
326
|
+
/**
|
|
327
|
+
* Log a message with LOG level formatting (always outputs unless mode is OFF)
|
|
328
|
+
* Uses console.log for output with green coloring
|
|
329
|
+
* LOG level bypasses normal filtering and always outputs (except when OFF is set)
|
|
330
|
+
* Automatically redacts sensitive data when provided
|
|
331
|
+
* @param message - The log message to output
|
|
332
|
+
* @param data - Optional data object to log (will be redacted)
|
|
333
|
+
*/
|
|
334
|
+
log(message, data) {
|
|
335
|
+
if (this.shouldLog(LogLevel.LOG)) {
|
|
336
|
+
const processedData = DataRedactor.redactData(data);
|
|
337
|
+
const formatted = this.formatMessage(LogLevel.LOG, message, processedData);
|
|
338
|
+
this.writeToOutput('log', message, formatted, processedData);
|
|
339
|
+
}
|
|
340
|
+
}
|
|
341
|
+
// Raw logging methods (bypass redaction for debugging)
|
|
342
|
+
/**
|
|
343
|
+
* Log a debug message without data redaction
|
|
344
|
+
* @param message - The debug message to log
|
|
345
|
+
* @param data - Optional data object to log (no redaction applied)
|
|
346
|
+
*/
|
|
347
|
+
debugRaw(message, data) {
|
|
348
|
+
if (this.shouldLog(LogLevel.DEBUG)) {
|
|
349
|
+
const formatted = this.formatMessage(LogLevel.DEBUG, message, data);
|
|
350
|
+
this.writeToOutput('debug', message, formatted, data);
|
|
351
|
+
}
|
|
352
|
+
}
|
|
353
|
+
/**
|
|
354
|
+
* Log an info message without data redaction
|
|
355
|
+
* @param message - The info message to log
|
|
356
|
+
* @param data - Optional data object to log (no redaction applied)
|
|
357
|
+
*/
|
|
358
|
+
infoRaw(message, data) {
|
|
359
|
+
if (this.shouldLog(LogLevel.INFO)) {
|
|
360
|
+
const formatted = this.formatMessage(LogLevel.INFO, message, data);
|
|
361
|
+
this.writeToOutput('info', message, formatted, data);
|
|
362
|
+
}
|
|
363
|
+
}
|
|
364
|
+
/**
|
|
365
|
+
* Log a warning message without data redaction
|
|
366
|
+
* @param message - The warning message to log
|
|
367
|
+
* @param data - Optional data object to log (no redaction applied)
|
|
368
|
+
*/
|
|
369
|
+
warnRaw(message, data) {
|
|
370
|
+
if (this.shouldLog(LogLevel.WARN)) {
|
|
371
|
+
const formatted = this.formatMessage(LogLevel.WARN, message, data);
|
|
372
|
+
this.writeToOutput('warn', message, formatted, data, false, true);
|
|
373
|
+
}
|
|
374
|
+
}
|
|
375
|
+
/**
|
|
376
|
+
* Log an error message without data redaction
|
|
377
|
+
* @param message - The error message to log
|
|
378
|
+
* @param data - Optional data object to log (no redaction applied)
|
|
379
|
+
*/
|
|
380
|
+
errorRaw(message, data) {
|
|
381
|
+
if (this.shouldLog(LogLevel.ERROR)) {
|
|
382
|
+
const formatted = this.formatMessage(LogLevel.ERROR, message, data);
|
|
383
|
+
this.writeToOutput('error', message, formatted, data, true, false);
|
|
384
|
+
}
|
|
385
|
+
}
|
|
386
|
+
/**
|
|
387
|
+
* Log a message without data redaction (always outputs unless mode is OFF)
|
|
388
|
+
* @param message - The log message to output
|
|
389
|
+
* @param data - Optional data object to log (no redaction applied)
|
|
390
|
+
*/
|
|
391
|
+
logRaw(message, data) {
|
|
392
|
+
if (this.shouldLog(LogLevel.LOG)) {
|
|
393
|
+
const formatted = this.formatMessage(LogLevel.LOG, message, data);
|
|
394
|
+
this.writeToOutput('log', message, formatted, data);
|
|
395
|
+
}
|
|
396
|
+
}
|
|
397
|
+
}
|
|
398
|
+
//# sourceMappingURL=core.js.map
|