@wgtechlabs/log-engine 1.0.2 → 1.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +127 -18
- package/dist/formatter.d.ts +41 -0
- package/dist/formatter.d.ts.map +1 -0
- package/dist/formatter.js +25 -3
- package/dist/index.d.ts +84 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +32 -15
- package/dist/logger.d.ts +72 -0
- package/dist/logger.d.ts.map +1 -0
- package/dist/logger.js +81 -7
- package/dist/types/index.d.ts +64 -0
- package/dist/types/index.d.ts.map +1 -0
- package/dist/types/index.js +24 -6
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -19,7 +19,7 @@ Log Engine transforms your development experience from chaotic debugging session
|
|
|
19
19
|
- **Lightweight & Fast**: Minimal overhead with maximum performance - designed to enhance your application, not slow it down.
|
|
20
20
|
- **No Learning Curve**: Dead simple API that you can master in seconds. No extensive documentation, complex configurations, or setup required - Log Engine works instantly.
|
|
21
21
|
- **Colorized Console Output**: Beautiful ANSI color-coded log levels with intelligent terminal formatting - instantly identify message severity at a glance with color-coded output.
|
|
22
|
-
- **Multiple Log
|
|
22
|
+
- **Multiple Log Modes**: Support for DEBUG, INFO, WARN, ERROR, SILENT, OFF, and special LOG levels with smart filtering - just set your mode and let it handle the rest.
|
|
23
23
|
- **Auto-Configuration**: Intelligent environment-based setup using NODE_ENV variables. No config files, initialization scripts, or manual setup - Log Engine works perfectly out of the box.
|
|
24
24
|
- **Enhanced Formatting**: Structured log entries with dual timestamps (ISO + human-readable) and colored level indicators for maximum readability.
|
|
25
25
|
- **TypeScript Ready**: Full TypeScript support with comprehensive type definitions for a seamless development experience.
|
|
@@ -70,38 +70,84 @@ yarn add @wgtechlabs/log-engine
|
|
|
70
70
|
### Quick Start
|
|
71
71
|
|
|
72
72
|
```typescript
|
|
73
|
-
import { LogEngine,
|
|
73
|
+
import { LogEngine, LogMode } from '@wgtechlabs/log-engine';
|
|
74
74
|
|
|
75
75
|
// Basic usage with auto-configuration based on NODE_ENV
|
|
76
76
|
LogEngine.debug('This is a debug message');
|
|
77
77
|
LogEngine.info('This is an info message');
|
|
78
78
|
LogEngine.warn('This is a warning message');
|
|
79
79
|
LogEngine.error('This is an error message');
|
|
80
|
+
LogEngine.log('This is a critical message that always shows');
|
|
80
81
|
```
|
|
81
82
|
|
|
82
|
-
###
|
|
83
|
+
### Mode-Based Configuration (Recommended)
|
|
84
|
+
|
|
85
|
+
Log Engine now uses a modern **LogMode** system that separates message severity from output control:
|
|
83
86
|
|
|
84
87
|
```typescript
|
|
85
|
-
import { LogEngine,
|
|
88
|
+
import { LogEngine, LogMode } from '@wgtechlabs/log-engine';
|
|
86
89
|
|
|
87
|
-
// Configure
|
|
88
|
-
|
|
90
|
+
// Configure using LogMode (recommended approach)
|
|
91
|
+
LogEngine.configure({ mode: LogMode.DEBUG }); // Most verbose
|
|
92
|
+
LogEngine.configure({ mode: LogMode.INFO }); // Balanced
|
|
93
|
+
LogEngine.configure({ mode: LogMode.WARN }); // Focused
|
|
94
|
+
LogEngine.configure({ mode: LogMode.ERROR }); // Minimal
|
|
95
|
+
LogEngine.configure({ mode: LogMode.SILENT }); // Critical only
|
|
96
|
+
LogEngine.configure({ mode: LogMode.OFF }); // Complete silence
|
|
97
|
+
|
|
98
|
+
// Environment-based configuration example
|
|
99
|
+
const env = process.env.NODE_ENV || 'development';
|
|
89
100
|
|
|
90
101
|
if (env === 'production') {
|
|
91
|
-
LogEngine.configure({
|
|
102
|
+
LogEngine.configure({ mode: LogMode.INFO });
|
|
92
103
|
} else if (env === 'staging') {
|
|
93
|
-
LogEngine.configure({
|
|
104
|
+
LogEngine.configure({ mode: LogMode.WARN });
|
|
94
105
|
} else {
|
|
95
|
-
LogEngine.configure({
|
|
106
|
+
LogEngine.configure({ mode: LogMode.DEBUG });
|
|
96
107
|
}
|
|
97
108
|
|
|
98
|
-
// Now use Log Engine - only messages
|
|
99
|
-
LogEngine.debug('This will only show in
|
|
109
|
+
// Now use Log Engine - only messages appropriate for the mode will be shown
|
|
110
|
+
LogEngine.debug('This will only show in DEBUG mode');
|
|
100
111
|
LogEngine.info('General information');
|
|
101
112
|
LogEngine.warn('Warning message');
|
|
102
113
|
LogEngine.error('Error message');
|
|
114
|
+
LogEngine.log('Critical message that always shows');
|
|
115
|
+
```
|
|
116
|
+
|
|
117
|
+
### Legacy Level-Based Configuration (Backwards Compatible)
|
|
118
|
+
|
|
119
|
+
For backwards compatibility, the old `LogLevel` API is still supported:
|
|
120
|
+
|
|
121
|
+
```typescript
|
|
122
|
+
import { LogEngine, LogLevel } from '@wgtechlabs/log-engine';
|
|
123
|
+
|
|
124
|
+
// Legacy configuration (still works but LogMode is recommended)
|
|
125
|
+
LogEngine.configure({ level: LogLevel.DEBUG });
|
|
126
|
+
LogEngine.configure({ level: LogLevel.INFO });
|
|
127
|
+
LogEngine.configure({ level: LogLevel.WARN });
|
|
128
|
+
LogEngine.configure({ level: LogLevel.ERROR });
|
|
129
|
+
```
|
|
130
|
+
|
|
131
|
+
### Migration Guide: LogLevel → LogMode
|
|
132
|
+
|
|
133
|
+
**Version 1.2.0+** introduces the new LogMode system for better separation of concerns. Here's how to migrate:
|
|
134
|
+
|
|
135
|
+
```typescript
|
|
136
|
+
// OLD (v1.1.0 and earlier) - still works but deprecated
|
|
137
|
+
import { LogEngine, LogLevel } from '@wgtechlabs/log-engine';
|
|
138
|
+
LogEngine.configure({ level: LogLevel.DEBUG });
|
|
139
|
+
|
|
140
|
+
// NEW (v1.2.0+) - recommended approach
|
|
141
|
+
import { LogEngine, LogMode } from '@wgtechlabs/log-engine';
|
|
142
|
+
LogEngine.configure({ mode: LogMode.DEBUG });
|
|
103
143
|
```
|
|
104
144
|
|
|
145
|
+
**Key Benefits of LogMode:**
|
|
146
|
+
- **Clearer API**: Separates message severity (`LogLevel`) from output control (`LogMode`)
|
|
147
|
+
- **Better Environment Defaults**: `development→DEBUG`, `staging→WARN`, `test→ERROR`
|
|
148
|
+
- **Future-Proof**: New features will use the LogMode system
|
|
149
|
+
- **100% Backwards Compatible**: Existing code continues to work unchanged
|
|
150
|
+
|
|
105
151
|
### Color-Coded Output 🎨
|
|
106
152
|
|
|
107
153
|
Log Engine now features beautiful, color-coded console output that makes debugging and monitoring a breeze:
|
|
@@ -114,6 +160,7 @@ LogEngine.debug('🔍 Debugging user authentication flow'); // Purple/Magenta
|
|
|
114
160
|
LogEngine.info('ℹ️ User successfully logged in'); // Blue
|
|
115
161
|
LogEngine.warn('⚠️ API rate limit at 80% capacity'); // Yellow
|
|
116
162
|
LogEngine.error('❌ Database connection timeout'); // Red
|
|
163
|
+
LogEngine.log('🚀 Application started successfully'); // Green
|
|
117
164
|
```
|
|
118
165
|
|
|
119
166
|
**Why Colors Matter:**
|
|
@@ -123,24 +170,84 @@ LogEngine.error('❌ Database connection timeout'); // Red
|
|
|
123
170
|
- **Production Monitoring**: Easily scan logs for critical issues in terminal environments
|
|
124
171
|
- **Enhanced Readability**: Color-coded timestamps and level indicators reduce eye strain
|
|
125
172
|
|
|
126
|
-
### Log
|
|
173
|
+
### Log Modes
|
|
174
|
+
|
|
175
|
+
Log Engine uses a **LogMode** system that controls output verbosity and filtering:
|
|
127
176
|
|
|
128
|
-
|
|
177
|
+
- `LogMode.DEBUG` (0) - Most verbose: shows DEBUG, INFO, WARN, ERROR, LOG messages
|
|
178
|
+
- `LogMode.INFO` (1) - Balanced: shows INFO, WARN, ERROR, LOG messages
|
|
179
|
+
- `LogMode.WARN` (2) - Focused: shows WARN, ERROR, LOG messages
|
|
180
|
+
- `LogMode.ERROR` (3) - Minimal: shows ERROR, LOG messages
|
|
181
|
+
- `LogMode.SILENT` (4) - Critical only: shows LOG messages only
|
|
182
|
+
- `LogMode.OFF` (5) - Complete silence: shows no messages at all
|
|
183
|
+
|
|
184
|
+
### Message Severity Levels
|
|
185
|
+
|
|
186
|
+
Individual log messages have severity levels that determine their importance:
|
|
129
187
|
|
|
130
188
|
- `LogLevel.DEBUG` (0) - Detailed information for debugging
|
|
131
189
|
- `LogLevel.INFO` (1) - General information
|
|
132
190
|
- `LogLevel.WARN` (2) - Warning messages
|
|
133
191
|
- `LogLevel.ERROR` (3) - Error messages
|
|
134
|
-
- `LogLevel.
|
|
192
|
+
- `LogLevel.LOG` (99) - Critical messages that always show (except when OFF mode is set)
|
|
135
193
|
|
|
136
194
|
### Auto-Configuration
|
|
137
195
|
|
|
138
196
|
Log Engine automatically configures itself based on the `NODE_ENV` environment variable:
|
|
139
197
|
|
|
140
|
-
- `
|
|
141
|
-
- `
|
|
142
|
-
- `
|
|
143
|
-
- `
|
|
198
|
+
- `development` → `LogMode.DEBUG` (most verbose)
|
|
199
|
+
- `production` → `LogMode.INFO` (balanced)
|
|
200
|
+
- `staging` → `LogMode.WARN` (focused)
|
|
201
|
+
- `test` → `LogMode.ERROR` (minimal)
|
|
202
|
+
- `default` → `LogMode.INFO` (balanced)
|
|
203
|
+
|
|
204
|
+
### Special LOG Level
|
|
205
|
+
|
|
206
|
+
The `LOG` level is special and behaves differently from other levels:
|
|
207
|
+
|
|
208
|
+
- **Always Visible**: LOG messages are always displayed regardless of the configured log mode (except when OFF mode is set)
|
|
209
|
+
- **Critical Information**: Perfect for essential system messages, application lifecycle events, and operational information that must never be filtered out
|
|
210
|
+
- **Green Color**: Uses green coloring to distinguish it from other levels
|
|
211
|
+
- **Use Cases**: Application startup/shutdown, server listening notifications, critical configuration changes, deployment information
|
|
212
|
+
|
|
213
|
+
```typescript
|
|
214
|
+
import { LogEngine, LogMode } from '@wgtechlabs/log-engine';
|
|
215
|
+
|
|
216
|
+
// Even with SILENT mode, LOG messages still appear
|
|
217
|
+
LogEngine.configure({ mode: LogMode.SILENT });
|
|
218
|
+
|
|
219
|
+
LogEngine.debug('Debug message'); // Hidden
|
|
220
|
+
LogEngine.info('Info message'); // Hidden
|
|
221
|
+
LogEngine.warn('Warning message'); // Hidden
|
|
222
|
+
LogEngine.error('Error message'); // Hidden
|
|
223
|
+
LogEngine.log('Server started on port 3000'); // ✅ Always visible!
|
|
224
|
+
|
|
225
|
+
// But with OFF mode, even LOG messages are hidden
|
|
226
|
+
LogEngine.configure({ mode: LogMode.OFF });
|
|
227
|
+
LogEngine.log('This LOG message is hidden'); // ❌ Hidden with OFF mode
|
|
228
|
+
```
|
|
229
|
+
|
|
230
|
+
### Complete Silence with OFF Mode
|
|
231
|
+
|
|
232
|
+
The `OFF` mode provides complete logging silence when you need to disable all output:
|
|
233
|
+
|
|
234
|
+
- **Total Silence**: Disables ALL logging including the special LOG level messages
|
|
235
|
+
- **Testing & CI/CD**: Perfect for automated testing environments where no console output is desired
|
|
236
|
+
- **Performance**: Minimal overhead when logging is completely disabled
|
|
237
|
+
- **Use Cases**: Unit tests, CI/CD pipelines, production environments requiring zero log output
|
|
238
|
+
|
|
239
|
+
```typescript
|
|
240
|
+
import { LogEngine, LogMode } from '@wgtechlabs/log-engine';
|
|
241
|
+
|
|
242
|
+
// Comparison: SILENT vs OFF
|
|
243
|
+
LogEngine.configure({ mode: LogMode.SILENT });
|
|
244
|
+
LogEngine.info('Info message'); // Hidden
|
|
245
|
+
LogEngine.log('Critical message'); // ✅ Still visible with SILENT
|
|
246
|
+
|
|
247
|
+
LogEngine.configure({ mode: LogMode.OFF });
|
|
248
|
+
LogEngine.info('Info message'); // Hidden
|
|
249
|
+
LogEngine.log('Critical message'); // ❌ Hidden with OFF - complete silence!
|
|
250
|
+
```
|
|
144
251
|
|
|
145
252
|
### Log Format
|
|
146
253
|
|
|
@@ -152,6 +259,7 @@ Log messages are beautifully formatted with colorized timestamps, levels, and sm
|
|
|
152
259
|
[2025-05-29T16:57:46.123Z][4:57 PM][INFO]: Server started successfully
|
|
153
260
|
[2025-05-29T16:57:47.456Z][4:57 PM][WARN]: API rate limit approaching
|
|
154
261
|
[2025-05-29T16:57:48.789Z][4:57 PM][ERROR]: Database connection failed
|
|
262
|
+
[2025-05-29T16:57:49.012Z][4:57 PM][LOG]: Application startup complete
|
|
155
263
|
```
|
|
156
264
|
|
|
157
265
|
**Color Scheme:**
|
|
@@ -160,6 +268,7 @@ Log messages are beautifully formatted with colorized timestamps, levels, and sm
|
|
|
160
268
|
- 🔵 **INFO**: Blue - General informational messages
|
|
161
269
|
- 🟡 **WARN**: Yellow - Warning messages that need attention
|
|
162
270
|
- 🔴 **ERROR**: Red - Error messages requiring immediate action
|
|
271
|
+
- 🟢 **LOG**: Green - Critical messages that always display
|
|
163
272
|
- ⚫ **Timestamps**: Gray (ISO) and Cyan (local time) for easy scanning
|
|
164
273
|
|
|
165
274
|
## 💬 Community Discussions
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Log message formatter that provides colorized console output with timestamps
|
|
3
|
+
* Handles ANSI color codes and structured log message formatting
|
|
4
|
+
*/
|
|
5
|
+
import { LogLevel } from './types';
|
|
6
|
+
/**
|
|
7
|
+
* LogFormatter class responsible for formatting log messages with colors and timestamps
|
|
8
|
+
* Creates readable, colored console output with ISO timestamps and local time
|
|
9
|
+
*/
|
|
10
|
+
export declare class LogFormatter {
|
|
11
|
+
private static readonly colors;
|
|
12
|
+
/**
|
|
13
|
+
* Formats a log message with timestamp, level indicator, and appropriate coloring
|
|
14
|
+
* Creates a structured log entry: [ISO_TIMESTAMP][LOCAL_TIME][LEVEL]: message
|
|
15
|
+
* @param level - The log level to format for
|
|
16
|
+
* @param message - The message content to format
|
|
17
|
+
* @returns Formatted string with ANSI colors and timestamps
|
|
18
|
+
*/
|
|
19
|
+
static format(level: LogLevel, message: string): string;
|
|
20
|
+
/**
|
|
21
|
+
* Formats a Log Engine system message with [LOG ENGINE] prefix instead of log levels
|
|
22
|
+
* Used for internal messages like deprecation warnings that should be distinguished from user logs
|
|
23
|
+
* @param message - The system message content to format
|
|
24
|
+
* @returns Formatted string with ANSI colors, timestamps, and LOG ENGINE prefix
|
|
25
|
+
*/
|
|
26
|
+
static formatSystemMessage(message: string): string;
|
|
27
|
+
/**
|
|
28
|
+
* Converts LogLevel enum to human-readable string
|
|
29
|
+
* @param level - The LogLevel to convert
|
|
30
|
+
* @returns String representation of the log level
|
|
31
|
+
*/
|
|
32
|
+
private static getLevelName;
|
|
33
|
+
/**
|
|
34
|
+
* Maps LogLevel to appropriate ANSI color code
|
|
35
|
+
* Colors help quickly identify message severity in console output
|
|
36
|
+
* @param level - The LogLevel to get color for
|
|
37
|
+
* @returns ANSI color escape sequence
|
|
38
|
+
*/
|
|
39
|
+
private static getLevelColor;
|
|
40
|
+
}
|
|
41
|
+
//# sourceMappingURL=formatter.d.ts.map
|
|
@@ -0,0 +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;;;;;;OAMG;IACH,MAAM,CAAC,MAAM,CAAC,KAAK,EAAE,QAAQ,EAAE,OAAO,EAAE,MAAM,GAAG,MAAM;IAoBvD;;;;;OAKG;IACH,MAAM,CAAC,mBAAmB,CAAC,OAAO,EAAE,MAAM,GAAG,MAAM;IAkBnD;;;;OAIG;IACH,OAAO,CAAC,MAAM,CAAC,YAAY;IAW3B;;;;;OAKG;IACH,OAAO,CAAC,MAAM,CAAC,aAAa;CAU/B"}
|
package/dist/formatter.js
CHANGED
|
@@ -34,6 +34,27 @@ class LogFormatter {
|
|
|
34
34
|
const coloredLevel = `${levelColor}[${levelName}]${this.colors.reset}`;
|
|
35
35
|
return `${coloredTimestamp}${coloredTimeString}${coloredLevel}: ${message}`;
|
|
36
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
|
+
});
|
|
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
|
+
}
|
|
37
58
|
/**
|
|
38
59
|
* Converts LogLevel enum to human-readable string
|
|
39
60
|
* @param level - The LogLevel to convert
|
|
@@ -45,7 +66,7 @@ class LogFormatter {
|
|
|
45
66
|
case types_1.LogLevel.INFO: return 'INFO';
|
|
46
67
|
case types_1.LogLevel.WARN: return 'WARN';
|
|
47
68
|
case types_1.LogLevel.ERROR: return 'ERROR';
|
|
48
|
-
case types_1.LogLevel.
|
|
69
|
+
case types_1.LogLevel.LOG: return 'LOG';
|
|
49
70
|
default: return 'UNKNOWN';
|
|
50
71
|
}
|
|
51
72
|
}
|
|
@@ -61,7 +82,7 @@ class LogFormatter {
|
|
|
61
82
|
case types_1.LogLevel.INFO: return this.colors.blue; // Blue for general info
|
|
62
83
|
case types_1.LogLevel.WARN: return this.colors.yellow; // Yellow for warnings
|
|
63
84
|
case types_1.LogLevel.ERROR: return this.colors.red; // Red for errors
|
|
64
|
-
case types_1.LogLevel.
|
|
85
|
+
case types_1.LogLevel.LOG: return this.colors.green; // Green for always-on log messages
|
|
65
86
|
default: return this.colors.white; // White for unknown levels
|
|
66
87
|
}
|
|
67
88
|
}
|
|
@@ -77,5 +98,6 @@ LogFormatter.colors = {
|
|
|
77
98
|
magenta: '\x1b[35m', // Magenta text (debug)
|
|
78
99
|
cyan: '\x1b[36m', // Cyan text (timestamps)
|
|
79
100
|
white: '\x1b[37m', // White text (default)
|
|
80
|
-
gray: '\x1b[90m' // Gray text (timestamps)
|
|
101
|
+
gray: '\x1b[90m', // Gray text (timestamps)
|
|
102
|
+
green: '\x1b[32m' // Green text (log level)
|
|
81
103
|
};
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Main entry point for the Log Engine library
|
|
3
|
+
* Provides a simple, configurable logging interface with environment-based auto-configuration
|
|
4
|
+
*/
|
|
5
|
+
import { LoggerConfig } from './types';
|
|
6
|
+
/**
|
|
7
|
+
* Main LogEngine API - provides all logging functionality with a clean interface
|
|
8
|
+
* Auto-configured based on NODE_ENV, but can be reconfigured at runtime
|
|
9
|
+
*/
|
|
10
|
+
export declare const LogEngine: {
|
|
11
|
+
/**
|
|
12
|
+
* Configure the logger with custom settings
|
|
13
|
+
* @param config - Partial configuration object containing level and/or environment
|
|
14
|
+
* @example
|
|
15
|
+
* ```typescript
|
|
16
|
+
* LogEngine.configure({ level: LogLevel.DEBUG });
|
|
17
|
+
* LogEngine.configure({ level: LogLevel.WARN, environment: 'staging' });
|
|
18
|
+
* ```
|
|
19
|
+
*/
|
|
20
|
+
configure: (config: Partial<LoggerConfig>) => void;
|
|
21
|
+
/**
|
|
22
|
+
* Log a debug message (lowest priority)
|
|
23
|
+
* Only shown when log level is DEBUG or lower
|
|
24
|
+
* Useful for detailed diagnostic information during development
|
|
25
|
+
* @param message - The debug message to log
|
|
26
|
+
* @example
|
|
27
|
+
* ```typescript
|
|
28
|
+
* LogEngine.debug('User authentication flow started');
|
|
29
|
+
* LogEngine.debug(`Processing ${items.length} items`);
|
|
30
|
+
* ```
|
|
31
|
+
*/
|
|
32
|
+
debug: (message: string) => void;
|
|
33
|
+
/**
|
|
34
|
+
* Log an informational message
|
|
35
|
+
* General information about application flow and state
|
|
36
|
+
* Shown when log level is INFO or lower
|
|
37
|
+
* @param message - The info message to log
|
|
38
|
+
* @example
|
|
39
|
+
* ```typescript
|
|
40
|
+
* LogEngine.info('Application started successfully');
|
|
41
|
+
* LogEngine.info('User logged in: john@example.com');
|
|
42
|
+
* ```
|
|
43
|
+
*/
|
|
44
|
+
info: (message: string) => void;
|
|
45
|
+
/**
|
|
46
|
+
* Log a warning message
|
|
47
|
+
* Indicates potential issues that don't prevent operation
|
|
48
|
+
* Shown when log level is WARN or lower
|
|
49
|
+
* @param message - The warning message to log
|
|
50
|
+
* @example
|
|
51
|
+
* ```typescript
|
|
52
|
+
* LogEngine.warn('API rate limit approaching');
|
|
53
|
+
* LogEngine.warn('Deprecated function called');
|
|
54
|
+
* ```
|
|
55
|
+
*/
|
|
56
|
+
warn: (message: string) => void;
|
|
57
|
+
/**
|
|
58
|
+
* Log an error message (highest priority)
|
|
59
|
+
* Indicates serious problems that need attention
|
|
60
|
+
* Always shown unless log level is SILENT
|
|
61
|
+
* @param message - The error message to log
|
|
62
|
+
* @example
|
|
63
|
+
* ```typescript
|
|
64
|
+
* LogEngine.error('Database connection failed');
|
|
65
|
+
* LogEngine.error('Authentication token expired');
|
|
66
|
+
* ```
|
|
67
|
+
*/
|
|
68
|
+
error: (message: string) => void;
|
|
69
|
+
/**
|
|
70
|
+
* Log a critical message that always outputs
|
|
71
|
+
* Essential messages that should always be visible regardless of log mode
|
|
72
|
+
* Always shown no matter what log mode is configured (except OFF mode)
|
|
73
|
+
* @param message - The critical log message to log
|
|
74
|
+
* @example
|
|
75
|
+
* ```typescript
|
|
76
|
+
* LogEngine.log('Application starting up');
|
|
77
|
+
* LogEngine.log('Server listening on port 3000');
|
|
78
|
+
* LogEngine.log('Graceful shutdown initiated');
|
|
79
|
+
* ```
|
|
80
|
+
*/
|
|
81
|
+
log: (message: string) => void;
|
|
82
|
+
};
|
|
83
|
+
export { LogLevel, LogMode, LoggerConfig } from './types';
|
|
84
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAGH,OAAO,EAAW,YAAY,EAAE,MAAM,SAAS,CAAC;AAiChD;;;GAGG;AACH,eAAO,MAAM,SAAS;IAClB;;;;;;;;OAQG;wBACiB,OAAO,CAAC,YAAY,CAAC;IAEzC;;;;;;;;;;OAUG;qBACc,MAAM;IAEvB;;;;;;;;;;OAUG;oBACa,MAAM;IAEtB;;;;;;;;;;OAUG;oBACa,MAAM;IAEtB;;;;;;;;;;OAUG;qBACc,MAAM;IAEvB;;;;;;;;;;;OAWG;mBACY,MAAM;CACxB,CAAC;AAEF,OAAO,EAAE,QAAQ,EAAE,OAAO,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC"}
|
package/dist/index.js
CHANGED
|
@@ -4,34 +4,37 @@
|
|
|
4
4
|
* Provides a simple, configurable logging interface with environment-based auto-configuration
|
|
5
5
|
*/
|
|
6
6
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
7
|
-
exports.LogLevel = exports.LogEngine = void 0;
|
|
7
|
+
exports.LogMode = exports.LogLevel = exports.LogEngine = void 0;
|
|
8
8
|
const logger_1 = require("./logger");
|
|
9
9
|
const types_1 = require("./types");
|
|
10
10
|
// Create singleton logger instance
|
|
11
11
|
const logger = new logger_1.Logger();
|
|
12
12
|
/**
|
|
13
|
-
* Determines the appropriate default log
|
|
14
|
-
* -
|
|
15
|
-
* -
|
|
16
|
-
* -
|
|
13
|
+
* Determines the appropriate default log mode based on NODE_ENV
|
|
14
|
+
* - development: DEBUG (most verbose - shows all messages)
|
|
15
|
+
* - production: INFO (balanced - shows info, warn, error, log)
|
|
16
|
+
* - staging: WARN (focused - shows warn, error, log only)
|
|
17
|
+
* - test: ERROR (minimal - shows error and log only)
|
|
17
18
|
* - default: INFO (balanced logging for other environments)
|
|
18
|
-
* @returns The appropriate
|
|
19
|
+
* @returns The appropriate LogMode for the current environment
|
|
19
20
|
*/
|
|
20
|
-
const
|
|
21
|
+
const getDefaultLogMode = () => {
|
|
21
22
|
const nodeEnv = process.env.NODE_ENV;
|
|
22
23
|
switch (nodeEnv) {
|
|
23
|
-
case 'production':
|
|
24
|
-
return types_1.LogLevel.WARN;
|
|
25
24
|
case 'development':
|
|
26
|
-
return types_1.
|
|
25
|
+
return types_1.LogMode.DEBUG;
|
|
26
|
+
case 'production':
|
|
27
|
+
return types_1.LogMode.INFO;
|
|
28
|
+
case 'staging':
|
|
29
|
+
return types_1.LogMode.WARN;
|
|
27
30
|
case 'test':
|
|
28
|
-
return types_1.
|
|
31
|
+
return types_1.LogMode.ERROR;
|
|
29
32
|
default:
|
|
30
|
-
return types_1.
|
|
33
|
+
return types_1.LogMode.INFO;
|
|
31
34
|
}
|
|
32
35
|
};
|
|
33
|
-
// Initialize logger with environment-appropriate default
|
|
34
|
-
logger.configure({
|
|
36
|
+
// Initialize logger with environment-appropriate default mode
|
|
37
|
+
logger.configure({ mode: getDefaultLogMode() });
|
|
35
38
|
/**
|
|
36
39
|
* Main LogEngine API - provides all logging functionality with a clean interface
|
|
37
40
|
* Auto-configured based on NODE_ENV, but can be reconfigured at runtime
|
|
@@ -94,7 +97,21 @@ exports.LogEngine = {
|
|
|
94
97
|
* LogEngine.error('Authentication token expired');
|
|
95
98
|
* ```
|
|
96
99
|
*/
|
|
97
|
-
error: (message) => logger.error(message)
|
|
100
|
+
error: (message) => logger.error(message),
|
|
101
|
+
/**
|
|
102
|
+
* Log a critical message that always outputs
|
|
103
|
+
* Essential messages that should always be visible regardless of log mode
|
|
104
|
+
* Always shown no matter what log mode is configured (except OFF mode)
|
|
105
|
+
* @param message - The critical log message to log
|
|
106
|
+
* @example
|
|
107
|
+
* ```typescript
|
|
108
|
+
* LogEngine.log('Application starting up');
|
|
109
|
+
* LogEngine.log('Server listening on port 3000');
|
|
110
|
+
* LogEngine.log('Graceful shutdown initiated');
|
|
111
|
+
* ```
|
|
112
|
+
*/
|
|
113
|
+
log: (message) => logger.log(message)
|
|
98
114
|
};
|
|
99
115
|
var types_2 = require("./types");
|
|
100
116
|
Object.defineProperty(exports, "LogLevel", { enumerable: true, get: function () { return types_2.LogLevel; } });
|
|
117
|
+
Object.defineProperty(exports, "LogMode", { enumerable: true, get: function () { return types_2.LogMode; } });
|
package/dist/logger.d.ts
ADDED
|
@@ -0,0 +1,72 @@
|
|
|
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
|
|
@@ -0,0 +1 @@
|
|
|
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
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
/**
|
|
3
3
|
* Core Logger class that handles log message output with configurable levels
|
|
4
|
-
* Supports DEBUG, INFO, WARN, ERROR levels with intelligent filtering
|
|
4
|
+
* Supports DEBUG, INFO, WARN, ERROR, and LOG levels with intelligent filtering
|
|
5
|
+
* LOG level always outputs regardless of configuration
|
|
5
6
|
* Uses colorized console output with timestamps for better readability
|
|
6
7
|
*/
|
|
7
8
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
@@ -10,31 +11,69 @@ const types_1 = require("./types");
|
|
|
10
11
|
const formatter_1 = require("./formatter");
|
|
11
12
|
/**
|
|
12
13
|
* Logger class responsible for managing log output and configuration
|
|
13
|
-
* Provides
|
|
14
|
+
* Provides mode-based filtering and formatted console output
|
|
14
15
|
*/
|
|
15
16
|
class Logger {
|
|
16
17
|
constructor() {
|
|
17
18
|
// Internal configuration state with sensible defaults
|
|
18
19
|
this.config = {
|
|
19
|
-
|
|
20
|
+
mode: types_1.LogMode.INFO
|
|
20
21
|
};
|
|
21
22
|
}
|
|
22
23
|
/**
|
|
23
24
|
* Updates logger configuration with new settings
|
|
24
25
|
* Merges provided config with existing settings (partial update)
|
|
26
|
+
* Supports backwards compatibility by mapping level to mode with deprecation warnings
|
|
25
27
|
* @param config - Partial configuration object to apply
|
|
26
28
|
*/
|
|
27
29
|
configure(config) {
|
|
28
|
-
|
|
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
|
+
}
|
|
29
60
|
}
|
|
30
61
|
/**
|
|
31
|
-
* Determines if a message should be logged based on current log
|
|
32
|
-
* Messages are shown only if their level
|
|
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
|
|
33
66
|
* @param level - The log level of the message to check
|
|
34
67
|
* @returns true if message should be logged, false otherwise
|
|
35
68
|
*/
|
|
36
69
|
shouldLog(level) {
|
|
37
|
-
|
|
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;
|
|
38
77
|
}
|
|
39
78
|
/**
|
|
40
79
|
* Log a debug message with DEBUG level formatting
|
|
@@ -80,5 +119,40 @@ class Logger {
|
|
|
80
119
|
console.error(formatted);
|
|
81
120
|
}
|
|
82
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
|
+
}
|
|
83
134
|
}
|
|
84
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
|
+
};
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Type definitions for the Log Engine library
|
|
3
|
+
* Provides strongly-typed interfaces for configuration and log levels
|
|
4
|
+
*/
|
|
5
|
+
/**
|
|
6
|
+
* Log levels representing message severity (lowest to highest)
|
|
7
|
+
* Used for filtering messages based on importance
|
|
8
|
+
*/
|
|
9
|
+
export declare enum LogLevel {
|
|
10
|
+
/** Detailed diagnostic information, typically only of interest during development */
|
|
11
|
+
DEBUG = 0,
|
|
12
|
+
/** General information about application flow and state */
|
|
13
|
+
INFO = 1,
|
|
14
|
+
/** Potentially harmful situations that don't prevent operation */
|
|
15
|
+
WARN = 2,
|
|
16
|
+
/** Error events that might still allow the application to continue */
|
|
17
|
+
ERROR = 3,
|
|
18
|
+
/** Critical messages that always output regardless of configured mode (except when OFF is set) */
|
|
19
|
+
LOG = 99
|
|
20
|
+
}
|
|
21
|
+
/**
|
|
22
|
+
* Log modes controlling output behavior and filtering
|
|
23
|
+
* Determines what messages are displayed based on verbosity requirements
|
|
24
|
+
*/
|
|
25
|
+
export declare enum LogMode {
|
|
26
|
+
/** Most verbose - shows DEBUG, INFO, WARN, ERROR, LOG messages */
|
|
27
|
+
DEBUG = 0,
|
|
28
|
+
/** Balanced - shows INFO, WARN, ERROR, LOG messages */
|
|
29
|
+
INFO = 1,
|
|
30
|
+
/** Focused - shows WARN, ERROR, LOG messages */
|
|
31
|
+
WARN = 2,
|
|
32
|
+
/** Minimal - shows ERROR, LOG messages */
|
|
33
|
+
ERROR = 3,
|
|
34
|
+
/** Critical only - shows LOG messages only */
|
|
35
|
+
SILENT = 4,
|
|
36
|
+
/** Complete silence - shows no messages at all */
|
|
37
|
+
OFF = 5
|
|
38
|
+
}
|
|
39
|
+
/**
|
|
40
|
+
* Represents a single log entry with timestamp, level, and message
|
|
41
|
+
* Used internally for structured logging operations
|
|
42
|
+
*/
|
|
43
|
+
export interface LogEntry {
|
|
44
|
+
/** When the log entry was created */
|
|
45
|
+
timestamp: Date;
|
|
46
|
+
/** The severity level of this log entry */
|
|
47
|
+
level: LogLevel;
|
|
48
|
+
/** The actual log message content */
|
|
49
|
+
message: string;
|
|
50
|
+
}
|
|
51
|
+
/**
|
|
52
|
+
* Configuration options for the logger
|
|
53
|
+
* Supports both legacy level-based and new mode-based configuration
|
|
54
|
+
*/
|
|
55
|
+
export interface LoggerConfig {
|
|
56
|
+
/** Log mode controlling output behavior (new API) */
|
|
57
|
+
mode?: LogMode;
|
|
58
|
+
/** Legacy: Minimum log level to display (backwards compatibility)
|
|
59
|
+
* Note: If both mode and level are provided, mode takes precedence */
|
|
60
|
+
level?: LogLevel;
|
|
61
|
+
/** Optional environment identifier for context (e.g., 'production', 'staging') */
|
|
62
|
+
environment?: string;
|
|
63
|
+
}
|
|
64
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/types/index.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH;;;GAGG;AACH,oBAAY,QAAQ;IAChB,qFAAqF;IACrF,KAAK,IAAI;IACT,2DAA2D;IAC3D,IAAI,IAAI;IACR,kEAAkE;IAClE,IAAI,IAAI;IACR,sEAAsE;IACtE,KAAK,IAAI;IACT,kGAAkG;IAClG,GAAG,KAAK;CACX;AAED;;;GAGG;AACH,oBAAY,OAAO;IACf,kEAAkE;IAClE,KAAK,IAAI;IACT,uDAAuD;IACvD,IAAI,IAAI;IACR,gDAAgD;IAChD,IAAI,IAAI;IACR,0CAA0C;IAC1C,KAAK,IAAI;IACT,8CAA8C;IAC9C,MAAM,IAAI;IACV,kDAAkD;IAClD,GAAG,IAAI;CACV;AAED;;;GAGG;AACH,MAAM,WAAW,QAAQ;IACrB,qCAAqC;IACrC,SAAS,EAAE,IAAI,CAAC;IAChB,2CAA2C;IAC3C,KAAK,EAAE,QAAQ,CAAC;IAChB,qCAAqC;IACrC,OAAO,EAAE,MAAM,CAAC;CACnB;AAED;;;GAGG;AACH,MAAM,WAAW,YAAY;IACzB,qDAAqD;IACrD,IAAI,CAAC,EAAE,OAAO,CAAC;IACf;0EACsE;IACtE,KAAK,CAAC,EAAE,QAAQ,CAAC;IACjB,kFAAkF;IAClF,WAAW,CAAC,EAAE,MAAM,CAAC;CACxB"}
|
package/dist/types/index.js
CHANGED
|
@@ -4,11 +4,10 @@
|
|
|
4
4
|
* Provides strongly-typed interfaces for configuration and log levels
|
|
5
5
|
*/
|
|
6
6
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
7
|
-
exports.LogLevel = void 0;
|
|
7
|
+
exports.LogMode = exports.LogLevel = void 0;
|
|
8
8
|
/**
|
|
9
|
-
* Log levels
|
|
10
|
-
*
|
|
11
|
-
* When a level is set, only messages at that level or higher are shown
|
|
9
|
+
* Log levels representing message severity (lowest to highest)
|
|
10
|
+
* Used for filtering messages based on importance
|
|
12
11
|
*/
|
|
13
12
|
var LogLevel;
|
|
14
13
|
(function (LogLevel) {
|
|
@@ -20,6 +19,25 @@ var LogLevel;
|
|
|
20
19
|
LogLevel[LogLevel["WARN"] = 2] = "WARN";
|
|
21
20
|
/** Error events that might still allow the application to continue */
|
|
22
21
|
LogLevel[LogLevel["ERROR"] = 3] = "ERROR";
|
|
23
|
-
/**
|
|
24
|
-
LogLevel[LogLevel["
|
|
22
|
+
/** Critical messages that always output regardless of configured mode (except when OFF is set) */
|
|
23
|
+
LogLevel[LogLevel["LOG"] = 99] = "LOG";
|
|
25
24
|
})(LogLevel || (exports.LogLevel = LogLevel = {}));
|
|
25
|
+
/**
|
|
26
|
+
* Log modes controlling output behavior and filtering
|
|
27
|
+
* Determines what messages are displayed based on verbosity requirements
|
|
28
|
+
*/
|
|
29
|
+
var LogMode;
|
|
30
|
+
(function (LogMode) {
|
|
31
|
+
/** Most verbose - shows DEBUG, INFO, WARN, ERROR, LOG messages */
|
|
32
|
+
LogMode[LogMode["DEBUG"] = 0] = "DEBUG";
|
|
33
|
+
/** Balanced - shows INFO, WARN, ERROR, LOG messages */
|
|
34
|
+
LogMode[LogMode["INFO"] = 1] = "INFO";
|
|
35
|
+
/** Focused - shows WARN, ERROR, LOG messages */
|
|
36
|
+
LogMode[LogMode["WARN"] = 2] = "WARN";
|
|
37
|
+
/** Minimal - shows ERROR, LOG messages */
|
|
38
|
+
LogMode[LogMode["ERROR"] = 3] = "ERROR";
|
|
39
|
+
/** Critical only - shows LOG messages only */
|
|
40
|
+
LogMode[LogMode["SILENT"] = 4] = "SILENT";
|
|
41
|
+
/** Complete silence - shows no messages at all */
|
|
42
|
+
LogMode[LogMode["OFF"] = 5] = "OFF";
|
|
43
|
+
})(LogMode || (exports.LogMode = LogMode = {}));
|