@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.
Files changed (52) hide show
  1. package/LICENSE +21 -661
  2. package/README.md +279 -14
  3. package/dist/formatter/colors.d.ts +32 -0
  4. package/dist/formatter/colors.d.ts.map +1 -0
  5. package/dist/formatter/colors.js +34 -0
  6. package/dist/formatter/data-formatter.d.ts +25 -0
  7. package/dist/formatter/data-formatter.d.ts.map +1 -0
  8. package/dist/formatter/data-formatter.js +53 -0
  9. package/dist/formatter/index.d.ts +10 -0
  10. package/dist/formatter/index.d.ts.map +1 -0
  11. package/dist/formatter/index.js +21 -0
  12. package/dist/{formatter.d.ts → formatter/message-formatter.d.ts} +10 -10
  13. package/dist/formatter/message-formatter.d.ts.map +1 -0
  14. package/dist/formatter/message-formatter.js +87 -0
  15. package/dist/formatter/timestamp.d.ts +27 -0
  16. package/dist/formatter/timestamp.d.ts.map +1 -0
  17. package/dist/formatter/timestamp.js +39 -0
  18. package/dist/index.d.ts +143 -41
  19. package/dist/index.d.ts.map +1 -1
  20. package/dist/index.js +155 -71
  21. package/dist/logger/config.d.ts +42 -0
  22. package/dist/logger/config.d.ts.map +1 -0
  23. package/dist/logger/config.js +101 -0
  24. package/dist/logger/core.d.ts +108 -0
  25. package/dist/logger/core.d.ts.map +1 -0
  26. package/dist/logger/core.js +185 -0
  27. package/dist/logger/environment.d.ts +36 -0
  28. package/dist/logger/environment.d.ts.map +1 -0
  29. package/dist/logger/environment.js +61 -0
  30. package/dist/logger/filtering.d.ts +36 -0
  31. package/dist/logger/filtering.d.ts.map +1 -0
  32. package/dist/logger/filtering.js +65 -0
  33. package/dist/logger/index.d.ts +10 -0
  34. package/dist/logger/index.d.ts.map +1 -0
  35. package/dist/logger/index.js +18 -0
  36. package/dist/redaction/config.d.ts +29 -0
  37. package/dist/redaction/config.d.ts.map +1 -0
  38. package/dist/redaction/config.js +95 -0
  39. package/dist/redaction/index.d.ts +8 -0
  40. package/dist/redaction/index.d.ts.map +1 -0
  41. package/dist/redaction/index.js +12 -0
  42. package/dist/redaction/redactor.d.ts +99 -0
  43. package/dist/redaction/redactor.d.ts.map +1 -0
  44. package/dist/redaction/redactor.js +257 -0
  45. package/dist/types/index.d.ts +164 -0
  46. package/dist/types/index.d.ts.map +1 -1
  47. package/package.json +17 -5
  48. package/dist/formatter.d.ts.map +0 -1
  49. package/dist/formatter.js +0 -103
  50. package/dist/logger.d.ts +0 -72
  51. package/dist/logger.d.ts.map +0 -1
  52. package/dist/logger.js +0 -158
package/dist/formatter.js DELETED
@@ -1,103 +0,0 @@
1
- "use strict";
2
- /**
3
- * Log message formatter that provides colorized console output with timestamps
4
- * Handles ANSI color codes and structured log message formatting
5
- */
6
- Object.defineProperty(exports, "__esModule", { value: true });
7
- exports.LogFormatter = void 0;
8
- const types_1 = require("./types");
9
- /**
10
- * LogFormatter class responsible for formatting log messages with colors and timestamps
11
- * Creates readable, colored console output with ISO timestamps and local time
12
- */
13
- class LogFormatter {
14
- /**
15
- * Formats a log message with timestamp, level indicator, and appropriate coloring
16
- * Creates a structured log entry: [ISO_TIMESTAMP][LOCAL_TIME][LEVEL]: message
17
- * @param level - The log level to format for
18
- * @param message - The message content to format
19
- * @returns Formatted string with ANSI colors and timestamps
20
- */
21
- static format(level, message) {
22
- const now = new Date();
23
- const isoTimestamp = now.toISOString();
24
- const timeString = now.toLocaleTimeString('en-US', {
25
- hour: 'numeric',
26
- minute: '2-digit',
27
- hour12: true
28
- }).replace(/\s+/g, '');
29
- const levelName = this.getLevelName(level);
30
- const levelColor = this.getLevelColor(level);
31
- // Apply colors to each component for better readability
32
- const coloredTimestamp = `${this.colors.gray}[${isoTimestamp}]${this.colors.reset}`;
33
- const coloredTimeString = `${this.colors.cyan}[${timeString}]${this.colors.reset}`;
34
- const coloredLevel = `${levelColor}[${levelName}]${this.colors.reset}`;
35
- return `${coloredTimestamp}${coloredTimeString}${coloredLevel}: ${message}`;
36
- }
37
- /**
38
- * Formats a Log Engine system message with [LOG ENGINE] prefix instead of log levels
39
- * Used for internal messages like deprecation warnings that should be distinguished from user logs
40
- * @param message - The system message content to format
41
- * @returns Formatted string with ANSI colors, timestamps, and LOG ENGINE prefix
42
- */
43
- static formatSystemMessage(message) {
44
- const now = new Date();
45
- const isoTimestamp = now.toISOString();
46
- const timeString = now.toLocaleTimeString('en-US', {
47
- hour: 'numeric',
48
- minute: '2-digit',
49
- hour12: true
50
- }).replace(/\s+/g, '');
51
- // Apply colors to each component for better readability
52
- const coloredTimestamp = `${LogFormatter.colors.gray}[${isoTimestamp}]${LogFormatter.colors.reset}`;
53
- const coloredTimeString = `${LogFormatter.colors.cyan}[${timeString}]${LogFormatter.colors.reset}`;
54
- const coloredLogEngine = `${LogFormatter.colors.yellow}[LOG ENGINE]${LogFormatter.colors.reset}`;
55
- const coloredMessage = `${LogFormatter.colors.yellow}${message}${LogFormatter.colors.reset}`;
56
- return `${coloredTimestamp}${coloredTimeString}${coloredLogEngine}: ${coloredMessage}`;
57
- }
58
- /**
59
- * Converts LogLevel enum to human-readable string
60
- * @param level - The LogLevel to convert
61
- * @returns String representation of the log level
62
- */
63
- static getLevelName(level) {
64
- switch (level) {
65
- case types_1.LogLevel.DEBUG: return 'DEBUG';
66
- case types_1.LogLevel.INFO: return 'INFO';
67
- case types_1.LogLevel.WARN: return 'WARN';
68
- case types_1.LogLevel.ERROR: return 'ERROR';
69
- case types_1.LogLevel.LOG: return 'LOG';
70
- default: return 'UNKNOWN';
71
- }
72
- }
73
- /**
74
- * Maps LogLevel to appropriate ANSI color code
75
- * Colors help quickly identify message severity in console output
76
- * @param level - The LogLevel to get color for
77
- * @returns ANSI color escape sequence
78
- */
79
- static getLevelColor(level) {
80
- switch (level) {
81
- case types_1.LogLevel.DEBUG: return this.colors.magenta; // Purple for debug info
82
- case types_1.LogLevel.INFO: return this.colors.blue; // Blue for general info
83
- case types_1.LogLevel.WARN: return this.colors.yellow; // Yellow for warnings
84
- case types_1.LogLevel.ERROR: return this.colors.red; // Red for errors
85
- case types_1.LogLevel.LOG: return this.colors.green; // Green for always-on log messages
86
- default: return this.colors.white; // White for unknown levels
87
- }
88
- }
89
- }
90
- exports.LogFormatter = LogFormatter;
91
- // ANSI color codes for terminal output styling
92
- LogFormatter.colors = {
93
- reset: '\x1b[0m', // Reset all formatting
94
- dim: '\x1b[2m', // Dim/faded text
95
- red: '\x1b[31m', // Red text (errors)
96
- yellow: '\x1b[33m', // Yellow text (warnings)
97
- blue: '\x1b[34m', // Blue text (info)
98
- magenta: '\x1b[35m', // Magenta text (debug)
99
- cyan: '\x1b[36m', // Cyan text (timestamps)
100
- white: '\x1b[37m', // White text (default)
101
- gray: '\x1b[90m', // Gray text (timestamps)
102
- green: '\x1b[32m' // Green text (log level)
103
- };
package/dist/logger.d.ts DELETED
@@ -1,72 +0,0 @@
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
- */
7
- import { LoggerConfig } from './types';
8
- /**
9
- * Logger class responsible for managing log output and configuration
10
- * Provides mode-based filtering and formatted console output
11
- */
12
- export declare class Logger {
13
- private config;
14
- /**
15
- * Updates logger configuration with new settings
16
- * Merges provided config with existing settings (partial update)
17
- * Supports backwards compatibility by mapping level to mode with deprecation warnings
18
- * @param config - Partial configuration object to apply
19
- */
20
- configure(config: Partial<LoggerConfig>): void;
21
- /**
22
- * Maps LogLevel values to severity ranks for consistent comparison
23
- * This prevents issues if enum numeric values change in the future
24
- */
25
- private static readonly SEVERITY_RANKS;
26
- /**
27
- * Maps LogMode values to minimum severity rank required for output
28
- * This defines the filtering threshold for each mode
29
- */
30
- private static readonly MODE_THRESHOLDS;
31
- /**
32
- * Determines if a message should be logged based on current log mode
33
- * Messages are shown only if their level is appropriate for the configured mode
34
- * LOG level is special - it always outputs regardless of configured mode (except when OFF is set)
35
- * OFF mode disables all logging including LOG level messages
36
- * @param level - The log level of the message to check
37
- * @returns true if message should be logged, false otherwise
38
- */
39
- private shouldLog;
40
- /**
41
- * Log a debug message with DEBUG level formatting
42
- * Uses console.log for output with purple/magenta coloring
43
- * @param message - The debug message to log
44
- */
45
- debug(message: string): void;
46
- /**
47
- * Log an informational message with INFO level formatting
48
- * Uses console.log for output with blue coloring
49
- * @param message - The info message to log
50
- */
51
- info(message: string): void;
52
- /**
53
- * Log a warning message with WARN level formatting
54
- * Uses console.warn for output with yellow coloring
55
- * @param message - The warning message to log
56
- */
57
- warn(message: string): void;
58
- /**
59
- * Log an error message with ERROR level formatting
60
- * Uses console.error for output with red coloring
61
- * @param message - The error message to log
62
- */
63
- error(message: string): void;
64
- /**
65
- * Log a critical message that always outputs (LOG level)
66
- * Uses console.log for output with green coloring
67
- * Always shown regardless of configured log level
68
- * @param message - The critical log message to log
69
- */
70
- log(message: string): void;
71
- }
72
- //# sourceMappingURL=logger.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"logger.d.ts","sourceRoot":"","sources":["../src/logger.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,EAAqB,YAAY,EAAE,MAAM,SAAS,CAAC;AAG1D;;;GAGG;AACH,qBAAa,MAAM;IAEf,OAAO,CAAC,MAAM,CAEZ;IAEF;;;;;OAKG;IACH,SAAS,CAAC,MAAM,EAAE,OAAO,CAAC,YAAY,CAAC,GAAG,IAAI;IAmC9C;;;OAGG;IACH,OAAO,CAAC,MAAM,CAAC,QAAQ,CAAC,cAAc,CAMpC;IAEF;;;OAGG;IACH,OAAO,CAAC,MAAM,CAAC,QAAQ,CAAC,eAAe,CAOrC;IAEF;;;;;;;OAOG;IACH,OAAO,CAAC,SAAS;IAajB;;;;OAIG;IACH,KAAK,CAAC,OAAO,EAAE,MAAM,GAAG,IAAI;IAO5B;;;;OAIG;IACH,IAAI,CAAC,OAAO,EAAE,MAAM,GAAG,IAAI;IAO3B;;;;OAIG;IACH,IAAI,CAAC,OAAO,EAAE,MAAM,GAAG,IAAI;IAO3B;;;;OAIG;IACH,KAAK,CAAC,OAAO,EAAE,MAAM,GAAG,IAAI;IAO5B;;;;;OAKG;IACH,GAAG,CAAC,OAAO,EAAE,MAAM,GAAG,IAAI;CAM7B"}
package/dist/logger.js DELETED
@@ -1,158 +0,0 @@
1
- "use strict";
2
- /**
3
- * Core Logger class that handles log message output with configurable levels
4
- * Supports DEBUG, INFO, WARN, ERROR, and LOG levels with intelligent filtering
5
- * LOG level always outputs regardless of configuration
6
- * Uses colorized console output with timestamps for better readability
7
- */
8
- Object.defineProperty(exports, "__esModule", { value: true });
9
- exports.Logger = void 0;
10
- const types_1 = require("./types");
11
- const formatter_1 = require("./formatter");
12
- /**
13
- * Logger class responsible for managing log output and configuration
14
- * Provides mode-based filtering and formatted console output
15
- */
16
- class Logger {
17
- constructor() {
18
- // Internal configuration state with sensible defaults
19
- this.config = {
20
- mode: types_1.LogMode.INFO
21
- };
22
- }
23
- /**
24
- * Updates logger configuration with new settings
25
- * Merges provided config with existing settings (partial update)
26
- * Supports backwards compatibility by mapping level to mode with deprecation warnings
27
- * @param config - Partial configuration object to apply
28
- */
29
- configure(config) {
30
- // Handle backwards compatibility - if level is provided but mode is not
31
- if (config.level !== undefined && config.mode === undefined) {
32
- // Only show deprecation warning in non-test environments
33
- if (process.env.NODE_ENV !== 'test') {
34
- console.warn(formatter_1.LogFormatter.formatSystemMessage('⚠️ DEPRECATION WARNING: The "level" configuration is deprecated and will be removed in v2.0.0. Please use "mode" instead.'));
35
- console.warn(formatter_1.LogFormatter.formatSystemMessage(' Migration: LogEngine.configure({ level: LogLevel.DEBUG }) → LogEngine.configure({ mode: LogMode.DEBUG })'));
36
- console.warn(formatter_1.LogFormatter.formatSystemMessage(' See: https://github.com/wgtechlabs/log-engine#migration-guide-loglevel--logmode'));
37
- }
38
- // Map legacy level values to new LogMode values (including SILENT=4, OFF=5)
39
- // This provides backwards compatibility for all legacy values
40
- const levelValue = config.level;
41
- const levelToModeMap = {
42
- [types_1.LogLevel.DEBUG]: types_1.LogMode.DEBUG, // 0 -> 0
43
- [types_1.LogLevel.INFO]: types_1.LogMode.INFO, // 1 -> 1
44
- [types_1.LogLevel.WARN]: types_1.LogMode.WARN, // 2 -> 2
45
- [types_1.LogLevel.ERROR]: types_1.LogMode.ERROR, // 3 -> 3
46
- [types_1.LogLevel.LOG]: types_1.LogMode.SILENT, // 99 -> 4 (preserves critical-only behavior)
47
- 4: types_1.LogMode.SILENT, // Legacy SILENT -> 4
48
- 5: types_1.LogMode.OFF // Legacy OFF -> 5
49
- };
50
- const mappedMode = levelToModeMap[levelValue];
51
- if (mappedMode === undefined) {
52
- 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.`);
53
- }
54
- this.config = { ...this.config, mode: mappedMode };
55
- }
56
- else {
57
- // Normal configuration update
58
- this.config = { ...this.config, ...config };
59
- }
60
- }
61
- /**
62
- * Determines if a message should be logged based on current log mode
63
- * Messages are shown only if their level is appropriate for the configured mode
64
- * LOG level is special - it always outputs regardless of configured mode (except when OFF is set)
65
- * OFF mode disables all logging including LOG level messages
66
- * @param level - The log level of the message to check
67
- * @returns true if message should be logged, false otherwise
68
- */
69
- shouldLog(level) {
70
- const currentMode = this.config.mode !== undefined ? this.config.mode : types_1.LogMode.INFO;
71
- // Get the severity rank for the message level
72
- const messageSeverity = Logger.SEVERITY_RANKS[level];
73
- // Get the minimum severity threshold for the current mode
74
- const modeThreshold = Logger.MODE_THRESHOLDS[currentMode];
75
- // Allow the message if its severity meets or exceeds the mode threshold
76
- return messageSeverity >= modeThreshold;
77
- }
78
- /**
79
- * Log a debug message with DEBUG level formatting
80
- * Uses console.log for output with purple/magenta coloring
81
- * @param message - The debug message to log
82
- */
83
- debug(message) {
84
- if (this.shouldLog(types_1.LogLevel.DEBUG)) {
85
- const formatted = formatter_1.LogFormatter.format(types_1.LogLevel.DEBUG, message);
86
- console.log(formatted);
87
- }
88
- }
89
- /**
90
- * Log an informational message with INFO level formatting
91
- * Uses console.log for output with blue coloring
92
- * @param message - The info message to log
93
- */
94
- info(message) {
95
- if (this.shouldLog(types_1.LogLevel.INFO)) {
96
- const formatted = formatter_1.LogFormatter.format(types_1.LogLevel.INFO, message);
97
- console.log(formatted);
98
- }
99
- }
100
- /**
101
- * Log a warning message with WARN level formatting
102
- * Uses console.warn for output with yellow coloring
103
- * @param message - The warning message to log
104
- */
105
- warn(message) {
106
- if (this.shouldLog(types_1.LogLevel.WARN)) {
107
- const formatted = formatter_1.LogFormatter.format(types_1.LogLevel.WARN, message);
108
- console.warn(formatted);
109
- }
110
- }
111
- /**
112
- * Log an error message with ERROR level formatting
113
- * Uses console.error for output with red coloring
114
- * @param message - The error message to log
115
- */
116
- error(message) {
117
- if (this.shouldLog(types_1.LogLevel.ERROR)) {
118
- const formatted = formatter_1.LogFormatter.format(types_1.LogLevel.ERROR, message);
119
- console.error(formatted);
120
- }
121
- }
122
- /**
123
- * Log a critical message that always outputs (LOG level)
124
- * Uses console.log for output with green coloring
125
- * Always shown regardless of configured log level
126
- * @param message - The critical log message to log
127
- */
128
- log(message) {
129
- if (this.shouldLog(types_1.LogLevel.LOG)) {
130
- const formatted = formatter_1.LogFormatter.format(types_1.LogLevel.LOG, message);
131
- console.log(formatted);
132
- }
133
- }
134
- }
135
- exports.Logger = Logger;
136
- /**
137
- * Maps LogLevel values to severity ranks for consistent comparison
138
- * This prevents issues if enum numeric values change in the future
139
- */
140
- Logger.SEVERITY_RANKS = {
141
- [types_1.LogLevel.DEBUG]: 0,
142
- [types_1.LogLevel.INFO]: 1,
143
- [types_1.LogLevel.WARN]: 2,
144
- [types_1.LogLevel.ERROR]: 3,
145
- [types_1.LogLevel.LOG]: 99 // Special case - always outputs (except when OFF)
146
- };
147
- /**
148
- * Maps LogMode values to minimum severity rank required for output
149
- * This defines the filtering threshold for each mode
150
- */
151
- Logger.MODE_THRESHOLDS = {
152
- [types_1.LogMode.DEBUG]: 0, // Shows DEBUG and above
153
- [types_1.LogMode.INFO]: 1, // Shows INFO and above
154
- [types_1.LogMode.WARN]: 2, // Shows WARN and above
155
- [types_1.LogMode.ERROR]: 3, // Shows ERROR and above
156
- [types_1.LogMode.SILENT]: 99, // Only shows LOG messages
157
- [types_1.LogMode.OFF]: 100 // Shows nothing
158
- };