@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
|
@@ -0,0 +1,185 @@
|
|
|
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
|
+
* Includes automatic data redaction for sensitive information
|
|
8
|
+
*/
|
|
9
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
10
|
+
exports.Logger = void 0;
|
|
11
|
+
const types_1 = require("../types");
|
|
12
|
+
const formatter_1 = require("../formatter");
|
|
13
|
+
const redaction_1 = require("../redaction");
|
|
14
|
+
const config_1 = require("./config");
|
|
15
|
+
const filtering_1 = require("./filtering");
|
|
16
|
+
/**
|
|
17
|
+
* Logger class responsible for managing log output and configuration
|
|
18
|
+
* Provides mode-based filtering and formatted console output
|
|
19
|
+
*/
|
|
20
|
+
class Logger {
|
|
21
|
+
/**
|
|
22
|
+
* Logger constructor - sets up environment-based auto-configuration
|
|
23
|
+
*/
|
|
24
|
+
constructor() {
|
|
25
|
+
this.configManager = new config_1.LoggerConfigManager();
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
* Updates logger configuration with new settings
|
|
29
|
+
* Also updates redaction configuration based on environment
|
|
30
|
+
* @param config - Partial configuration object to apply
|
|
31
|
+
*/
|
|
32
|
+
configure(config) {
|
|
33
|
+
this.configManager.updateConfig(config);
|
|
34
|
+
// Update redaction configuration based on current environment
|
|
35
|
+
redaction_1.DataRedactor.updateConfig({
|
|
36
|
+
...redaction_1.defaultRedactionConfig,
|
|
37
|
+
...redaction_1.RedactionController.getEnvironmentConfig()
|
|
38
|
+
});
|
|
39
|
+
}
|
|
40
|
+
/**
|
|
41
|
+
* Get current logger configuration
|
|
42
|
+
* @returns Current logger configuration
|
|
43
|
+
*/
|
|
44
|
+
getConfig() {
|
|
45
|
+
return this.configManager.getConfig();
|
|
46
|
+
}
|
|
47
|
+
/**
|
|
48
|
+
* Determines if a message should be logged based on current log mode
|
|
49
|
+
* @param level - The log level of the message to check
|
|
50
|
+
* @returns true if message should be logged, false otherwise
|
|
51
|
+
*/
|
|
52
|
+
shouldLog(level) {
|
|
53
|
+
const currentConfig = this.configManager.getConfig();
|
|
54
|
+
const currentMode = currentConfig.mode !== undefined ? currentConfig.mode : types_1.LogMode.INFO;
|
|
55
|
+
return filtering_1.LogFilter.shouldLog(level, currentMode);
|
|
56
|
+
}
|
|
57
|
+
/**
|
|
58
|
+
* Log a debug message with DEBUG level formatting
|
|
59
|
+
* Uses console.log for output with purple/magenta coloring
|
|
60
|
+
* Automatically redacts sensitive data when provided
|
|
61
|
+
* @param message - The debug message to log
|
|
62
|
+
* @param data - Optional data object to log (will be redacted)
|
|
63
|
+
*/
|
|
64
|
+
debug(message, data) {
|
|
65
|
+
if (this.shouldLog(types_1.LogLevel.DEBUG)) {
|
|
66
|
+
const processedData = redaction_1.DataRedactor.redactData(data);
|
|
67
|
+
const formatted = formatter_1.LogFormatter.format(types_1.LogLevel.DEBUG, message, processedData);
|
|
68
|
+
console.log(formatted);
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
/**
|
|
72
|
+
* Log an informational message with INFO level formatting
|
|
73
|
+
* Uses console.log for output with blue coloring
|
|
74
|
+
* Automatically redacts sensitive data when provided
|
|
75
|
+
* @param message - The info message to log
|
|
76
|
+
* @param data - Optional data object to log (will be redacted)
|
|
77
|
+
*/
|
|
78
|
+
info(message, data) {
|
|
79
|
+
if (this.shouldLog(types_1.LogLevel.INFO)) {
|
|
80
|
+
const processedData = redaction_1.DataRedactor.redactData(data);
|
|
81
|
+
const formatted = formatter_1.LogFormatter.format(types_1.LogLevel.INFO, message, processedData);
|
|
82
|
+
console.log(formatted);
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
/**
|
|
86
|
+
* Log a warning message with WARN level formatting
|
|
87
|
+
* Uses console.warn for output with yellow coloring
|
|
88
|
+
* Automatically redacts sensitive data when provided
|
|
89
|
+
* @param message - The warning message to log
|
|
90
|
+
* @param data - Optional data object to log (will be redacted)
|
|
91
|
+
*/
|
|
92
|
+
warn(message, data) {
|
|
93
|
+
if (this.shouldLog(types_1.LogLevel.WARN)) {
|
|
94
|
+
const processedData = redaction_1.DataRedactor.redactData(data);
|
|
95
|
+
const formatted = formatter_1.LogFormatter.format(types_1.LogLevel.WARN, message, processedData);
|
|
96
|
+
console.warn(formatted);
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
/**
|
|
100
|
+
* Log an error message with ERROR level formatting
|
|
101
|
+
* Uses console.error for output with red coloring
|
|
102
|
+
* Automatically redacts sensitive data when provided
|
|
103
|
+
* @param message - The error message to log
|
|
104
|
+
* @param data - Optional data object to log (will be redacted)
|
|
105
|
+
*/
|
|
106
|
+
error(message, data) {
|
|
107
|
+
if (this.shouldLog(types_1.LogLevel.ERROR)) {
|
|
108
|
+
const processedData = redaction_1.DataRedactor.redactData(data);
|
|
109
|
+
const formatted = formatter_1.LogFormatter.format(types_1.LogLevel.ERROR, message, processedData);
|
|
110
|
+
console.error(formatted);
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
/**
|
|
114
|
+
* Log a message with LOG level formatting (always outputs unless mode is OFF)
|
|
115
|
+
* Uses console.log for output with green coloring
|
|
116
|
+
* LOG level bypasses normal filtering and always outputs (except when OFF is set)
|
|
117
|
+
* Automatically redacts sensitive data when provided
|
|
118
|
+
* @param message - The log message to output
|
|
119
|
+
* @param data - Optional data object to log (will be redacted)
|
|
120
|
+
*/
|
|
121
|
+
log(message, data) {
|
|
122
|
+
if (this.shouldLog(types_1.LogLevel.LOG)) {
|
|
123
|
+
const processedData = redaction_1.DataRedactor.redactData(data);
|
|
124
|
+
const formatted = formatter_1.LogFormatter.format(types_1.LogLevel.LOG, message, processedData);
|
|
125
|
+
console.log(formatted);
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
// Raw logging methods (bypass redaction for debugging)
|
|
129
|
+
/**
|
|
130
|
+
* Log a debug message without data redaction
|
|
131
|
+
* @param message - The debug message to log
|
|
132
|
+
* @param data - Optional data object to log (no redaction applied)
|
|
133
|
+
*/
|
|
134
|
+
debugRaw(message, data) {
|
|
135
|
+
if (this.shouldLog(types_1.LogLevel.DEBUG)) {
|
|
136
|
+
const formatted = formatter_1.LogFormatter.format(types_1.LogLevel.DEBUG, message, data);
|
|
137
|
+
console.log(formatted);
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
/**
|
|
141
|
+
* Log an info message without data redaction
|
|
142
|
+
* @param message - The info message to log
|
|
143
|
+
* @param data - Optional data object to log (no redaction applied)
|
|
144
|
+
*/
|
|
145
|
+
infoRaw(message, data) {
|
|
146
|
+
if (this.shouldLog(types_1.LogLevel.INFO)) {
|
|
147
|
+
const formatted = formatter_1.LogFormatter.format(types_1.LogLevel.INFO, message, data);
|
|
148
|
+
console.log(formatted);
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
/**
|
|
152
|
+
* Log a warning message without data redaction
|
|
153
|
+
* @param message - The warning message to log
|
|
154
|
+
* @param data - Optional data object to log (no redaction applied)
|
|
155
|
+
*/
|
|
156
|
+
warnRaw(message, data) {
|
|
157
|
+
if (this.shouldLog(types_1.LogLevel.WARN)) {
|
|
158
|
+
const formatted = formatter_1.LogFormatter.format(types_1.LogLevel.WARN, message, data);
|
|
159
|
+
console.warn(formatted);
|
|
160
|
+
}
|
|
161
|
+
}
|
|
162
|
+
/**
|
|
163
|
+
* Log an error message without data redaction
|
|
164
|
+
* @param message - The error message to log
|
|
165
|
+
* @param data - Optional data object to log (no redaction applied)
|
|
166
|
+
*/
|
|
167
|
+
errorRaw(message, data) {
|
|
168
|
+
if (this.shouldLog(types_1.LogLevel.ERROR)) {
|
|
169
|
+
const formatted = formatter_1.LogFormatter.format(types_1.LogLevel.ERROR, message, data);
|
|
170
|
+
console.error(formatted);
|
|
171
|
+
}
|
|
172
|
+
}
|
|
173
|
+
/**
|
|
174
|
+
* Log a message without data redaction (always outputs unless mode is OFF)
|
|
175
|
+
* @param message - The log message to output
|
|
176
|
+
* @param data - Optional data object to log (no redaction applied)
|
|
177
|
+
*/
|
|
178
|
+
logRaw(message, data) {
|
|
179
|
+
if (this.shouldLog(types_1.LogLevel.LOG)) {
|
|
180
|
+
const formatted = formatter_1.LogFormatter.format(types_1.LogLevel.LOG, message, data);
|
|
181
|
+
console.log(formatted);
|
|
182
|
+
}
|
|
183
|
+
}
|
|
184
|
+
}
|
|
185
|
+
exports.Logger = Logger;
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Environment detection utilities for logging configuration
|
|
3
|
+
* Handles automatic environment-based configuration
|
|
4
|
+
*/
|
|
5
|
+
import { LogMode } from '../types';
|
|
6
|
+
/**
|
|
7
|
+
* Environment detection and configuration utilities
|
|
8
|
+
*/
|
|
9
|
+
export declare class EnvironmentDetector {
|
|
10
|
+
/**
|
|
11
|
+
* Get the normalized NODE_ENV value
|
|
12
|
+
* @returns Normalized NODE_ENV (trimmed and lowercase)
|
|
13
|
+
*/
|
|
14
|
+
private static getNormalizedNodeEnv;
|
|
15
|
+
/**
|
|
16
|
+
* Determines the appropriate log mode based on NODE_ENV
|
|
17
|
+
* @returns LogMode appropriate for current environment
|
|
18
|
+
*/
|
|
19
|
+
static getEnvironmentMode(): LogMode;
|
|
20
|
+
/**
|
|
21
|
+
* Check if we're in a test environment
|
|
22
|
+
* @returns true if NODE_ENV is 'test'
|
|
23
|
+
*/
|
|
24
|
+
static isTestEnvironment(): boolean;
|
|
25
|
+
/**
|
|
26
|
+
* Check if we're in a development environment
|
|
27
|
+
* @returns true if NODE_ENV is 'development'
|
|
28
|
+
*/
|
|
29
|
+
static isDevelopmentEnvironment(): boolean;
|
|
30
|
+
/**
|
|
31
|
+
* Check if we're in a production environment
|
|
32
|
+
* @returns true if NODE_ENV is 'production'
|
|
33
|
+
*/
|
|
34
|
+
static isProductionEnvironment(): boolean;
|
|
35
|
+
}
|
|
36
|
+
//# sourceMappingURL=environment.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"environment.d.ts","sourceRoot":"","sources":["../../src/logger/environment.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EAAE,OAAO,EAAE,MAAM,UAAU,CAAC;AAEnC;;GAEG;AACH,qBAAa,mBAAmB;IAC5B;;;OAGG;IACH,OAAO,CAAC,MAAM,CAAC,oBAAoB;IAInC;;;OAGG;IACH,MAAM,CAAC,kBAAkB,IAAI,OAAO;IAiBpC;;;OAGG;IACH,MAAM,CAAC,iBAAiB,IAAI,OAAO;IAInC;;;OAGG;IACH,MAAM,CAAC,wBAAwB,IAAI,OAAO;IAI1C;;;OAGG;IACH,MAAM,CAAC,uBAAuB,IAAI,OAAO;CAG5C"}
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Environment detection utilities for logging configuration
|
|
4
|
+
* Handles automatic environment-based configuration
|
|
5
|
+
*/
|
|
6
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
7
|
+
exports.EnvironmentDetector = void 0;
|
|
8
|
+
const types_1 = require("../types");
|
|
9
|
+
/**
|
|
10
|
+
* Environment detection and configuration utilities
|
|
11
|
+
*/
|
|
12
|
+
class EnvironmentDetector {
|
|
13
|
+
/**
|
|
14
|
+
* Get the normalized NODE_ENV value
|
|
15
|
+
* @returns Normalized NODE_ENV (trimmed and lowercase)
|
|
16
|
+
*/
|
|
17
|
+
static getNormalizedNodeEnv() {
|
|
18
|
+
return (process.env.NODE_ENV || '').trim().toLowerCase();
|
|
19
|
+
}
|
|
20
|
+
/**
|
|
21
|
+
* Determines the appropriate log mode based on NODE_ENV
|
|
22
|
+
* @returns LogMode appropriate for current environment
|
|
23
|
+
*/
|
|
24
|
+
static getEnvironmentMode() {
|
|
25
|
+
const nodeEnv = EnvironmentDetector.getNormalizedNodeEnv();
|
|
26
|
+
switch (nodeEnv) {
|
|
27
|
+
case 'development':
|
|
28
|
+
return types_1.LogMode.DEBUG; // Verbose logging for development
|
|
29
|
+
case 'production':
|
|
30
|
+
return types_1.LogMode.INFO; // Important info and above for production
|
|
31
|
+
case 'staging':
|
|
32
|
+
return types_1.LogMode.WARN; // Focused logging for staging
|
|
33
|
+
case 'test':
|
|
34
|
+
return types_1.LogMode.ERROR; // Minimal logging during tests
|
|
35
|
+
default:
|
|
36
|
+
return types_1.LogMode.INFO; // Default fallback for unknown environments
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
/**
|
|
40
|
+
* Check if we're in a test environment
|
|
41
|
+
* @returns true if NODE_ENV is 'test'
|
|
42
|
+
*/
|
|
43
|
+
static isTestEnvironment() {
|
|
44
|
+
return EnvironmentDetector.getNormalizedNodeEnv() === 'test';
|
|
45
|
+
}
|
|
46
|
+
/**
|
|
47
|
+
* Check if we're in a development environment
|
|
48
|
+
* @returns true if NODE_ENV is 'development'
|
|
49
|
+
*/
|
|
50
|
+
static isDevelopmentEnvironment() {
|
|
51
|
+
return EnvironmentDetector.getNormalizedNodeEnv() === 'development';
|
|
52
|
+
}
|
|
53
|
+
/**
|
|
54
|
+
* Check if we're in a production environment
|
|
55
|
+
* @returns true if NODE_ENV is 'production'
|
|
56
|
+
*/
|
|
57
|
+
static isProductionEnvironment() {
|
|
58
|
+
return EnvironmentDetector.getNormalizedNodeEnv() === 'production';
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
exports.EnvironmentDetector = EnvironmentDetector;
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Log level and mode filtering logic
|
|
3
|
+
* Handles the decision logic for whether messages should be logged
|
|
4
|
+
*/
|
|
5
|
+
import { LogLevel, LogMode } from '../types';
|
|
6
|
+
/**
|
|
7
|
+
* Filtering logic for log messages based on levels and modes
|
|
8
|
+
* Determines whether a message should be output based on current configuration
|
|
9
|
+
*/
|
|
10
|
+
export declare class LogFilter {
|
|
11
|
+
private static readonly SEVERITY_RANKS;
|
|
12
|
+
private static readonly MODE_THRESHOLDS;
|
|
13
|
+
/**
|
|
14
|
+
* Determines if a message should be logged based on current log mode
|
|
15
|
+
* Messages are shown only if their level is appropriate for the configured mode
|
|
16
|
+
* LOG level is special - it always outputs regardless of configured mode (except when OFF is set)
|
|
17
|
+
* OFF mode disables all logging including LOG level messages
|
|
18
|
+
* @param level - The log level of the message to check
|
|
19
|
+
* @param currentMode - The current logging mode
|
|
20
|
+
* @returns true if message should be logged, false otherwise
|
|
21
|
+
*/
|
|
22
|
+
static shouldLog(level: LogLevel, currentMode: LogMode): boolean;
|
|
23
|
+
/**
|
|
24
|
+
* Get the severity rank for a log level
|
|
25
|
+
* @param level - The log level to get rank for
|
|
26
|
+
* @returns Numeric severity rank
|
|
27
|
+
*/
|
|
28
|
+
static getSeverityRank(level: LogLevel): number;
|
|
29
|
+
/**
|
|
30
|
+
* Get the threshold for a log mode
|
|
31
|
+
* @param mode - The log mode to get threshold for
|
|
32
|
+
* @returns Numeric threshold value
|
|
33
|
+
*/
|
|
34
|
+
static getModeThreshold(mode: LogMode): number;
|
|
35
|
+
}
|
|
36
|
+
//# sourceMappingURL=filtering.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"filtering.d.ts","sourceRoot":"","sources":["../../src/logger/filtering.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EAAE,QAAQ,EAAE,OAAO,EAAE,MAAM,UAAU,CAAC;AAE7C;;;GAGG;AACH,qBAAa,SAAS;IAElB,OAAO,CAAC,MAAM,CAAC,QAAQ,CAAC,cAAc,CAMpC;IAGF,OAAO,CAAC,MAAM,CAAC,QAAQ,CAAC,eAAe,CAOrC;IAEF;;;;;;;;OAQG;IACH,MAAM,CAAC,SAAS,CAAC,KAAK,EAAE,QAAQ,EAAE,WAAW,EAAE,OAAO,GAAG,OAAO;IAWhE;;;;OAIG;IACH,MAAM,CAAC,eAAe,CAAC,KAAK,EAAE,QAAQ,GAAG,MAAM;IAI/C;;;;OAIG;IACH,MAAM,CAAC,gBAAgB,CAAC,IAAI,EAAE,OAAO,GAAG,MAAM;CAGjD"}
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Log level and mode filtering logic
|
|
4
|
+
* Handles the decision logic for whether messages should be logged
|
|
5
|
+
*/
|
|
6
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
7
|
+
exports.LogFilter = void 0;
|
|
8
|
+
const types_1 = require("../types");
|
|
9
|
+
/**
|
|
10
|
+
* Filtering logic for log messages based on levels and modes
|
|
11
|
+
* Determines whether a message should be output based on current configuration
|
|
12
|
+
*/
|
|
13
|
+
class LogFilter {
|
|
14
|
+
/**
|
|
15
|
+
* Determines if a message should be logged based on current log mode
|
|
16
|
+
* Messages are shown only if their level is appropriate for the configured mode
|
|
17
|
+
* LOG level is special - it always outputs regardless of configured mode (except when OFF is set)
|
|
18
|
+
* OFF mode disables all logging including LOG level messages
|
|
19
|
+
* @param level - The log level of the message to check
|
|
20
|
+
* @param currentMode - The current logging mode
|
|
21
|
+
* @returns true if message should be logged, false otherwise
|
|
22
|
+
*/
|
|
23
|
+
static shouldLog(level, currentMode) {
|
|
24
|
+
// Get the severity rank for the message level
|
|
25
|
+
const messageSeverity = this.SEVERITY_RANKS[level];
|
|
26
|
+
// Get the minimum severity threshold for the current mode
|
|
27
|
+
const modeThreshold = this.MODE_THRESHOLDS[currentMode];
|
|
28
|
+
// Allow the message if its severity meets or exceeds the mode threshold
|
|
29
|
+
return messageSeverity >= modeThreshold;
|
|
30
|
+
}
|
|
31
|
+
/**
|
|
32
|
+
* Get the severity rank for a log level
|
|
33
|
+
* @param level - The log level to get rank for
|
|
34
|
+
* @returns Numeric severity rank
|
|
35
|
+
*/
|
|
36
|
+
static getSeverityRank(level) {
|
|
37
|
+
return this.SEVERITY_RANKS[level];
|
|
38
|
+
}
|
|
39
|
+
/**
|
|
40
|
+
* Get the threshold for a log mode
|
|
41
|
+
* @param mode - The log mode to get threshold for
|
|
42
|
+
* @returns Numeric threshold value
|
|
43
|
+
*/
|
|
44
|
+
static getModeThreshold(mode) {
|
|
45
|
+
return this.MODE_THRESHOLDS[mode];
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
exports.LogFilter = LogFilter;
|
|
49
|
+
// Maps LogLevel values to severity ranks for consistent comparison
|
|
50
|
+
LogFilter.SEVERITY_RANKS = {
|
|
51
|
+
[types_1.LogLevel.DEBUG]: 0,
|
|
52
|
+
[types_1.LogLevel.INFO]: 1,
|
|
53
|
+
[types_1.LogLevel.WARN]: 2,
|
|
54
|
+
[types_1.LogLevel.ERROR]: 3,
|
|
55
|
+
[types_1.LogLevel.LOG]: 99 // Special case - always outputs (except when OFF)
|
|
56
|
+
};
|
|
57
|
+
// Maps LogMode values to minimum severity rank required for output
|
|
58
|
+
LogFilter.MODE_THRESHOLDS = {
|
|
59
|
+
[types_1.LogMode.DEBUG]: 0, // Shows DEBUG and above
|
|
60
|
+
[types_1.LogMode.INFO]: 1, // Shows INFO and above
|
|
61
|
+
[types_1.LogMode.WARN]: 2, // Shows WARN and above
|
|
62
|
+
[types_1.LogMode.ERROR]: 3, // Shows ERROR and above
|
|
63
|
+
[types_1.LogMode.SILENT]: 99, // Only shows LOG messages
|
|
64
|
+
[types_1.LogMode.OFF]: 100 // Shows nothing
|
|
65
|
+
};
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Logger module exports
|
|
3
|
+
* Provides centralized access to all logging functionality
|
|
4
|
+
*/
|
|
5
|
+
export { Logger } from './core';
|
|
6
|
+
export { LoggerConfigManager } from './config';
|
|
7
|
+
export { LogFilter } from './filtering';
|
|
8
|
+
export { EnvironmentDetector } from './environment';
|
|
9
|
+
export { Logger as CoreLogger } from './core';
|
|
10
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/logger/index.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AAChC,OAAO,EAAE,mBAAmB,EAAE,MAAM,UAAU,CAAC;AAC/C,OAAO,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC;AACxC,OAAO,EAAE,mBAAmB,EAAE,MAAM,eAAe,CAAC;AAGpD,OAAO,EAAE,MAAM,IAAI,UAAU,EAAE,MAAM,QAAQ,CAAC"}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Logger module exports
|
|
4
|
+
* Provides centralized access to all logging functionality
|
|
5
|
+
*/
|
|
6
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
7
|
+
exports.CoreLogger = exports.EnvironmentDetector = exports.LogFilter = exports.LoggerConfigManager = exports.Logger = void 0;
|
|
8
|
+
var core_1 = require("./core");
|
|
9
|
+
Object.defineProperty(exports, "Logger", { enumerable: true, get: function () { return core_1.Logger; } });
|
|
10
|
+
var config_1 = require("./config");
|
|
11
|
+
Object.defineProperty(exports, "LoggerConfigManager", { enumerable: true, get: function () { return config_1.LoggerConfigManager; } });
|
|
12
|
+
var filtering_1 = require("./filtering");
|
|
13
|
+
Object.defineProperty(exports, "LogFilter", { enumerable: true, get: function () { return filtering_1.LogFilter; } });
|
|
14
|
+
var environment_1 = require("./environment");
|
|
15
|
+
Object.defineProperty(exports, "EnvironmentDetector", { enumerable: true, get: function () { return environment_1.EnvironmentDetector; } });
|
|
16
|
+
// Backward compatibility - maintain the original Logger class interface
|
|
17
|
+
var core_2 = require("./core");
|
|
18
|
+
Object.defineProperty(exports, "CoreLogger", { enumerable: true, get: function () { return core_2.Logger; } });
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Default configuration and constants for data redaction
|
|
3
|
+
* Provides comprehensive coverage of common sensitive field patterns
|
|
4
|
+
*/
|
|
5
|
+
import { RedactionConfig } from '../types';
|
|
6
|
+
/**
|
|
7
|
+
* Default redaction configuration with comprehensive sensitive field detection
|
|
8
|
+
* Covers authentication, personal information, financial data, and internal systems
|
|
9
|
+
*/
|
|
10
|
+
export declare const defaultRedactionConfig: RedactionConfig;
|
|
11
|
+
/**
|
|
12
|
+
* Environment-based redaction controller
|
|
13
|
+
* Determines when redaction should be disabled based on environment variables
|
|
14
|
+
*/
|
|
15
|
+
export declare class RedactionController {
|
|
16
|
+
/**
|
|
17
|
+
* Check if redaction should be disabled based on environment variables
|
|
18
|
+
* Development mode and explicit flags can disable redaction for debugging
|
|
19
|
+
* @returns true if redaction should be disabled, false otherwise
|
|
20
|
+
*/
|
|
21
|
+
static isRedactionDisabled(): boolean;
|
|
22
|
+
/**
|
|
23
|
+
* Get environment-specific configuration overrides
|
|
24
|
+
* Allows customization through environment variables
|
|
25
|
+
* @returns Partial redaction config with environment-based overrides
|
|
26
|
+
*/
|
|
27
|
+
static getEnvironmentConfig(): Partial<RedactionConfig>;
|
|
28
|
+
}
|
|
29
|
+
//# sourceMappingURL=config.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"config.d.ts","sourceRoot":"","sources":["../../src/redaction/config.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EAAE,eAAe,EAAE,MAAM,UAAU,CAAC;AAE3C;;;GAGG;AACH,eAAO,MAAM,sBAAsB,EAAE,eAyCpC,CAAC;AAEF;;;GAGG;AACH,qBAAa,mBAAmB;IAC5B;;;;OAIG;IACH,MAAM,CAAC,mBAAmB,IAAI,OAAO;IAUrC;;;;OAIG;IACH,MAAM,CAAC,oBAAoB,IAAI,OAAO,CAAC,eAAe,CAAC;CA4B1D"}
|
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Default configuration and constants for data redaction
|
|
4
|
+
* Provides comprehensive coverage of common sensitive field patterns
|
|
5
|
+
*/
|
|
6
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
7
|
+
exports.RedactionController = exports.defaultRedactionConfig = void 0;
|
|
8
|
+
/**
|
|
9
|
+
* Default redaction configuration with comprehensive sensitive field detection
|
|
10
|
+
* Covers authentication, personal information, financial data, and internal systems
|
|
11
|
+
*/
|
|
12
|
+
exports.defaultRedactionConfig = {
|
|
13
|
+
enabled: true,
|
|
14
|
+
deepRedaction: true,
|
|
15
|
+
maxContentLength: 100,
|
|
16
|
+
redactionText: '[REDACTED]',
|
|
17
|
+
truncationText: '... [TRUNCATED]',
|
|
18
|
+
// Comprehensive list of sensitive field patterns (case-insensitive)
|
|
19
|
+
sensitiveFields: [
|
|
20
|
+
// Authentication & Security
|
|
21
|
+
'password', 'pwd', 'pass', 'passphrase',
|
|
22
|
+
'token', 'accessToken', 'refreshToken', 'bearerToken',
|
|
23
|
+
'apiKey', 'api_key', 'secret', 'secretKey', 'privateKey',
|
|
24
|
+
'auth', 'authorization', 'authToken',
|
|
25
|
+
'jwt', 'sessionId', 'session_id',
|
|
26
|
+
'cookie', 'cookies', 'csrf', 'csrfToken',
|
|
27
|
+
// Personal Information (PII)
|
|
28
|
+
'email', 'emailAddress', 'email_address',
|
|
29
|
+
'phone', 'phoneNumber', 'phone_number', 'mobile',
|
|
30
|
+
'ssn', 'socialSecurityNumber', 'social_security_number',
|
|
31
|
+
'address', 'homeAddress', 'workAddress',
|
|
32
|
+
'firstName', 'lastName', 'fullName', 'realName', 'displayName',
|
|
33
|
+
'dateOfBirth', 'dob', 'birthDate',
|
|
34
|
+
// Financial Information
|
|
35
|
+
'creditCard', 'credit_card', 'cardNumber', 'card_number',
|
|
36
|
+
'cvv', 'cvc', 'pin', 'expiryDate', 'expiry_date',
|
|
37
|
+
'bankAccount', 'bank_account', 'routingNumber',
|
|
38
|
+
// Internal/System Information
|
|
39
|
+
'internalId', 'userId', 'customerId',
|
|
40
|
+
'personalInfo', 'pii', 'sensitive',
|
|
41
|
+
'clientSecret', 'webhookSecret'
|
|
42
|
+
],
|
|
43
|
+
// Fields that should be truncated rather than redacted
|
|
44
|
+
contentFields: [
|
|
45
|
+
'content', 'text', 'message', 'body', 'data',
|
|
46
|
+
'payload', 'response', 'request', 'description'
|
|
47
|
+
]
|
|
48
|
+
};
|
|
49
|
+
/**
|
|
50
|
+
* Environment-based redaction controller
|
|
51
|
+
* Determines when redaction should be disabled based on environment variables
|
|
52
|
+
*/
|
|
53
|
+
class RedactionController {
|
|
54
|
+
/**
|
|
55
|
+
* Check if redaction should be disabled based on environment variables
|
|
56
|
+
* Development mode and explicit flags can disable redaction for debugging
|
|
57
|
+
* @returns true if redaction should be disabled, false otherwise
|
|
58
|
+
*/
|
|
59
|
+
static isRedactionDisabled() {
|
|
60
|
+
return (process.env.NODE_ENV === 'development' ||
|
|
61
|
+
process.env.LOG_REDACTION_DISABLED === 'true' ||
|
|
62
|
+
process.env.DEBUG_FULL_PAYLOADS === 'true' ||
|
|
63
|
+
process.env.LOG_LEVEL === 'debug' ||
|
|
64
|
+
process.env.LOG_REDACTION_ENABLED === 'false');
|
|
65
|
+
}
|
|
66
|
+
/**
|
|
67
|
+
* Get environment-specific configuration overrides
|
|
68
|
+
* Allows customization through environment variables
|
|
69
|
+
* @returns Partial redaction config with environment-based overrides
|
|
70
|
+
*/
|
|
71
|
+
static getEnvironmentConfig() {
|
|
72
|
+
const envConfig = {
|
|
73
|
+
enabled: !this.isRedactionDisabled()
|
|
74
|
+
};
|
|
75
|
+
// Apply environment variable overrides if they exist
|
|
76
|
+
if (process.env.LOG_MAX_CONTENT_LENGTH) {
|
|
77
|
+
const parsedLength = parseInt(process.env.LOG_MAX_CONTENT_LENGTH, 10);
|
|
78
|
+
if (!isNaN(parsedLength) && parsedLength > 0) {
|
|
79
|
+
envConfig.maxContentLength = parsedLength;
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
if (process.env.LOG_REDACTION_TEXT) {
|
|
83
|
+
envConfig.redactionText = process.env.LOG_REDACTION_TEXT;
|
|
84
|
+
}
|
|
85
|
+
if (process.env.LOG_TRUNCATION_TEXT) {
|
|
86
|
+
envConfig.truncationText = process.env.LOG_TRUNCATION_TEXT;
|
|
87
|
+
}
|
|
88
|
+
if (process.env.LOG_SENSITIVE_FIELDS) {
|
|
89
|
+
const customFields = process.env.LOG_SENSITIVE_FIELDS.split(',').map(f => f.trim());
|
|
90
|
+
envConfig.sensitiveFields = [...exports.defaultRedactionConfig.sensitiveFields, ...customFields];
|
|
91
|
+
}
|
|
92
|
+
return envConfig;
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
exports.RedactionController = RedactionController;
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Redaction module exports
|
|
3
|
+
* Provides centralized access to all redaction functionality
|
|
4
|
+
*/
|
|
5
|
+
export { DataRedactor } from './redactor';
|
|
6
|
+
export { defaultRedactionConfig, RedactionController } from './config';
|
|
7
|
+
export type { RedactionConfig } from '../types';
|
|
8
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/redaction/index.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EAAE,YAAY,EAAE,MAAM,YAAY,CAAC;AAC1C,OAAO,EAAE,sBAAsB,EAAE,mBAAmB,EAAE,MAAM,UAAU,CAAC;AACvE,YAAY,EAAE,eAAe,EAAE,MAAM,UAAU,CAAC"}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Redaction module exports
|
|
4
|
+
* Provides centralized access to all redaction functionality
|
|
5
|
+
*/
|
|
6
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
7
|
+
exports.RedactionController = exports.defaultRedactionConfig = exports.DataRedactor = void 0;
|
|
8
|
+
var redactor_1 = require("./redactor");
|
|
9
|
+
Object.defineProperty(exports, "DataRedactor", { enumerable: true, get: function () { return redactor_1.DataRedactor; } });
|
|
10
|
+
var config_1 = require("./config");
|
|
11
|
+
Object.defineProperty(exports, "defaultRedactionConfig", { enumerable: true, get: function () { return config_1.defaultRedactionConfig; } });
|
|
12
|
+
Object.defineProperty(exports, "RedactionController", { enumerable: true, get: function () { return config_1.RedactionController; } });
|