@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.
Files changed (36) hide show
  1. package/LICENSE +21 -21
  2. package/README.md +869 -608
  3. package/dist/formatter/data-formatter.d.ts +2 -1
  4. package/dist/formatter/data-formatter.d.ts.map +1 -1
  5. package/dist/formatter/data-formatter.js +1 -1
  6. package/dist/formatter/message-formatter.d.ts +23 -23
  7. package/dist/formatter/message-formatter.d.ts.map +1 -1
  8. package/dist/formatter/message-formatter.js +23 -23
  9. package/dist/formatter/timestamp.d.ts.map +1 -1
  10. package/dist/index.d.ts +130 -136
  11. package/dist/index.d.ts.map +1 -1
  12. package/dist/index.js +108 -108
  13. package/dist/logger/advanced-outputs.d.ts +159 -0
  14. package/dist/logger/advanced-outputs.d.ts.map +1 -0
  15. package/dist/logger/advanced-outputs.js +586 -0
  16. package/dist/logger/config.d.ts +18 -18
  17. package/dist/logger/config.d.ts.map +1 -1
  18. package/dist/logger/config.js +32 -29
  19. package/dist/logger/core.d.ts +128 -84
  20. package/dist/logger/core.d.ts.map +1 -1
  21. package/dist/logger/core.js +259 -74
  22. package/dist/logger/environment.d.ts +15 -15
  23. package/dist/logger/environment.d.ts.map +1 -1
  24. package/dist/logger/environment.js +15 -15
  25. package/dist/logger/filtering.d.ts +16 -16
  26. package/dist/logger/filtering.d.ts.map +1 -1
  27. package/dist/logger/filtering.js +37 -22
  28. package/dist/redaction/config.d.ts +8 -8
  29. package/dist/redaction/config.d.ts.map +1 -1
  30. package/dist/redaction/config.js +8 -8
  31. package/dist/redaction/redactor.d.ts +60 -60
  32. package/dist/redaction/redactor.d.ts.map +1 -1
  33. package/dist/redaction/redactor.js +101 -96
  34. package/dist/types/index.d.ts +98 -16
  35. package/dist/types/index.d.ts.map +1 -1
  36. package/package.json +80 -68
@@ -19,18 +19,18 @@ class LoggerConfigManager {
19
19
  };
20
20
  }
21
21
  /**
22
- * Get current configuration
23
- * @returns Current logger configuration
24
- */
22
+ * Get current configuration
23
+ * @returns Current logger configuration
24
+ */
25
25
  getConfig() {
26
26
  return { ...this.config };
27
27
  }
28
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
- */
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
- * Handle legacy level-based configuration with deprecation warnings
53
- * @param config - Configuration containing legacy level property
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
- * Map legacy LogLevel values to LogMode values
74
- * @param levelValue - Legacy level value
75
- * @returns Corresponding LogMode or undefined if invalid
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
- 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];
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
- * Create deprecation warning message using LogFormatter
91
- * Outputs formatted deprecation warning messages to console
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 v2.0.0. Please use "mode" instead.'));
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
  }
@@ -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
- * Logger constructor - sets up environment-based auto-configuration
17
- */
16
+ * Logger constructor - sets up environment-based auto-configuration
17
+ */
18
18
  constructor();
19
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
- */
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
- * Get current logger configuration
27
- * @returns Current logger configuration
28
- */
58
+ * Get current logger configuration
59
+ * @returns Current logger configuration
60
+ */
29
61
  getConfig(): LoggerConfig;
30
62
  /**
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
- */
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
- * 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;
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","sourceR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