@wgtechlabs/log-engine 1.2.0 → 1.3.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 +283 -18
- 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/message-formatter.d.ts +41 -0
- 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/formatter.d.ts +10 -2
- package/dist/formatter.d.ts.map +1 -1
- package/dist/formatter.js +42 -5
- 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/logger.d.ts +61 -5
- package/dist/logger.d.ts.map +1 -1
- package/dist/logger.js +117 -10
- 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 +11 -4
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Core message formatting functionality
|
|
4
|
+
* Handles the main log message formatting with colors, timestamps, and levels
|
|
5
|
+
*/
|
|
6
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
7
|
+
exports.MessageFormatter = void 0;
|
|
8
|
+
const types_1 = require("../types");
|
|
9
|
+
const colors_1 = require("./colors");
|
|
10
|
+
const timestamp_1 = require("./timestamp");
|
|
11
|
+
const data_formatter_1 = require("./data-formatter");
|
|
12
|
+
/**
|
|
13
|
+
* Core message formatter class
|
|
14
|
+
* Provides the main formatting functionality for log messages
|
|
15
|
+
*/
|
|
16
|
+
class MessageFormatter {
|
|
17
|
+
/**
|
|
18
|
+
* Formats a log message with timestamp, level indicator, and appropriate coloring
|
|
19
|
+
* Creates a structured log entry: [ISO_TIMESTAMP][LOCAL_TIME][LEVEL]: message [data]
|
|
20
|
+
* @param level - The log level to format for
|
|
21
|
+
* @param message - The message content to format
|
|
22
|
+
* @param data - Optional data object to include in the log output
|
|
23
|
+
* @returns Formatted string with ANSI colors and timestamps
|
|
24
|
+
*/
|
|
25
|
+
static format(level, message, data) {
|
|
26
|
+
const { isoTimestamp, timeString } = (0, timestamp_1.getTimestampComponents)();
|
|
27
|
+
const timestamp = (0, timestamp_1.formatTimestamp)(isoTimestamp, timeString, colors_1.colorScheme);
|
|
28
|
+
const levelName = this.getLevelName(level);
|
|
29
|
+
const levelColor = this.getLevelColor(level);
|
|
30
|
+
const coloredLevel = `${levelColor}[${levelName}]${colors_1.colors.reset}`;
|
|
31
|
+
// Format the base message
|
|
32
|
+
let formattedMessage = `${timestamp}${coloredLevel}: ${message}`;
|
|
33
|
+
// Append data if provided
|
|
34
|
+
if (data !== undefined) {
|
|
35
|
+
const dataString = (0, data_formatter_1.formatData)(data);
|
|
36
|
+
const styledData = (0, data_formatter_1.styleData)(dataString, colors_1.colorScheme);
|
|
37
|
+
formattedMessage += styledData;
|
|
38
|
+
}
|
|
39
|
+
// Always reset colors at the end of the entire log line
|
|
40
|
+
return formattedMessage + colors_1.colors.reset;
|
|
41
|
+
}
|
|
42
|
+
/**
|
|
43
|
+
* Formats a Log Engine system message with [LOG ENGINE] prefix instead of log levels
|
|
44
|
+
* Used for internal messages like deprecation warnings that should be distinguished from user logs
|
|
45
|
+
* @param message - The system message content to format
|
|
46
|
+
* @returns Formatted string with ANSI colors, timestamps, and LOG ENGINE prefix
|
|
47
|
+
*/
|
|
48
|
+
static formatSystemMessage(message) {
|
|
49
|
+
const { isoTimestamp, timeString } = (0, timestamp_1.getTimestampComponents)();
|
|
50
|
+
const timestamp = (0, timestamp_1.formatTimestamp)(isoTimestamp, timeString, colors_1.colorScheme);
|
|
51
|
+
const coloredLogEngine = `${colors_1.colorScheme.system}[LOG ENGINE]${colors_1.colors.reset}`;
|
|
52
|
+
const coloredMessage = `${colors_1.colorScheme.system}${message}${colors_1.colors.reset}`;
|
|
53
|
+
return `${timestamp}${coloredLogEngine}: ${coloredMessage}`;
|
|
54
|
+
}
|
|
55
|
+
/**
|
|
56
|
+
* Converts LogLevel enum to human-readable string
|
|
57
|
+
* @param level - The LogLevel to convert
|
|
58
|
+
* @returns String representation of the log level
|
|
59
|
+
*/
|
|
60
|
+
static getLevelName(level) {
|
|
61
|
+
switch (level) {
|
|
62
|
+
case types_1.LogLevel.DEBUG: return 'DEBUG';
|
|
63
|
+
case types_1.LogLevel.INFO: return 'INFO';
|
|
64
|
+
case types_1.LogLevel.WARN: return 'WARN';
|
|
65
|
+
case types_1.LogLevel.ERROR: return 'ERROR';
|
|
66
|
+
case types_1.LogLevel.LOG: return 'LOG';
|
|
67
|
+
default: return 'UNKNOWN';
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
/**
|
|
71
|
+
* Maps LogLevel to appropriate ANSI color code
|
|
72
|
+
* Colors help quickly identify message severity in console output
|
|
73
|
+
* @param level - The LogLevel to get color for
|
|
74
|
+
* @returns ANSI color escape sequence
|
|
75
|
+
*/
|
|
76
|
+
static getLevelColor(level) {
|
|
77
|
+
switch (level) {
|
|
78
|
+
case types_1.LogLevel.DEBUG: return colors_1.colors.magenta; // Purple for debug info
|
|
79
|
+
case types_1.LogLevel.INFO: return colors_1.colors.blue; // Blue for general info
|
|
80
|
+
case types_1.LogLevel.WARN: return colors_1.colors.yellow; // Yellow for warnings
|
|
81
|
+
case types_1.LogLevel.ERROR: return colors_1.colors.red; // Red for errors
|
|
82
|
+
case types_1.LogLevel.LOG: return colors_1.colors.green; // Green for always-on log messages
|
|
83
|
+
default: return colors_1.colors.white; // White for unknown levels
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
exports.MessageFormatter = MessageFormatter;
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Timestamp formatting utilities
|
|
3
|
+
* Handles ISO timestamp and local time formatting for log messages
|
|
4
|
+
*/
|
|
5
|
+
/**
|
|
6
|
+
* Generates the current timestamp as both an ISO 8601 string and a compact US English local time string.
|
|
7
|
+
*
|
|
8
|
+
* @returns An object containing `isoTimestamp` (ISO 8601 format) and `timeString` (localized time string without spaces)
|
|
9
|
+
*/
|
|
10
|
+
export declare function getTimestampComponents(): {
|
|
11
|
+
isoTimestamp: string;
|
|
12
|
+
timeString: string;
|
|
13
|
+
};
|
|
14
|
+
/**
|
|
15
|
+
* Returns a formatted string combining an ISO timestamp and a local time string, each wrapped with specified color codes for console output.
|
|
16
|
+
*
|
|
17
|
+
* @param isoTimestamp - The ISO 8601 formatted timestamp to display
|
|
18
|
+
* @param timeString - The local time string to display
|
|
19
|
+
* @param colors - An object containing color codes for the timestamp, time string, and reset sequence
|
|
20
|
+
* @returns The combined, colorized timestamp string suitable for log messages
|
|
21
|
+
*/
|
|
22
|
+
export declare function formatTimestamp(isoTimestamp: string, timeString: string, colors: {
|
|
23
|
+
timestamp: string;
|
|
24
|
+
timeString: string;
|
|
25
|
+
reset: string;
|
|
26
|
+
}): string;
|
|
27
|
+
//# sourceMappingURL=timestamp.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"timestamp.d.ts","sourceRoot":"","sources":["../../src/formatter/timestamp.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH;;;;GAIG;AACH,wBAAgB,sBAAsB,IAAI;IACtC,YAAY,EAAE,MAAM,CAAC;IACrB,UAAU,EAAE,MAAM,CAAC;CACtB,CAaA;AAED;;;;;;;GAOG;AACH,wBAAgB,eAAe,CAC3B,YAAY,EAAE,MAAM,EACpB,UAAU,EAAE,MAAM,EAClB,MAAM,EAAE;IAAE,SAAS,EAAE,MAAM,CAAC;IAAC,UAAU,EAAE,MAAM,CAAC;IAAC,KAAK,EAAE,MAAM,CAAA;CAAE,GACjE,MAAM,CAKR"}
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Timestamp formatting utilities
|
|
4
|
+
* Handles ISO timestamp and local time formatting for log messages
|
|
5
|
+
*/
|
|
6
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
7
|
+
exports.getTimestampComponents = getTimestampComponents;
|
|
8
|
+
exports.formatTimestamp = formatTimestamp;
|
|
9
|
+
/**
|
|
10
|
+
* Generates the current timestamp as both an ISO 8601 string and a compact US English local time string.
|
|
11
|
+
*
|
|
12
|
+
* @returns An object containing `isoTimestamp` (ISO 8601 format) and `timeString` (localized time string without spaces)
|
|
13
|
+
*/
|
|
14
|
+
function getTimestampComponents() {
|
|
15
|
+
const now = new Date();
|
|
16
|
+
const isoTimestamp = now.toISOString();
|
|
17
|
+
const timeString = now.toLocaleTimeString('en-US', {
|
|
18
|
+
hour: 'numeric',
|
|
19
|
+
minute: '2-digit',
|
|
20
|
+
hour12: true
|
|
21
|
+
}).replace(/\s+/g, '');
|
|
22
|
+
return {
|
|
23
|
+
isoTimestamp,
|
|
24
|
+
timeString
|
|
25
|
+
};
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
* Returns a formatted string combining an ISO timestamp and a local time string, each wrapped with specified color codes for console output.
|
|
29
|
+
*
|
|
30
|
+
* @param isoTimestamp - The ISO 8601 formatted timestamp to display
|
|
31
|
+
* @param timeString - The local time string to display
|
|
32
|
+
* @param colors - An object containing color codes for the timestamp, time string, and reset sequence
|
|
33
|
+
* @returns The combined, colorized timestamp string suitable for log messages
|
|
34
|
+
*/
|
|
35
|
+
function formatTimestamp(isoTimestamp, timeString, colors) {
|
|
36
|
+
const coloredTimestamp = `${colors.timestamp}[${isoTimestamp}]${colors.reset}`;
|
|
37
|
+
const coloredTimeString = `${colors.timeString}[${timeString}]${colors.reset}`;
|
|
38
|
+
return `${coloredTimestamp}${coloredTimeString}`;
|
|
39
|
+
}
|
package/dist/formatter.d.ts
CHANGED
|
@@ -11,12 +11,13 @@ export declare class LogFormatter {
|
|
|
11
11
|
private static readonly colors;
|
|
12
12
|
/**
|
|
13
13
|
* Formats a log message with timestamp, level indicator, and appropriate coloring
|
|
14
|
-
* Creates a structured log entry: [ISO_TIMESTAMP][LOCAL_TIME][LEVEL]: message
|
|
14
|
+
* Creates a structured log entry: [ISO_TIMESTAMP][LOCAL_TIME][LEVEL]: message [data]
|
|
15
15
|
* @param level - The log level to format for
|
|
16
16
|
* @param message - The message content to format
|
|
17
|
+
* @param data - Optional data object to include in the log output
|
|
17
18
|
* @returns Formatted string with ANSI colors and timestamps
|
|
18
19
|
*/
|
|
19
|
-
static format(level: LogLevel, message: string): string;
|
|
20
|
+
static format(level: LogLevel, message: string, data?: any): string;
|
|
20
21
|
/**
|
|
21
22
|
* Formats a Log Engine system message with [LOG ENGINE] prefix instead of log levels
|
|
22
23
|
* Used for internal messages like deprecation warnings that should be distinguished from user logs
|
|
@@ -24,6 +25,13 @@ export declare class LogFormatter {
|
|
|
24
25
|
* @returns Formatted string with ANSI colors, timestamps, and LOG ENGINE prefix
|
|
25
26
|
*/
|
|
26
27
|
static formatSystemMessage(message: string): string;
|
|
28
|
+
/**
|
|
29
|
+
* Formats data objects for log output
|
|
30
|
+
* Converts objects to readable JSON string format
|
|
31
|
+
* @param data - Data to format
|
|
32
|
+
* @returns Formatted string representation of the data
|
|
33
|
+
*/
|
|
34
|
+
private static formatData;
|
|
27
35
|
/**
|
|
28
36
|
* Converts LogLevel enum to human-readable string
|
|
29
37
|
* @param level - The LogLevel to convert
|
package/dist/formatter.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"formatter.d.ts","sourceRoot":"","sources":["../src/formatter.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EAAE,QAAQ,EAAE,MAAM,SAAS,CAAC;AAEnC;;;GAGG;AACH,qBAAa,YAAY;IAErB,OAAO,CAAC,MAAM,CAAC,QAAQ,CAAC,MAAM,CAW5B;IAEF
|
|
1
|
+
{"version":3,"file":"formatter.d.ts","sourceRoot":"","sources":["../src/formatter.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EAAE,QAAQ,EAAE,MAAM,SAAS,CAAC;AAEnC;;;GAGG;AACH,qBAAa,YAAY;IAErB,OAAO,CAAC,MAAM,CAAC,QAAQ,CAAC,MAAM,CAW5B;IAEF;;;;;;;OAOG;IACH,MAAM,CAAC,MAAM,CAAC,KAAK,EAAE,QAAQ,EAAE,OAAO,EAAE,MAAM,EAAE,IAAI,CAAC,EAAE,GAAG,GAAG,MAAM;IA+BnE;;;;;OAKG;IACH,MAAM,CAAC,mBAAmB,CAAC,OAAO,EAAE,MAAM,GAAG,MAAM;IAkBnD;;;;;OAKG;IACH,OAAO,CAAC,MAAM,CAAC,UAAU;IAyBzB;;;;OAIG;IACH,OAAO,CAAC,MAAM,CAAC,YAAY;IAW3B;;;;;OAKG;IACH,OAAO,CAAC,MAAM,CAAC,aAAa;CAU/B"}
|
package/dist/formatter.js
CHANGED
|
@@ -13,26 +13,36 @@ const types_1 = require("./types");
|
|
|
13
13
|
class LogFormatter {
|
|
14
14
|
/**
|
|
15
15
|
* Formats a log message with timestamp, level indicator, and appropriate coloring
|
|
16
|
-
* Creates a structured log entry: [ISO_TIMESTAMP][LOCAL_TIME][LEVEL]: message
|
|
16
|
+
* Creates a structured log entry: [ISO_TIMESTAMP][LOCAL_TIME][LEVEL]: message [data]
|
|
17
17
|
* @param level - The log level to format for
|
|
18
18
|
* @param message - The message content to format
|
|
19
|
+
* @param data - Optional data object to include in the log output
|
|
19
20
|
* @returns Formatted string with ANSI colors and timestamps
|
|
20
21
|
*/
|
|
21
|
-
static format(level, message) {
|
|
22
|
+
static format(level, message, data) {
|
|
22
23
|
const now = new Date();
|
|
23
24
|
const isoTimestamp = now.toISOString();
|
|
24
25
|
const timeString = now.toLocaleTimeString('en-US', {
|
|
25
26
|
hour: 'numeric',
|
|
26
27
|
minute: '2-digit',
|
|
27
28
|
hour12: true
|
|
28
|
-
});
|
|
29
|
+
}).replace(/\s+/g, '');
|
|
29
30
|
const levelName = this.getLevelName(level);
|
|
30
31
|
const levelColor = this.getLevelColor(level);
|
|
31
32
|
// Apply colors to each component for better readability
|
|
32
33
|
const coloredTimestamp = `${this.colors.gray}[${isoTimestamp}]${this.colors.reset}`;
|
|
33
34
|
const coloredTimeString = `${this.colors.cyan}[${timeString}]${this.colors.reset}`;
|
|
34
35
|
const coloredLevel = `${levelColor}[${levelName}]${this.colors.reset}`;
|
|
35
|
-
|
|
36
|
+
// Format the base message
|
|
37
|
+
let formattedMessage = `${coloredTimestamp}${coloredTimeString}${coloredLevel}: ${message}`;
|
|
38
|
+
// Append data if provided
|
|
39
|
+
if (data !== undefined) {
|
|
40
|
+
const dataString = this.formatData(data);
|
|
41
|
+
if (dataString) {
|
|
42
|
+
formattedMessage += ` ${this.colors.dim}${dataString}${this.colors.reset}`;
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
return formattedMessage;
|
|
36
46
|
}
|
|
37
47
|
/**
|
|
38
48
|
* Formats a Log Engine system message with [LOG ENGINE] prefix instead of log levels
|
|
@@ -47,7 +57,7 @@ class LogFormatter {
|
|
|
47
57
|
hour: 'numeric',
|
|
48
58
|
minute: '2-digit',
|
|
49
59
|
hour12: true
|
|
50
|
-
});
|
|
60
|
+
}).replace(/\s+/g, '');
|
|
51
61
|
// Apply colors to each component for better readability
|
|
52
62
|
const coloredTimestamp = `${LogFormatter.colors.gray}[${isoTimestamp}]${LogFormatter.colors.reset}`;
|
|
53
63
|
const coloredTimeString = `${LogFormatter.colors.cyan}[${timeString}]${LogFormatter.colors.reset}`;
|
|
@@ -55,6 +65,33 @@ class LogFormatter {
|
|
|
55
65
|
const coloredMessage = `${LogFormatter.colors.yellow}${message}${LogFormatter.colors.reset}`;
|
|
56
66
|
return `${coloredTimestamp}${coloredTimeString}${coloredLogEngine}: ${coloredMessage}`;
|
|
57
67
|
}
|
|
68
|
+
/**
|
|
69
|
+
* Formats data objects for log output
|
|
70
|
+
* Converts objects to readable JSON string format
|
|
71
|
+
* @param data - Data to format
|
|
72
|
+
* @returns Formatted string representation of the data
|
|
73
|
+
*/
|
|
74
|
+
static formatData(data) {
|
|
75
|
+
if (data === null) {
|
|
76
|
+
return 'null';
|
|
77
|
+
}
|
|
78
|
+
if (data === undefined) {
|
|
79
|
+
return '';
|
|
80
|
+
}
|
|
81
|
+
if (typeof data === 'string') {
|
|
82
|
+
return data;
|
|
83
|
+
}
|
|
84
|
+
if (typeof data === 'number' || typeof data === 'boolean') {
|
|
85
|
+
return String(data);
|
|
86
|
+
}
|
|
87
|
+
try {
|
|
88
|
+
return JSON.stringify(data, null, 0);
|
|
89
|
+
}
|
|
90
|
+
catch (error) {
|
|
91
|
+
// Fallback for objects that can't be stringified (e.g., circular references)
|
|
92
|
+
return '[Object]';
|
|
93
|
+
}
|
|
94
|
+
}
|
|
58
95
|
/**
|
|
59
96
|
* Converts LogLevel enum to human-readable string
|
|
60
97
|
* @param level - The LogLevel to convert
|
package/dist/index.d.ts
CHANGED
|
@@ -1,84 +1,186 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* Main
|
|
3
|
-
*
|
|
2
|
+
* Main LogEngine module - provides a comprehensive logging solution
|
|
3
|
+
* with mode-based filtering, colorized output, and automatic data redaction
|
|
4
|
+
*
|
|
5
|
+
* Features a modular architecture with separate modules for:
|
|
6
|
+
* - Logger: Core logging functionality with environment-based configuration
|
|
7
|
+
* - Formatter: Message formatting with ANSI colors and timestamps
|
|
8
|
+
* - Redaction: Automatic sensitive data protection with customizable patterns
|
|
9
|
+
*
|
|
10
|
+
* @example
|
|
11
|
+
* ```typescript
|
|
12
|
+
* import { LogEngine, LogMode } from '@wgtechlabs/log-engine';
|
|
13
|
+
*
|
|
14
|
+
* // Configure logging mode
|
|
15
|
+
* LogEngine.configure({ mode: LogMode.DEBUG });
|
|
16
|
+
*
|
|
17
|
+
* // Log with automatic redaction
|
|
18
|
+
* LogEngine.info('User login', { username: 'john', password: 'secret123' });
|
|
19
|
+
* // Output: [2025-06-18T...][3:45PM][INFO]: User login { username: 'john', password: '[REDACTED]' }
|
|
20
|
+
* ```
|
|
4
21
|
*/
|
|
5
|
-
import { LoggerConfig } from './types';
|
|
22
|
+
import type { LoggerConfig, RedactionConfig } from './types';
|
|
6
23
|
/**
|
|
7
|
-
*
|
|
8
|
-
*
|
|
24
|
+
* LogEngine - The main interface for logging operations
|
|
25
|
+
* Provides a simple, intuitive API for all logging needs with security-first design
|
|
9
26
|
*/
|
|
10
27
|
export declare const LogEngine: {
|
|
11
28
|
/**
|
|
12
|
-
* Configure the logger with
|
|
13
|
-
* @param config -
|
|
29
|
+
* Configure the logger with new settings
|
|
30
|
+
* @param config - Configuration object containing logger settings
|
|
14
31
|
* @example
|
|
15
32
|
* ```typescript
|
|
16
|
-
* LogEngine.configure({
|
|
17
|
-
* LogEngine.configure({ level: LogLevel.WARN, environment: 'staging' });
|
|
33
|
+
* LogEngine.configure({ mode: LogMode.PRODUCTION });
|
|
18
34
|
* ```
|
|
19
35
|
*/
|
|
20
36
|
configure: (config: Partial<LoggerConfig>) => void;
|
|
21
37
|
/**
|
|
22
|
-
* Log a debug message
|
|
23
|
-
* Only shown
|
|
24
|
-
* Useful for detailed diagnostic information during development
|
|
38
|
+
* Log a debug message with automatic data redaction
|
|
39
|
+
* Only shown in DEVELOPMENT mode
|
|
25
40
|
* @param message - The debug message to log
|
|
41
|
+
* @param data - Optional data object to log (sensitive data will be redacted)
|
|
26
42
|
* @example
|
|
27
43
|
* ```typescript
|
|
28
|
-
* LogEngine.debug('
|
|
29
|
-
* LogEngine.debug(`Processing ${items.length} items`);
|
|
44
|
+
* LogEngine.debug('Processing user data', { userId: 123, email: 'user@example.com' });
|
|
30
45
|
* ```
|
|
31
46
|
*/
|
|
32
|
-
debug: (message: string) => void;
|
|
47
|
+
debug: (message: string, data?: any) => void;
|
|
33
48
|
/**
|
|
34
|
-
* Log an
|
|
35
|
-
*
|
|
36
|
-
* Shown when log level is INFO or lower
|
|
49
|
+
* Log an info message with automatic data redaction
|
|
50
|
+
* Shown in DEVELOPMENT and PRODUCTION modes
|
|
37
51
|
* @param message - The info message to log
|
|
52
|
+
* @param data - Optional data object to log (sensitive data will be redacted)
|
|
38
53
|
* @example
|
|
39
54
|
* ```typescript
|
|
40
|
-
* LogEngine.info('
|
|
41
|
-
* LogEngine.info('User logged in: john@example.com');
|
|
55
|
+
* LogEngine.info('User login successful', { username: 'john' });
|
|
42
56
|
* ```
|
|
43
57
|
*/
|
|
44
|
-
info: (message: string) => void;
|
|
58
|
+
info: (message: string, data?: any) => void;
|
|
45
59
|
/**
|
|
46
|
-
* Log a warning message
|
|
47
|
-
*
|
|
48
|
-
* Shown when log level is WARN or lower
|
|
60
|
+
* Log a warning message with automatic data redaction
|
|
61
|
+
* Shown in DEVELOPMENT and PRODUCTION modes
|
|
49
62
|
* @param message - The warning message to log
|
|
63
|
+
* @param data - Optional data object to log (sensitive data will be redacted)
|
|
50
64
|
* @example
|
|
51
65
|
* ```typescript
|
|
52
|
-
* LogEngine.warn('API rate limit approaching');
|
|
53
|
-
* LogEngine.warn('Deprecated function called');
|
|
66
|
+
* LogEngine.warn('API rate limit approaching', { requestsRemaining: 10 });
|
|
54
67
|
* ```
|
|
55
68
|
*/
|
|
56
|
-
warn: (message: string) => void;
|
|
69
|
+
warn: (message: string, data?: any) => void;
|
|
57
70
|
/**
|
|
58
|
-
* Log an error message
|
|
59
|
-
*
|
|
60
|
-
* Always shown unless log level is SILENT
|
|
71
|
+
* Log an error message with automatic data redaction
|
|
72
|
+
* Shown in DEVELOPMENT and PRODUCTION modes
|
|
61
73
|
* @param message - The error message to log
|
|
74
|
+
* @param data - Optional data object to log (sensitive data will be redacted)
|
|
62
75
|
* @example
|
|
63
76
|
* ```typescript
|
|
64
|
-
* LogEngine.error('Database connection failed');
|
|
65
|
-
* LogEngine.error('Authentication token expired');
|
|
77
|
+
* LogEngine.error('Database connection failed', { host: 'localhost', port: 5432 });
|
|
66
78
|
* ```
|
|
67
79
|
*/
|
|
68
|
-
error: (message: string) => void;
|
|
80
|
+
error: (message: string, data?: any) => void;
|
|
69
81
|
/**
|
|
70
|
-
* Log a critical message
|
|
71
|
-
*
|
|
72
|
-
* Always shown no matter what log mode is configured (except OFF mode)
|
|
82
|
+
* Log a critical message with automatic data redaction
|
|
83
|
+
* Always shown regardless of mode (except OFF)
|
|
73
84
|
* @param message - The critical log message to log
|
|
85
|
+
* @param data - Optional data object to log (sensitive data will be redacted)
|
|
74
86
|
* @example
|
|
75
87
|
* ```typescript
|
|
76
|
-
* LogEngine.log('Application starting
|
|
77
|
-
* LogEngine.log('Server listening on port 3000');
|
|
78
|
-
* LogEngine.log('Graceful shutdown initiated');
|
|
88
|
+
* LogEngine.log('Application starting', { version: '1.0.0' });
|
|
79
89
|
* ```
|
|
80
90
|
*/
|
|
81
|
-
log: (message: string) => void;
|
|
91
|
+
log: (message: string, data?: any) => void;
|
|
92
|
+
/**
|
|
93
|
+
* Log a debug message without redaction (use with caution)
|
|
94
|
+
* Bypasses automatic data redaction for debugging purposes
|
|
95
|
+
* @param message - The debug message to log
|
|
96
|
+
* @param data - Optional data object to log (no redaction applied)
|
|
97
|
+
*/
|
|
98
|
+
debugRaw: (message: string, data?: any) => void;
|
|
99
|
+
/**
|
|
100
|
+
* Log an info message without redaction (use with caution)
|
|
101
|
+
* Bypasses automatic data redaction for debugging purposes
|
|
102
|
+
* @param message - The info message to log
|
|
103
|
+
* @param data - Optional data object to log (no redaction applied)
|
|
104
|
+
*/
|
|
105
|
+
infoRaw: (message: string, data?: any) => void;
|
|
106
|
+
/**
|
|
107
|
+
* Log a warning message without redaction (use with caution)
|
|
108
|
+
* Bypasses automatic data redaction for debugging purposes
|
|
109
|
+
* @param message - The warning message to log
|
|
110
|
+
* @param data - Optional data object to log (no redaction applied)
|
|
111
|
+
*/
|
|
112
|
+
warnRaw: (message: string, data?: any) => void;
|
|
113
|
+
/**
|
|
114
|
+
* Log an error message without redaction (use with caution)
|
|
115
|
+
* Bypasses automatic data redaction for debugging purposes
|
|
116
|
+
* @param message - The error message to log
|
|
117
|
+
* @param data - Optional data object to log (no redaction applied)
|
|
118
|
+
*/
|
|
119
|
+
errorRaw: (message: string, data?: any) => void;
|
|
120
|
+
/**
|
|
121
|
+
* Log a critical message without redaction (use with caution)
|
|
122
|
+
* Bypasses automatic data redaction for debugging purposes
|
|
123
|
+
* @param message - The critical log message to log
|
|
124
|
+
* @param data - Optional data object to log (no redaction applied)
|
|
125
|
+
*/
|
|
126
|
+
logRaw: (message: string, data?: any) => void;
|
|
127
|
+
/**
|
|
128
|
+
* Configure data redaction settings
|
|
129
|
+
* @param config - Partial redaction configuration to apply
|
|
130
|
+
*/
|
|
131
|
+
configureRedaction: (config: Partial<RedactionConfig>) => void;
|
|
132
|
+
/**
|
|
133
|
+
* Refresh redaction configuration from environment variables
|
|
134
|
+
* Useful for picking up runtime environment changes
|
|
135
|
+
*/
|
|
136
|
+
refreshRedactionConfig: () => void;
|
|
137
|
+
/**
|
|
138
|
+
* Reset redaction configuration to defaults
|
|
139
|
+
*/
|
|
140
|
+
resetRedactionConfig: () => void;
|
|
141
|
+
/**
|
|
142
|
+
* Get current redaction configuration
|
|
143
|
+
* @returns Current redaction configuration
|
|
144
|
+
*/
|
|
145
|
+
getRedactionConfig: () => RedactionConfig;
|
|
146
|
+
/**
|
|
147
|
+
* Add custom regex patterns for advanced field detection
|
|
148
|
+
* @param patterns - Array of regex patterns to add
|
|
149
|
+
*/
|
|
150
|
+
addCustomRedactionPatterns: (patterns: RegExp[]) => void;
|
|
151
|
+
/**
|
|
152
|
+
* Clear all custom redaction patterns
|
|
153
|
+
*/
|
|
154
|
+
clearCustomRedactionPatterns: () => void;
|
|
155
|
+
/**
|
|
156
|
+
* Add custom sensitive field names to the existing list
|
|
157
|
+
* @param fields - Array of field names to add
|
|
158
|
+
*/
|
|
159
|
+
addSensitiveFields: (fields: string[]) => void;
|
|
160
|
+
/**
|
|
161
|
+
* Test if a field name would be redacted with current configuration
|
|
162
|
+
* @param fieldName - Field name to test
|
|
163
|
+
* @returns true if field would be redacted, false otherwise
|
|
164
|
+
*/
|
|
165
|
+
testFieldRedaction: (fieldName: string) => boolean;
|
|
166
|
+
/**
|
|
167
|
+
* Temporarily disable redaction for a specific logging call
|
|
168
|
+
* @returns LogEngine instance with redaction bypassed
|
|
169
|
+
* @example
|
|
170
|
+
* ```typescript
|
|
171
|
+
* LogEngine.withoutRedaction().info('Debug data', sensitiveObject);
|
|
172
|
+
* ```
|
|
173
|
+
*/
|
|
174
|
+
withoutRedaction: () => {
|
|
175
|
+
debug: (message: string, data?: any) => void;
|
|
176
|
+
info: (message: string, data?: any) => void;
|
|
177
|
+
warn: (message: string, data?: any) => void;
|
|
178
|
+
error: (message: string, data?: any) => void;
|
|
179
|
+
log: (message: string, data?: any) => void;
|
|
180
|
+
};
|
|
82
181
|
};
|
|
83
|
-
export {
|
|
182
|
+
export { LogMode, LogLevel } from './types';
|
|
183
|
+
export type { LoggerConfig, RedactionConfig } from './types';
|
|
184
|
+
export { DataRedactor, defaultRedactionConfig, RedactionController } from './redaction';
|
|
185
|
+
export default LogEngine;
|
|
84
186
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;GAoBG;AAIH,OAAO,KAAK,EAAE,YAAY,EAAE,eAAe,EAAE,MAAM,SAAS,CAAC;AAM7D;;;GAGG;AACH,eAAO,MAAM,SAAS;IAClB;;;;;;;OAOG;wBACiB,OAAO,CAAC,YAAY,CAAC;IAGzC;;;;;;;;;OASG;qBACc,MAAM,SAAS,GAAG;IAEnC;;;;;;;;;OASG;oBACa,MAAM,SAAS,GAAG;IAElC;;;;;;;;;OASG;oBACa,MAAM,SAAS,GAAG;IAElC;;;;;;;;;OASG;qBACc,MAAM,SAAS,GAAG;IAEnC;;;;;;;;;OASG;mBACY,MAAM,SAAS,GAAG;IAGjC;;;;;OAKG;wBACiB,MAAM,SAAS,GAAG;IAEtC;;;;;OAKG;uBACgB,MAAM,SAAS,GAAG;IAErC;;;;;OAKG;uBACgB,MAAM,SAAS,GAAG;IAErC;;;;;OAKG;wBACiB,MAAM,SAAS,GAAG;IAEtC;;;;;OAKG;sBACe,MAAM,SAAS,GAAG;IAGpC;;;OAGG;iCAC0B,OAAO,CAAC,eAAe,CAAC;IAErD;;;OAGG;;IAGH;;OAEG;;IAGH;;;OAGG;;IAIH;;;OAGG;2CACoC,MAAM,EAAE;IAE/C;;OAEG;;IAGH;;;OAGG;iCAC0B,MAAM,EAAE;IAErC;;;;OAIG;oCAC6B,MAAM;IAEtC;;;;;;;OAOG;;yBAEkB,MAAM,SAAS,GAAG;wBACnB,MAAM,SAAS,GAAG;wBAClB,MAAM,SAAS,GAAG;yBACjB,MAAM,SAAS,GAAG;uBACpB,MAAM,SAAS,GAAG;;CAExC,CAAC;AAGF,OAAO,EAAE,OAAO,EAAE,QAAQ,EAAE,MAAM,SAAS,CAAC;AAC5C,YAAY,EAAE,YAAY,EAAE,eAAe,EAAE,MAAM,SAAS,CAAC;AAC7D,OAAO,EAAE,YAAY,EAAE,sBAAsB,EAAE,mBAAmB,EAAE,MAAM,aAAa,CAAC;AAGxF,eAAe,SAAS,CAAC"}
|