@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
package/README.md
CHANGED
|
@@ -4,9 +4,9 @@
|
|
|
4
4
|
|
|
5
5
|
[](https://github.com/wgtechlabs/log-engine)
|
|
6
6
|
|
|
7
|
-
WG's Log Engine is the **ultimate logging solution for Node.js developers** - a lightweight, battle-tested utility specifically engineered for Discord bots, Telegram bots, web servers, APIs, and server-side applications. Born from real-world development challenges and proven in production environments like the [Unthread Discord Bot](https://github.com/wgtechlabs/unthread-discord-bot/), Log Engine delivers enterprise-grade logging with zero complexity
|
|
7
|
+
WG's Log Engine is the **ultimate logging solution for Node.js developers** - a lightweight, battle-tested utility specifically engineered for Discord bots, Telegram bots, web servers, APIs, and server-side applications. Born from real-world development challenges and proven in production environments like the [Unthread Discord Bot](https://github.com/wgtechlabs/unthread-discord-bot/), Log Engine delivers enterprise-grade logging with zero complexity, beautiful color-coded console output, and **advanced automatic data redaction with comprehensive PII protection**.
|
|
8
8
|
|
|
9
|
-
**Stop wrestling with logging configurations and start building amazing applications
|
|
9
|
+
**The first logging library with built-in advanced PII protection and comprehensive TypeScript support.** Stop wrestling with logging configurations and start building amazing applications safely. Whether you're creating the next viral Discord community bot, building high-performance APIs, developing microservices, or deploying production servers, Log Engine provides intelligent terminal-based logging with vibrant colors, advanced customizable redaction patterns, and automatic sensitive data protection that scales with your application's growth - from your first "Hello World" to handling millions of requests across distributed systems.
|
|
10
10
|
|
|
11
11
|
## ❣️ Motivation
|
|
12
12
|
|
|
@@ -16,15 +16,19 @@ Log Engine transforms your development experience from chaotic debugging session
|
|
|
16
16
|
|
|
17
17
|
## ✨ Key Features
|
|
18
18
|
|
|
19
|
-
-
|
|
20
|
-
-
|
|
21
|
-
-
|
|
22
|
-
-
|
|
23
|
-
-
|
|
24
|
-
-
|
|
25
|
-
-
|
|
26
|
-
-
|
|
27
|
-
-
|
|
19
|
+
- **🔒 Advanced Data Redaction (Enhanced!)**: Built-in PII protection with **custom regex patterns**, **dynamic field management**, and **environment-based configuration** - the first logging library with comprehensive security-first logging by default.
|
|
20
|
+
- **⚡ Custom Redaction Patterns**: Add your own regex patterns for advanced field detection and enterprise-specific data protection requirements.
|
|
21
|
+
- **🎯 Dynamic Field Management**: Runtime configuration of sensitive fields with case-insensitive matching and partial field name detection.
|
|
22
|
+
- **🛠️ Developer-Friendly API**: Advanced redaction methods including `testFieldRedaction()`, `withoutRedaction()`, and comprehensive configuration management.
|
|
23
|
+
- **📊 Comprehensive TypeScript Support**: Full type definitions with 10+ interfaces covering all functionality for maximum developer experience and IDE support.
|
|
24
|
+
- **🚀 Lightweight & Fast**: Minimal overhead with maximum performance - designed to enhance your application, not slow it down.
|
|
25
|
+
- **📚 No Learning Curve**: Dead simple API that you can master in seconds. No extensive documentation, complex configurations, or setup required - Log Engine works instantly.
|
|
26
|
+
- **🌈 Colorized Console Output**: Beautiful ANSI color-coded log levels with intelligent terminal formatting - instantly identify message severity at a glance with color-coded output.
|
|
27
|
+
- **🎛️ 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.
|
|
28
|
+
- **⚙️ 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.
|
|
29
|
+
- **✨ Enhanced Formatting**: Structured log entries with dual timestamps (ISO + human-readable) and colored level indicators for maximum readability.
|
|
30
|
+
- **🔗 Zero Dependencies**: No external dependencies for maximum compatibility and security - keeps your bundle clean and your project simple.
|
|
31
|
+
- **🔌 Easy Integration**: Simple API that works seamlessly with existing Node.js applications. Just `import` and start logging - no middleware, plugins, or configuration required.
|
|
28
32
|
|
|
29
33
|
## 🤔 How It Works
|
|
30
34
|
<!-- markdownlint-disable MD051 -->
|
|
@@ -78,6 +82,25 @@ LogEngine.info('This is an info message');
|
|
|
78
82
|
LogEngine.warn('This is a warning message');
|
|
79
83
|
LogEngine.error('This is an error message');
|
|
80
84
|
LogEngine.log('This is a critical message that always shows');
|
|
85
|
+
|
|
86
|
+
// Advanced automatic data redaction (no configuration needed!)
|
|
87
|
+
LogEngine.info('User login', {
|
|
88
|
+
username: 'john_doe', // ✅ Visible
|
|
89
|
+
password: 'secret123', // ❌ [REDACTED]
|
|
90
|
+
email: 'john@example.com', // ❌ [REDACTED]
|
|
91
|
+
apiKey: 'apikey123' // ❌ [REDACTED]
|
|
92
|
+
});
|
|
93
|
+
|
|
94
|
+
// Advanced redaction features - Add custom patterns
|
|
95
|
+
LogEngine.addCustomRedactionPatterns([/internal.*/i, /company.*/i]);
|
|
96
|
+
LogEngine.addSensitiveFields(['companySecret', 'internalToken']);
|
|
97
|
+
|
|
98
|
+
// Test field redaction
|
|
99
|
+
console.log(LogEngine.testFieldRedaction('password')); // true
|
|
100
|
+
console.log(LogEngine.testFieldRedaction('username')); // false
|
|
101
|
+
|
|
102
|
+
// Raw logging for debugging (bypasses redaction)
|
|
103
|
+
LogEngine.withoutRedaction().info('Debug data', { password: 'visible-in-debug' });
|
|
81
104
|
```
|
|
82
105
|
|
|
83
106
|
### Mode-Based Configuration (Recommended)
|
|
@@ -137,15 +160,17 @@ LogEngine.configure({ level: LogLevel.ERROR });
|
|
|
137
160
|
import { LogEngine, LogLevel } from '@wgtechlabs/log-engine';
|
|
138
161
|
LogEngine.configure({ level: LogLevel.DEBUG });
|
|
139
162
|
|
|
140
|
-
// NEW (v1.2.
|
|
163
|
+
// NEW (v1.2.1+) - recommended approach with advanced features
|
|
141
164
|
import { LogEngine, LogMode } from '@wgtechlabs/log-engine';
|
|
142
165
|
LogEngine.configure({ mode: LogMode.DEBUG });
|
|
143
166
|
```
|
|
144
167
|
|
|
145
168
|
**Key Benefits of LogMode:**
|
|
169
|
+
|
|
146
170
|
- **Clearer API**: Separates message severity (`LogLevel`) from output control (`LogMode`)
|
|
147
171
|
- **Better Environment Defaults**: `development→DEBUG`, `staging→WARN`, `test→ERROR`
|
|
148
|
-
- **
|
|
172
|
+
- **Advanced Features**: New redaction APIs and TypeScript interfaces work with LogMode
|
|
173
|
+
- **Future-Proof**: All new features use the LogMode system
|
|
149
174
|
- **100% Backwards Compatible**: Existing code continues to work unchanged
|
|
150
175
|
|
|
151
176
|
### Color-Coded Output 🎨
|
|
@@ -255,11 +280,11 @@ Log messages are beautifully formatted with colorized timestamps, levels, and sm
|
|
|
255
280
|
|
|
256
281
|
```bash
|
|
257
282
|
# Example colorized output (colors visible in terminal)
|
|
258
|
-
[2025-05-29T16:57:45.678Z][4:
|
|
259
|
-
[2025-05-29T16:57:46.123Z][4:
|
|
260
|
-
[2025-05-29T16:57:47.456Z][4:
|
|
261
|
-
[2025-05-29T16:57:48.789Z][4:
|
|
262
|
-
[2025-05-29T16:57:49.012Z][4:
|
|
283
|
+
[2025-05-29T16:57:45.678Z][4:57PM][DEBUG]: Debugging application flow
|
|
284
|
+
[2025-05-29T16:57:46.123Z][4:57PM][INFO]: Server started successfully
|
|
285
|
+
[2025-05-29T16:57:47.456Z][4:57PM][WARN]: API rate limit approaching
|
|
286
|
+
[2025-05-29T16:57:48.789Z][4:57PM][ERROR]: Database connection failed
|
|
287
|
+
[2025-05-29T16:57:49.012Z][4:57PM][LOG]: Application startup complete
|
|
263
288
|
```
|
|
264
289
|
|
|
265
290
|
**Color Scheme:**
|
|
@@ -271,6 +296,244 @@ Log messages are beautifully formatted with colorized timestamps, levels, and sm
|
|
|
271
296
|
- 🟢 **LOG**: Green - Critical messages that always display
|
|
272
297
|
- ⚫ **Timestamps**: Gray (ISO) and Cyan (local time) for easy scanning
|
|
273
298
|
|
|
299
|
+
## 🔒 Advanced Data Redaction
|
|
300
|
+
|
|
301
|
+
**LogEngine features comprehensive built-in PII protection with advanced customization capabilities that automatically redacts sensitive information from your logs.** This security-first approach prevents accidental exposure of passwords, tokens, emails, and other sensitive data while maintaining full debugging capabilities with enterprise-grade flexibility.
|
|
302
|
+
|
|
303
|
+
### Zero Configuration Security
|
|
304
|
+
|
|
305
|
+
Just use LogEngine normally - **sensitive data is automatically protected**:
|
|
306
|
+
|
|
307
|
+
```typescript
|
|
308
|
+
import { LogEngine } from '@wgtechlabs/log-engine';
|
|
309
|
+
|
|
310
|
+
// ✅ Automatic redaction - no setup needed!
|
|
311
|
+
LogEngine.info('User authentication', {
|
|
312
|
+
username: 'john_doe', // ✅ Visible
|
|
313
|
+
password: 'secret123', // ❌ [REDACTED]
|
|
314
|
+
email: 'john@example.com', // ❌ [REDACTED]
|
|
315
|
+
apiKey: 'apikey123', // ❌ [REDACTED]
|
|
316
|
+
timestamp: new Date() // ✅ Visible
|
|
317
|
+
});
|
|
318
|
+
|
|
319
|
+
// Output: [INFO]: User authentication {"username":"john_doe","password":"[REDACTED]","email":"[REDACTED]","apiKey":"[REDACTED]","timestamp":"2025-06-17T..."}
|
|
320
|
+
```
|
|
321
|
+
|
|
322
|
+
### Protected Data Types
|
|
323
|
+
|
|
324
|
+
**50+ sensitive patterns automatically detected:**
|
|
325
|
+
|
|
326
|
+
- **Authentication**: `password`, `token`, `apiKey`, `secret`, `jwt`, `auth`, `sessionId`
|
|
327
|
+
- **Personal Info**: `email`, `phone`, `ssn`, `firstName`, `lastName`, `address`
|
|
328
|
+
- **Financial**: `creditCard`, `cvv`, `bankAccount`, `routingNumber`
|
|
329
|
+
- **System**: `clientSecret`, `privateKey`, `webhookSecret`
|
|
330
|
+
|
|
331
|
+
### Deep Object Scanning
|
|
332
|
+
|
|
333
|
+
Automatically scans nested objects and arrays:
|
|
334
|
+
|
|
335
|
+
```typescript
|
|
336
|
+
LogEngine.warn('Payment processing', {
|
|
337
|
+
order: {
|
|
338
|
+
id: 'order-123', // ✅ Visible
|
|
339
|
+
customer: {
|
|
340
|
+
username: 'customer1', // ✅ Visible
|
|
341
|
+
email: 'user@example.com', // ❌ [REDACTED]
|
|
342
|
+
creditCard: '4532-****' // ❌ [REDACTED]
|
|
343
|
+
}
|
|
344
|
+
},
|
|
345
|
+
metadata: {
|
|
346
|
+
processor: 'stripe',
|
|
347
|
+
apiSecret: 'sk_live_...' // ❌ [REDACTED]
|
|
348
|
+
}
|
|
349
|
+
});
|
|
350
|
+
```
|
|
351
|
+
|
|
352
|
+
### Content Truncation
|
|
353
|
+
|
|
354
|
+
Large content fields are automatically truncated to prevent log bloat:
|
|
355
|
+
|
|
356
|
+
```typescript
|
|
357
|
+
LogEngine.debug('Large payload', {
|
|
358
|
+
content: 'Very long content...'.repeat(100), // Truncated at 100 chars + "... [TRUNCATED]"
|
|
359
|
+
size: 'large',
|
|
360
|
+
processed: true
|
|
361
|
+
});
|
|
362
|
+
```
|
|
363
|
+
|
|
364
|
+
### Development-Friendly Features
|
|
365
|
+
|
|
366
|
+
**Raw Methods for Debugging:**
|
|
367
|
+
|
|
368
|
+
```typescript
|
|
369
|
+
// ⚠️ Use with caution - bypasses redaction
|
|
370
|
+
LogEngine.debugRaw('Full debug data', {
|
|
371
|
+
password: 'secret123', // ⚠️ Visible (not redacted)
|
|
372
|
+
apiKey: 'full-key' // ⚠️ Visible (not redacted)
|
|
373
|
+
});
|
|
374
|
+
|
|
375
|
+
// Or use the helper method
|
|
376
|
+
LogEngine.withoutRedaction().info('Debug mode', sensitiveData);
|
|
377
|
+
```
|
|
378
|
+
|
|
379
|
+
**Environment-Based Control:**
|
|
380
|
+
|
|
381
|
+
```bash
|
|
382
|
+
# Development - show everything (redaction disabled)
|
|
383
|
+
NODE_ENV=development
|
|
384
|
+
|
|
385
|
+
# Explicitly disable redaction
|
|
386
|
+
LOG_REDACTION_DISABLED=true
|
|
387
|
+
DEBUG_FULL_PAYLOADS=true
|
|
388
|
+
|
|
389
|
+
# Custom redaction configuration
|
|
390
|
+
LOG_REDACTION_TEXT="***CONFIDENTIAL***"
|
|
391
|
+
LOG_MAX_CONTENT_LENGTH=200
|
|
392
|
+
LOG_SENSITIVE_FIELDS="customField,companySecret,internalData"
|
|
393
|
+
LOG_TRUNCATION_TEXT="... [CUSTOM_TRUNCATED]"
|
|
394
|
+
|
|
395
|
+
# Advanced environment integration
|
|
396
|
+
LOG_REDACTION_ENABLED=false # Alternative disable method
|
|
397
|
+
```
|
|
398
|
+
|
|
399
|
+
### Custom Configuration
|
|
400
|
+
|
|
401
|
+
**Modify redaction behavior:**
|
|
402
|
+
|
|
403
|
+
```typescript
|
|
404
|
+
// Custom redaction settings
|
|
405
|
+
LogEngine.configureRedaction({
|
|
406
|
+
redactionText: '***HIDDEN***',
|
|
407
|
+
maxContentLength: 200,
|
|
408
|
+
sensitiveFields: ['myCustomField', 'internalSecret']
|
|
409
|
+
});
|
|
410
|
+
|
|
411
|
+
// Get current configuration
|
|
412
|
+
const config = LogEngine.getRedactionConfig();
|
|
413
|
+
console.log(config);
|
|
414
|
+
```
|
|
415
|
+
|
|
416
|
+
### Advanced Redaction Features (v1.2.1+)
|
|
417
|
+
|
|
418
|
+
**Custom Patterns & Dynamic Field Management:**
|
|
419
|
+
|
|
420
|
+
```typescript
|
|
421
|
+
// Add custom regex patterns for enterprise-specific data protection
|
|
422
|
+
LogEngine.addCustomRedactionPatterns([
|
|
423
|
+
/internal.*/i, // Matches any field starting with "internal"
|
|
424
|
+
/company.*/i, // Matches any field starting with "company"
|
|
425
|
+
/^config[A-Z]/ // Matches camelCase config fields
|
|
426
|
+
]);
|
|
427
|
+
|
|
428
|
+
// Add custom sensitive field names dynamically
|
|
429
|
+
LogEngine.addSensitiveFields(['companySecret', 'internalToken', 'proprietaryData']);
|
|
430
|
+
|
|
431
|
+
// Test field redaction before logging
|
|
432
|
+
if (LogEngine.testFieldRedaction('myField')) {
|
|
433
|
+
console.log('Field will be redacted');
|
|
434
|
+
}
|
|
435
|
+
|
|
436
|
+
// Advanced configuration management
|
|
437
|
+
LogEngine.configureRedaction({
|
|
438
|
+
redactionText: '***CONFIDENTIAL***',
|
|
439
|
+
maxContentLength: 150,
|
|
440
|
+
customPatterns: [/private.*/i, /secret.*/i]
|
|
441
|
+
});
|
|
442
|
+
|
|
443
|
+
// Configuration utilities
|
|
444
|
+
const currentConfig = LogEngine.getRedactionConfig();
|
|
445
|
+
LogEngine.refreshRedactionConfig(); // Refresh from environment
|
|
446
|
+
LogEngine.resetRedactionConfig(); // Reset to defaults
|
|
447
|
+
LogEngine.clearCustomRedactionPatterns(); // Clear custom patterns
|
|
448
|
+
```
|
|
449
|
+
|
|
450
|
+
**Enhanced Development Workflow:**
|
|
451
|
+
|
|
452
|
+
```typescript
|
|
453
|
+
// Raw logging methods (bypass redaction) - use with caution
|
|
454
|
+
LogEngine.debugRaw('Full debug data', { password: 'visible', apiKey: 'full-key' });
|
|
455
|
+
|
|
456
|
+
// Temporary redaction bypass using helper method
|
|
457
|
+
LogEngine.withoutRedaction().info('Debug mode', sensitiveData);
|
|
458
|
+
|
|
459
|
+
// Compare outputs during development
|
|
460
|
+
LogEngine.info('With redaction', data); // ❌ [REDACTED]
|
|
461
|
+
LogEngine.withoutRedaction().info('Without redaction', data); // ⚠️ Visible
|
|
462
|
+
```
|
|
463
|
+
|
|
464
|
+
### Environment Behavior
|
|
465
|
+
|
|
466
|
+
| Environment | Redaction Status | Use Case |
|
|
467
|
+
|-------------|------------------|----------|
|
|
468
|
+
| **Production** | 🔒 **Active** | Full protection for live systems |
|
|
469
|
+
| **Development** | 🛠️ **Disabled** | Full data visibility for debugging |
|
|
470
|
+
| **Staging** | 🔒 **Active** | Test with production-like security |
|
|
471
|
+
| **Test** | 🔒 **Active** | Consistent test environment |
|
|
472
|
+
|
|
473
|
+
### Security Benefits
|
|
474
|
+
|
|
475
|
+
✅ **Advanced Pattern Recognition** - Custom regex patterns for enterprise-specific data protection
|
|
476
|
+
✅ **Dynamic Field Management** - Runtime configuration of sensitive fields with intelligent matching
|
|
477
|
+
✅ **Comprehensive Testing API** - `testFieldRedaction()` for validation and debugging
|
|
478
|
+
✅ **Environment Integration** - Seamless configuration via environment variables
|
|
479
|
+
✅ **Development Workflow** - Raw logging methods and temporary redaction bypass for debugging
|
|
480
|
+
✅ **Prevents Data Leaks** - Automatic protection against accidental exposure with 50+ built-in patterns
|
|
481
|
+
✅ **Compliance Ready** - Helps meet GDPR, HIPAA, and other privacy requirements
|
|
482
|
+
✅ **Zero Configuration** - Secure by default, advanced features when needed
|
|
483
|
+
✅ **Performance Optimized** - Minimal overhead with intelligent processing and depth limiting
|
|
484
|
+
✅ **TypeScript Excellence** - Full type safety with comprehensive interfaces and type definitions
|
|
485
|
+
|
|
486
|
+
**Perfect for:** Enterprise applications, compliance requirements, team development environments, production systems requiring both security and debugging flexibility, and any scenario where sensitive data protection is critical.
|
|
487
|
+
|
|
488
|
+
## 📚 Comprehensive TypeScript Support
|
|
489
|
+
|
|
490
|
+
**LogEngine v1.2.1+ includes extensive TypeScript definitions with 10+ interfaces for maximum type safety and developer experience:**
|
|
491
|
+
|
|
492
|
+
### Core Interfaces
|
|
493
|
+
|
|
494
|
+
```typescript
|
|
495
|
+
import {
|
|
496
|
+
LogEngine,
|
|
497
|
+
LogMode,
|
|
498
|
+
LogLevel,
|
|
499
|
+
ILogEngine,
|
|
500
|
+
ILogEngineWithoutRedaction,
|
|
501
|
+
RedactionConfig,
|
|
502
|
+
LoggerConfig,
|
|
503
|
+
IDataRedactor
|
|
504
|
+
} from '@wgtechlabs/log-engine';
|
|
505
|
+
|
|
506
|
+
// Full type safety for all methods
|
|
507
|
+
const config: RedactionConfig = {
|
|
508
|
+
enabled: true,
|
|
509
|
+
sensitiveFields: ['password', 'token'],
|
|
510
|
+
redactionText: '[HIDDEN]',
|
|
511
|
+
maxContentLength: 100,
|
|
512
|
+
// ... fully typed configuration
|
|
513
|
+
};
|
|
514
|
+
|
|
515
|
+
// Advanced redaction testing with return types
|
|
516
|
+
const isRedacted: boolean = LogEngine.testFieldRedaction('password');
|
|
517
|
+
const currentConfig: RedactionConfig = LogEngine.getRedactionConfig();
|
|
518
|
+
|
|
519
|
+
// Type-safe raw logging
|
|
520
|
+
const rawLogger: ILogEngineWithoutRedaction = LogEngine.withoutRedaction();
|
|
521
|
+
rawLogger.info('Debug info', sensitiveData); // Fully typed methods
|
|
522
|
+
```
|
|
523
|
+
|
|
524
|
+
### Available Interfaces
|
|
525
|
+
|
|
526
|
+
- **`ILogEngine`** - Complete LogEngine API with all methods
|
|
527
|
+
- **`ILogEngineWithoutRedaction`** - Raw logging methods interface
|
|
528
|
+
- **`IDataRedactor`** - Static DataRedactor class methods
|
|
529
|
+
- **`RedactionConfig`** - Comprehensive redaction configuration
|
|
530
|
+
- **`LoggerConfig`** - Logger configuration options
|
|
531
|
+
- **`LogEntry`** - Structured log entry interface
|
|
532
|
+
- **`EnvironmentConfig`** - Environment variable documentation
|
|
533
|
+
- **Plus 3+ additional interfaces** for advanced use cases
|
|
534
|
+
|
|
535
|
+
**IDE Benefits:** IntelliSense, auto-completion, parameter hints, error detection, and comprehensive documentation tooltips throughout your development workflow.
|
|
536
|
+
|
|
274
537
|
## 💬 Community Discussions
|
|
275
538
|
|
|
276
539
|
Join our community discussions to get help, share ideas, and connect with other users:
|
|
@@ -334,6 +597,8 @@ This project is licensed under the [GNU Affero General Public License v3.0](http
|
|
|
334
597
|
|
|
335
598
|
This project is created by **[Waren Gonzaga](https://github.com/warengonzaga)** under [WG Technology Labs](https://github.com/wgtechlabs), with the help of awesome [contributors](https://github.com/wgtechlabs/log-engine/graphs/contributors).
|
|
336
599
|
|
|
600
|
+
**Latest Version:** v1.3.0 - Enhanced with advanced redaction features, comprehensive TypeScript support, and 95%+ test coverage.
|
|
601
|
+
|
|
337
602
|
[](https://github.com/wgtechlabs/log-engine/graphs/contributors)
|
|
338
603
|
|
|
339
604
|
---
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* ANSI color codes and color management for terminal output
|
|
3
|
+
* Provides consistent color definitions used throughout the formatting system
|
|
4
|
+
*/
|
|
5
|
+
/**
|
|
6
|
+
* ANSI color codes for terminal output styling
|
|
7
|
+
* Used to create colorized console output with consistent theming
|
|
8
|
+
*/
|
|
9
|
+
export declare const colors: {
|
|
10
|
+
readonly reset: "\u001B[0m";
|
|
11
|
+
readonly dim: "\u001B[2m";
|
|
12
|
+
readonly red: "\u001B[31m";
|
|
13
|
+
readonly yellow: "\u001B[33m";
|
|
14
|
+
readonly blue: "\u001B[34m";
|
|
15
|
+
readonly magenta: "\u001B[35m";
|
|
16
|
+
readonly cyan: "\u001B[36m";
|
|
17
|
+
readonly white: "\u001B[37m";
|
|
18
|
+
readonly gray: "\u001B[90m";
|
|
19
|
+
readonly green: "\u001B[32m";
|
|
20
|
+
};
|
|
21
|
+
/**
|
|
22
|
+
* Color scheme configuration
|
|
23
|
+
* Maps semantic meanings to specific colors for consistent theming
|
|
24
|
+
*/
|
|
25
|
+
export declare const colorScheme: {
|
|
26
|
+
readonly timestamp: "\u001B[90m";
|
|
27
|
+
readonly timeString: "\u001B[36m";
|
|
28
|
+
readonly system: "\u001B[33m";
|
|
29
|
+
readonly data: "\u001B[2m";
|
|
30
|
+
readonly reset: "\u001B[0m";
|
|
31
|
+
};
|
|
32
|
+
//# sourceMappingURL=colors.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"colors.d.ts","sourceRoot":"","sources":["../../src/formatter/colors.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH;;;GAGG;AACH,eAAO,MAAM,MAAM;;;;;;;;;;;CAWT,CAAC;AAEX;;;GAGG;AACH,eAAO,MAAM,WAAW;;;;;;CAMd,CAAC"}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* ANSI color codes and color management for terminal output
|
|
4
|
+
* Provides consistent color definitions used throughout the formatting system
|
|
5
|
+
*/
|
|
6
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
7
|
+
exports.colorScheme = exports.colors = void 0;
|
|
8
|
+
/**
|
|
9
|
+
* ANSI color codes for terminal output styling
|
|
10
|
+
* Used to create colorized console output with consistent theming
|
|
11
|
+
*/
|
|
12
|
+
exports.colors = {
|
|
13
|
+
reset: '\x1b[0m', // Reset all formatting
|
|
14
|
+
dim: '\x1b[2m', // Dim/faded text
|
|
15
|
+
red: '\x1b[31m', // Red text (errors)
|
|
16
|
+
yellow: '\x1b[33m', // Yellow text (warnings)
|
|
17
|
+
blue: '\x1b[34m', // Blue text (info)
|
|
18
|
+
magenta: '\x1b[35m', // Magenta text (debug)
|
|
19
|
+
cyan: '\x1b[36m', // Cyan text (timestamps)
|
|
20
|
+
white: '\x1b[37m', // White text (default)
|
|
21
|
+
gray: '\x1b[90m', // Gray text (timestamps)
|
|
22
|
+
green: '\x1b[32m' // Green text (log level)
|
|
23
|
+
};
|
|
24
|
+
/**
|
|
25
|
+
* Color scheme configuration
|
|
26
|
+
* Maps semantic meanings to specific colors for consistent theming
|
|
27
|
+
*/
|
|
28
|
+
exports.colorScheme = {
|
|
29
|
+
timestamp: exports.colors.gray,
|
|
30
|
+
timeString: exports.colors.cyan,
|
|
31
|
+
system: exports.colors.yellow,
|
|
32
|
+
data: exports.colors.dim,
|
|
33
|
+
reset: exports.colors.reset
|
|
34
|
+
};
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Data formatting utilities for log output
|
|
3
|
+
* Handles serialization and formatting of data objects in log messages
|
|
4
|
+
*/
|
|
5
|
+
/**
|
|
6
|
+
* Converts input data to a readable string suitable for log output.
|
|
7
|
+
*
|
|
8
|
+
* Returns 'null' for `null`, an empty string for `undefined`, the value itself for strings, and string representations for numbers and booleans. For other types, attempts JSON serialization; if serialization fails, returns '[Object]'.
|
|
9
|
+
*
|
|
10
|
+
* @param data - The value to format for logging
|
|
11
|
+
* @returns The formatted string representation of the input data
|
|
12
|
+
*/
|
|
13
|
+
export declare function formatData(data: any): string;
|
|
14
|
+
/**
|
|
15
|
+
* Applies color styling to a formatted data string using the provided color codes.
|
|
16
|
+
*
|
|
17
|
+
* @param dataString - The string to be styled; if falsy, an empty string is returned.
|
|
18
|
+
* @param colors - An object containing `data` (the color code prefix) and `reset` (the color code suffix).
|
|
19
|
+
* @returns The styled data string with color codes applied, or an empty string if `dataString` is falsy.
|
|
20
|
+
*/
|
|
21
|
+
export declare function styleData(dataString: string, colors: {
|
|
22
|
+
data: string;
|
|
23
|
+
reset: string;
|
|
24
|
+
}): string;
|
|
25
|
+
//# sourceMappingURL=data-formatter.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"data-formatter.d.ts","sourceRoot":"","sources":["../../src/formatter/data-formatter.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH;;;;;;;GAOG;AACH,wBAAgB,UAAU,CAAC,IAAI,EAAE,GAAG,GAAG,MAAM,CA2B5C;AAED;;;;;;GAMG;AACH,wBAAgB,SAAS,CAAC,UAAU,EAAE,MAAM,EAAE,MAAM,EAAE;IAAE,IAAI,EAAE,MAAM,CAAC;IAAC,KAAK,EAAE,MAAM,CAAA;CAAE,GAAG,MAAM,CAM7F"}
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Data formatting utilities for log output
|
|
4
|
+
* Handles serialization and formatting of data objects in log messages
|
|
5
|
+
*/
|
|
6
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
7
|
+
exports.formatData = formatData;
|
|
8
|
+
exports.styleData = styleData;
|
|
9
|
+
/**
|
|
10
|
+
* Converts input data to a readable string suitable for log output.
|
|
11
|
+
*
|
|
12
|
+
* Returns 'null' for `null`, an empty string for `undefined`, the value itself for strings, and string representations for numbers and booleans. For other types, attempts JSON serialization; if serialization fails, returns '[Object]'.
|
|
13
|
+
*
|
|
14
|
+
* @param data - The value to format for logging
|
|
15
|
+
* @returns The formatted string representation of the input data
|
|
16
|
+
*/
|
|
17
|
+
function formatData(data) {
|
|
18
|
+
if (data === null) {
|
|
19
|
+
return 'null';
|
|
20
|
+
}
|
|
21
|
+
if (data === undefined) {
|
|
22
|
+
return '';
|
|
23
|
+
}
|
|
24
|
+
if (typeof data === 'string') {
|
|
25
|
+
return data;
|
|
26
|
+
}
|
|
27
|
+
if (typeof data === 'number' || typeof data === 'boolean') {
|
|
28
|
+
return String(data);
|
|
29
|
+
}
|
|
30
|
+
if (typeof data === 'symbol') {
|
|
31
|
+
return data.toString();
|
|
32
|
+
}
|
|
33
|
+
try {
|
|
34
|
+
return JSON.stringify(data, null, 0);
|
|
35
|
+
}
|
|
36
|
+
catch (error) {
|
|
37
|
+
// Fallback for objects that can't be stringified (e.g., circular references)
|
|
38
|
+
return '[Object]';
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
/**
|
|
42
|
+
* Applies color styling to a formatted data string using the provided color codes.
|
|
43
|
+
*
|
|
44
|
+
* @param dataString - The string to be styled; if falsy, an empty string is returned.
|
|
45
|
+
* @param colors - An object containing `data` (the color code prefix) and `reset` (the color code suffix).
|
|
46
|
+
* @returns The styled data string with color codes applied, or an empty string if `dataString` is falsy.
|
|
47
|
+
*/
|
|
48
|
+
function styleData(dataString, colors) {
|
|
49
|
+
if (!dataString) {
|
|
50
|
+
return '';
|
|
51
|
+
}
|
|
52
|
+
return ` ${colors.data}${dataString}${colors.reset}`;
|
|
53
|
+
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Formatter module exports
|
|
3
|
+
* Provides centralized access to all formatting functionality
|
|
4
|
+
*/
|
|
5
|
+
export { MessageFormatter } from './message-formatter';
|
|
6
|
+
export { colors, colorScheme } from './colors';
|
|
7
|
+
export { getTimestampComponents, formatTimestamp } from './timestamp';
|
|
8
|
+
export { formatData, styleData } from './data-formatter';
|
|
9
|
+
export { MessageFormatter as LogFormatter } from './message-formatter';
|
|
10
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/formatter/index.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EAAE,gBAAgB,EAAE,MAAM,qBAAqB,CAAC;AACvD,OAAO,EAAE,MAAM,EAAE,WAAW,EAAE,MAAM,UAAU,CAAC;AAC/C,OAAO,EAAE,sBAAsB,EAAE,eAAe,EAAE,MAAM,aAAa,CAAC;AACtE,OAAO,EAAE,UAAU,EAAE,SAAS,EAAE,MAAM,kBAAkB,CAAC;AAGzD,OAAO,EAAE,gBAAgB,IAAI,YAAY,EAAE,MAAM,qBAAqB,CAAC"}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Formatter module exports
|
|
4
|
+
* Provides centralized access to all formatting functionality
|
|
5
|
+
*/
|
|
6
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
7
|
+
exports.LogFormatter = exports.styleData = exports.formatData = exports.formatTimestamp = exports.getTimestampComponents = exports.colorScheme = exports.colors = exports.MessageFormatter = void 0;
|
|
8
|
+
var message_formatter_1 = require("./message-formatter");
|
|
9
|
+
Object.defineProperty(exports, "MessageFormatter", { enumerable: true, get: function () { return message_formatter_1.MessageFormatter; } });
|
|
10
|
+
var colors_1 = require("./colors");
|
|
11
|
+
Object.defineProperty(exports, "colors", { enumerable: true, get: function () { return colors_1.colors; } });
|
|
12
|
+
Object.defineProperty(exports, "colorScheme", { enumerable: true, get: function () { return colors_1.colorScheme; } });
|
|
13
|
+
var timestamp_1 = require("./timestamp");
|
|
14
|
+
Object.defineProperty(exports, "getTimestampComponents", { enumerable: true, get: function () { return timestamp_1.getTimestampComponents; } });
|
|
15
|
+
Object.defineProperty(exports, "formatTimestamp", { enumerable: true, get: function () { return timestamp_1.formatTimestamp; } });
|
|
16
|
+
var data_formatter_1 = require("./data-formatter");
|
|
17
|
+
Object.defineProperty(exports, "formatData", { enumerable: true, get: function () { return data_formatter_1.formatData; } });
|
|
18
|
+
Object.defineProperty(exports, "styleData", { enumerable: true, get: function () { return data_formatter_1.styleData; } });
|
|
19
|
+
// Backward compatibility - maintain the original LogFormatter class interface
|
|
20
|
+
var message_formatter_2 = require("./message-formatter");
|
|
21
|
+
Object.defineProperty(exports, "LogFormatter", { enumerable: true, get: function () { return message_formatter_2.MessageFormatter; } });
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Core message formatting functionality
|
|
3
|
+
* Handles the main log message formatting with colors, timestamps, and levels
|
|
4
|
+
*/
|
|
5
|
+
import { LogLevel } from '../types';
|
|
6
|
+
/**
|
|
7
|
+
* Core message formatter class
|
|
8
|
+
* Provides the main formatting functionality for log messages
|
|
9
|
+
*/
|
|
10
|
+
export declare class MessageFormatter {
|
|
11
|
+
/**
|
|
12
|
+
* Formats a log message with timestamp, level indicator, and appropriate coloring
|
|
13
|
+
* Creates a structured log entry: [ISO_TIMESTAMP][LOCAL_TIME][LEVEL]: message [data]
|
|
14
|
+
* @param level - The log level to format for
|
|
15
|
+
* @param message - The message content to format
|
|
16
|
+
* @param data - Optional data object to include in the log output
|
|
17
|
+
* @returns Formatted string with ANSI colors and timestamps
|
|
18
|
+
*/
|
|
19
|
+
static format(level: LogLevel, message: string, data?: any): 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=message-formatter.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"message-formatter.d.ts","sourceRoot":"","sources":["../../src/formatter/message-formatter.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EAAE,QAAQ,EAAE,MAAM,UAAU,CAAC;AAKpC;;;GAGG;AACH,qBAAa,gBAAgB;IACzB;;;;;;;OAOG;IACH,MAAM,CAAC,MAAM,CAAC,KAAK,EAAE,QAAQ,EAAE,OAAO,EAAE,MAAM,EAAE,IAAI,CAAC,EAAE,GAAG,GAAG,MAAM;IAsBnE;;;;;OAKG;IACH,MAAM,CAAC,mBAAmB,CAAC,OAAO,EAAE,MAAM,GAAG,MAAM;IAUnD;;;;OAIG;IACH,OAAO,CAAC,MAAM,CAAC,YAAY;IAW3B;;;;;OAKG;IACH,OAAO,CAAC,MAAM,CAAC,aAAa;CAU/B"}
|