@wgtechlabs/log-engine 2.2.2-patch.e0f838f â 2.2.2-pr.45ee083
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 +223 -13
- package/dist/cjs/formatter/emoji-data.cjs +87 -0
- package/dist/cjs/formatter/emoji-data.d.ts +18 -0
- package/dist/cjs/formatter/emoji-data.d.ts.map +1 -0
- package/dist/cjs/formatter/emoji-data.js.map +1 -0
- package/dist/cjs/formatter/emoji-selector.cjs +212 -0
- package/dist/cjs/formatter/emoji-selector.d.ts +88 -0
- package/dist/cjs/formatter/emoji-selector.d.ts.map +1 -0
- package/dist/cjs/formatter/emoji-selector.js.map +1 -0
- package/dist/cjs/formatter/index.cjs +6 -1
- package/dist/cjs/formatter/index.d.ts +2 -0
- package/dist/cjs/formatter/index.d.ts.map +1 -1
- package/dist/cjs/formatter/index.js.map +1 -1
- package/dist/cjs/formatter/message-formatter.cjs +11 -2
- package/dist/cjs/formatter/message-formatter.d.ts.map +1 -1
- package/dist/cjs/formatter/message-formatter.js.map +1 -1
- package/dist/cjs/index.cjs +5 -1
- package/dist/cjs/index.d.ts +2 -1
- package/dist/cjs/index.d.ts.map +1 -1
- package/dist/cjs/index.js.map +1 -1
- package/dist/cjs/logger/core.cjs +10 -0
- package/dist/cjs/logger/core.d.ts.map +1 -1
- package/dist/cjs/logger/core.js.map +1 -1
- package/dist/cjs/types/index.d.ts +29 -0
- package/dist/cjs/types/index.d.ts.map +1 -1
- package/dist/esm/formatter/emoji-data.d.ts +18 -0
- package/dist/esm/formatter/emoji-data.d.ts.map +1 -0
- package/dist/esm/formatter/emoji-data.js +84 -0
- package/dist/esm/formatter/emoji-data.js.map +1 -0
- package/dist/esm/formatter/emoji-selector.d.ts +88 -0
- package/dist/esm/formatter/emoji-selector.d.ts.map +1 -0
- package/dist/esm/formatter/emoji-selector.js +208 -0
- package/dist/esm/formatter/emoji-selector.js.map +1 -0
- package/dist/esm/formatter/index.d.ts +2 -0
- package/dist/esm/formatter/index.d.ts.map +1 -1
- package/dist/esm/formatter/index.js +2 -0
- package/dist/esm/formatter/index.js.map +1 -1
- package/dist/esm/formatter/message-formatter.d.ts.map +1 -1
- package/dist/esm/formatter/message-formatter.js +11 -2
- package/dist/esm/formatter/message-formatter.js.map +1 -1
- package/dist/esm/index.d.ts +2 -1
- package/dist/esm/index.d.ts.map +1 -1
- package/dist/esm/index.js +1 -0
- package/dist/esm/index.js.map +1 -1
- package/dist/esm/logger/core.d.ts.map +1 -1
- package/dist/esm/logger/core.js +11 -1
- package/dist/esm/logger/core.js.map +1 -1
- package/dist/esm/types/index.d.ts +29 -0
- package/dist/esm/types/index.d.ts.map +1 -1
- package/package.json +6 -4
package/README.md
CHANGED
|
@@ -16,6 +16,7 @@ Log Engine transforms your development experience from chaotic debugging session
|
|
|
16
16
|
|
|
17
17
|
## ⨠Key Features
|
|
18
18
|
|
|
19
|
+
- **đ¨ Context-Aware Emoji (New!)**: Intelligent emoji support that enhances log readability by analyzing content and automatically selecting relevant visual indicators - based on the gitmoji set with 40+ curated mappings and fully customizable.
|
|
19
20
|
- **đ 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
21
|
- **đ¯ Configurable Output Handlers (New!)**: Revolutionary output routing system supporting **custom destinations**, **multiple simultaneous outputs**, and **production-ready handlers** - redirect logs to files, HTTP endpoints, GUI applications, testing frameworks, or any custom destination with zero configuration complexity.
|
|
21
22
|
- **⥠Custom Redaction Patterns**: Add your own regex patterns for advanced field detection and enterprise-specific data protection requirements.
|
|
@@ -29,6 +30,7 @@ Log Engine transforms your development experience from chaotic debugging session
|
|
|
29
30
|
- **âī¸ 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.
|
|
30
31
|
- **⨠Enhanced Formatting**: Structured log entries with dual timestamps (ISO + human-readable) and colored level indicators for maximum readability.
|
|
31
32
|
- **đ Zero Dependencies**: No external dependencies for maximum compatibility and security - keeps your bundle clean and your project simple.
|
|
33
|
+
- **đ Size Monitoring**: Automated bundle size checking ensures the package stays under 1MB to maintain its lightweight promise.
|
|
32
34
|
- **đ Easy Integration**: Simple API that works seamlessly with existing Node.js applications. Just `import` and start logging - no middleware, plugins, or configuration required.
|
|
33
35
|
|
|
34
36
|
## â ī¸ Breaking Changes Notice
|
|
@@ -62,10 +64,10 @@ Open source development is resource-intensive. These **sponsored ads help keep L
|
|
|
62
64
|
|
|
63
65
|
## đĻ Installation
|
|
64
66
|
|
|
65
|
-
Install the package using
|
|
67
|
+
Install the package using pnpm (recommended):
|
|
66
68
|
|
|
67
69
|
```bash
|
|
68
|
-
|
|
70
|
+
pnpm add @wgtechlabs/log-engine
|
|
69
71
|
```
|
|
70
72
|
|
|
71
73
|
Or using npm:
|
|
@@ -74,7 +76,13 @@ Or using npm:
|
|
|
74
76
|
npm install @wgtechlabs/log-engine
|
|
75
77
|
```
|
|
76
78
|
|
|
77
|
-
|
|
79
|
+
Or using yarn:
|
|
80
|
+
|
|
81
|
+
```bash
|
|
82
|
+
yarn add @wgtechlabs/log-engine
|
|
83
|
+
```
|
|
84
|
+
|
|
85
|
+
> **Note**: This project uses pnpm as the primary package manager for development. If you're contributing to the project, please use pnpm to ensure consistency with the development environment.
|
|
78
86
|
|
|
79
87
|
## đšī¸ Usage
|
|
80
88
|
|
|
@@ -407,6 +415,207 @@ LogEngine.error('Connection failed');
|
|
|
407
415
|
|
|
408
416
|
**Note**: Log levels (`[DEBUG]`, `[INFO]`, `[WARN]`, `[ERROR]`, `[LOG]`) are always included regardless of configuration to maintain log clarity and filtering capabilities.
|
|
409
417
|
|
|
418
|
+
## đ¨ Context-Aware Emoji Support
|
|
419
|
+
|
|
420
|
+
**LogEngine features intelligent emoji support that enhances log readability by adding visual context to each log message.** The emoji engine analyzes your log content (level + message + data) and automatically selects the most relevant emoji, making it easier to visually parse large logs and instantly identify the type of each log line.
|
|
421
|
+
|
|
422
|
+
### Features
|
|
423
|
+
|
|
424
|
+
- **đ¯ Context-Aware Selection**: Automatically analyzes message content and data to select appropriate emoji
|
|
425
|
+
- **đĻ Rich Emoji Set**: Based on [gitmoji](https://gitmoji.dev) with 40+ curated emoji mappings
|
|
426
|
+
- **đ Smart Fallback**: Uses level-specific emoji when no context match is found
|
|
427
|
+
- **đ ī¸ Fully Customizable**: Extend or override emoji mappings and fallback behavior
|
|
428
|
+
- **â
Enabled by Default**: Emoji are automatically included in logs (can be disabled via `includeEmoji: false`)
|
|
429
|
+
|
|
430
|
+
### Quick Start
|
|
431
|
+
|
|
432
|
+
```typescript
|
|
433
|
+
import { LogEngine } from '@wgtechlabs/log-engine';
|
|
434
|
+
|
|
435
|
+
// Emoji are enabled by default - just start logging!
|
|
436
|
+
LogEngine.error('Database connection failed');
|
|
437
|
+
// Output: [2026-02-11T14:00:00.000Z][2:00PM][ERROR][đī¸]: Database connection failed
|
|
438
|
+
|
|
439
|
+
LogEngine.info('Deployed to production successfully');
|
|
440
|
+
// Output: [2026-02-11T14:00:01.000Z][2:00PM][INFO][đ]: Deployed to production successfully
|
|
441
|
+
|
|
442
|
+
LogEngine.warn('Performance degradation detected');
|
|
443
|
+
// Output: [2026-02-11T14:00:02.000Z][2:00PM][WARN][âĄī¸]: Performance degradation detected
|
|
444
|
+
|
|
445
|
+
LogEngine.info('Unknown event happened');
|
|
446
|
+
// Output: [2026-02-11T14:00:03.000Z][2:00PM][INFO][âšī¸]: Unknown event happened (fallback)
|
|
447
|
+
|
|
448
|
+
// Disable emoji if needed
|
|
449
|
+
LogEngine.configure({
|
|
450
|
+
format: {
|
|
451
|
+
includeEmoji: false
|
|
452
|
+
}
|
|
453
|
+
});
|
|
454
|
+
```
|
|
455
|
+
|
|
456
|
+
### Context-Aware Emoji Mappings
|
|
457
|
+
|
|
458
|
+
LogEngine intelligently matches keywords in your log messages to select appropriate emoji:
|
|
459
|
+
|
|
460
|
+
| Context | Keywords | Emoji | Example |
|
|
461
|
+
|---------|----------|-------|---------|
|
|
462
|
+
| **Database** | database, db, sql, query, mongo, postgres | đī¸ | "Database query failed" |
|
|
463
|
+
| **Deployment** | deploy, release, launched, production | đ | "Deployed to production" |
|
|
464
|
+
| **Performance** | performance, speed, optimize, latency | âĄī¸ | "Performance issues detected" |
|
|
465
|
+
| **Security** | security, vulnerability, auth, permission | đī¸ | "Security breach detected" |
|
|
466
|
+
| **Critical** | critical, urgent, emergency, crash | đī¸ | "Critical system failure" |
|
|
467
|
+
| **Bugs** | bug, fix, defect, issue | đ | "Fixed bug in login" |
|
|
468
|
+
| **Network** | network, http, api, endpoint | đ | "API request failed" |
|
|
469
|
+
| **Testing** | tests, testing, validation | â
| "All tests passed" |
|
|
470
|
+
|
|
471
|
+
### Fallback Emoji by Level
|
|
472
|
+
|
|
473
|
+
When no context-specific emoji matches, LogEngine uses these fallback emoji:
|
|
474
|
+
|
|
475
|
+
| Log Level | Emoji | Description |
|
|
476
|
+
|-----------|-------|-------------|
|
|
477
|
+
| `DEBUG` | đ | Debugging information |
|
|
478
|
+
| `INFO` | âšī¸ | General information |
|
|
479
|
+
| `WARN` | â ī¸ | Warning messages |
|
|
480
|
+
| `ERROR` | â | Error messages |
|
|
481
|
+
| `LOG` | â
| Critical log messages |
|
|
482
|
+
|
|
483
|
+
### Custom Emoji Configuration
|
|
484
|
+
|
|
485
|
+
#### Custom Context Mappings
|
|
486
|
+
|
|
487
|
+
Add your own emoji mappings for custom contexts:
|
|
488
|
+
|
|
489
|
+
```typescript
|
|
490
|
+
LogEngine.configure({
|
|
491
|
+
format: {
|
|
492
|
+
emoji: {
|
|
493
|
+
customMappings: [
|
|
494
|
+
{
|
|
495
|
+
emoji: 'đ¯',
|
|
496
|
+
code: ':dart:',
|
|
497
|
+
description: 'Goal achieved',
|
|
498
|
+
keywords: ['goal', 'target', 'achieved', 'milestone']
|
|
499
|
+
},
|
|
500
|
+
{
|
|
501
|
+
emoji: 'đ°',
|
|
502
|
+
code: ':moneybag:',
|
|
503
|
+
description: 'Payment operations',
|
|
504
|
+
keywords: ['payment', 'transaction', 'billing', 'invoice']
|
|
505
|
+
}
|
|
506
|
+
]
|
|
507
|
+
}
|
|
508
|
+
}
|
|
509
|
+
});
|
|
510
|
+
|
|
511
|
+
LogEngine.info('Payment processed successfully');
|
|
512
|
+
// Output: [INFO][đ°]: Payment processed successfully
|
|
513
|
+
|
|
514
|
+
LogEngine.info('Sales target achieved');
|
|
515
|
+
// Output: [INFO][đ¯]: Sales target achieved
|
|
516
|
+
```
|
|
517
|
+
|
|
518
|
+
#### Custom Fallback Emoji
|
|
519
|
+
|
|
520
|
+
Override the default fallback emoji for each log level:
|
|
521
|
+
|
|
522
|
+
```typescript
|
|
523
|
+
LogEngine.configure({
|
|
524
|
+
format: {
|
|
525
|
+
emoji: {
|
|
526
|
+
customFallbacks: {
|
|
527
|
+
DEBUG: 'đ',
|
|
528
|
+
INFO: 'đĸ',
|
|
529
|
+
WARN: 'đ¨',
|
|
530
|
+
ERROR: 'đ',
|
|
531
|
+
LOG: 'đ'
|
|
532
|
+
}
|
|
533
|
+
}
|
|
534
|
+
}
|
|
535
|
+
});
|
|
536
|
+
|
|
537
|
+
LogEngine.info('Generic info message');
|
|
538
|
+
// Output: [INFO][đĸ]: Generic info message
|
|
539
|
+
```
|
|
540
|
+
|
|
541
|
+
#### Use Custom Mappings Exclusively
|
|
542
|
+
|
|
543
|
+
Use only your custom mappings and ignore the built-in set:
|
|
544
|
+
|
|
545
|
+
```typescript
|
|
546
|
+
LogEngine.configure({
|
|
547
|
+
format: {
|
|
548
|
+
emoji: {
|
|
549
|
+
useCustomOnly: true,
|
|
550
|
+
customMappings: [
|
|
551
|
+
// Your custom mappings only
|
|
552
|
+
]
|
|
553
|
+
}
|
|
554
|
+
}
|
|
555
|
+
});
|
|
556
|
+
```
|
|
557
|
+
|
|
558
|
+
### Data Context Analysis
|
|
559
|
+
|
|
560
|
+
The emoji selector also analyzes data objects for context:
|
|
561
|
+
|
|
562
|
+
```typescript
|
|
563
|
+
LogEngine.info('Operation completed', {
|
|
564
|
+
database: 'postgres',
|
|
565
|
+
table: 'users',
|
|
566
|
+
rows: 1000
|
|
567
|
+
});
|
|
568
|
+
// Output: [INFO][đī¸]: Operation completed { database: 'postgres', ... }
|
|
569
|
+
|
|
570
|
+
LogEngine.warn('Issue detected', {
|
|
571
|
+
performance: 'degraded',
|
|
572
|
+
latency: '500ms'
|
|
573
|
+
});
|
|
574
|
+
// Output: [WARN][âĄī¸]: Issue detected { performance: 'degraded', ... }
|
|
575
|
+
```
|
|
576
|
+
|
|
577
|
+
### Programmatic Access
|
|
578
|
+
|
|
579
|
+
Access emoji utilities directly for advanced use cases:
|
|
580
|
+
|
|
581
|
+
```typescript
|
|
582
|
+
import { EmojiSelector, EMOJI_MAPPINGS, FALLBACK_EMOJI } from '@wgtechlabs/log-engine';
|
|
583
|
+
|
|
584
|
+
// Check all available emoji mappings
|
|
585
|
+
console.log(EMOJI_MAPPINGS);
|
|
586
|
+
// [{ emoji: 'đ', code: ':bug:', description: 'Fix a bug', keywords: [...] }, ...]
|
|
587
|
+
|
|
588
|
+
// Check fallback emoji
|
|
589
|
+
console.log(FALLBACK_EMOJI);
|
|
590
|
+
// { DEBUG: 'đ', INFO: 'âšī¸', WARN: 'â ī¸', ERROR: 'â', LOG: 'â
' }
|
|
591
|
+
|
|
592
|
+
// Configure emoji selector directly (for customization)
|
|
593
|
+
EmojiSelector.configure({
|
|
594
|
+
customMappings: [...]
|
|
595
|
+
});
|
|
596
|
+
```
|
|
597
|
+
|
|
598
|
+
### Output Format
|
|
599
|
+
|
|
600
|
+
With emoji (enabled by default), the log format is:
|
|
601
|
+
|
|
602
|
+
```
|
|
603
|
+
[ISO_TIMESTAMP][LOCAL_TIME][LEVEL][EMOJI]: message [data]
|
|
604
|
+
```
|
|
605
|
+
|
|
606
|
+
Example:
|
|
607
|
+
```
|
|
608
|
+
[2026-02-11T14:00:00.000Z][2:00PM][ERROR][đī¸]: Database connection failed
|
|
609
|
+
```
|
|
610
|
+
|
|
611
|
+
### Benefits
|
|
612
|
+
|
|
613
|
+
- **đī¸ Visual Clarity**: Instantly identify log context at a glance
|
|
614
|
+
- **đ¯ Better Debugging**: Quickly locate specific types of logs in large outputs
|
|
615
|
+
- **đ¨ Enhanced UX**: More engaging and pleasant logging experience
|
|
616
|
+
- **đ§ Flexible**: Fully customizable to match your project's needs
|
|
617
|
+
- **đ Compatibility Note**: Enabled by default â existing log output will include emojis; disable or customize emoji behavior via configuration to preserve prior formats
|
|
618
|
+
|
|
410
619
|
## đ Advanced Data Redaction
|
|
411
620
|
|
|
412
621
|
**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.
|
|
@@ -879,7 +1088,7 @@ Contributions are welcome, create a pull request to this repo and I will review
|
|
|
879
1088
|
**Development Environment:**
|
|
880
1089
|
|
|
881
1090
|
- This project is configured for **local development workflows only** - no CI/CD setup required
|
|
882
|
-
- Uses **
|
|
1091
|
+
- Uses **pnpm** as the primary package manager for consistency
|
|
883
1092
|
- Simple, cross-platform development setup with TypeScript, Jest, and ESLint
|
|
884
1093
|
- Clean test output maintained using `jest.setup.js` to suppress console noise during testing
|
|
885
1094
|
- All error logging functionality remains intact in production code
|
|
@@ -887,15 +1096,16 @@ Contributions are welcome, create a pull request to this repo and I will review
|
|
|
887
1096
|
|
|
888
1097
|
**Available Scripts:**
|
|
889
1098
|
|
|
890
|
-
- `
|
|
891
|
-
- `
|
|
892
|
-
- `
|
|
893
|
-
- `
|
|
894
|
-
- `
|
|
895
|
-
- `
|
|
896
|
-
- `
|
|
897
|
-
- `
|
|
898
|
-
- `
|
|
1099
|
+
- `pnpm test` - Run all tests
|
|
1100
|
+
- `pnpm test:watch` - Run tests in watch mode
|
|
1101
|
+
- `pnpm test:coverage` - Run tests with coverage reporting
|
|
1102
|
+
- `pnpm lint` - Run TypeScript and code quality checks
|
|
1103
|
+
- `pnpm lint:fix` - Automatically fix linting issues
|
|
1104
|
+
- `pnpm lint:security` - Run security-focused linting
|
|
1105
|
+
- `pnpm secure` - Run comprehensive security checks
|
|
1106
|
+
- `pnpm build` - Build the TypeScript project
|
|
1107
|
+
- `pnpm size:check` - Check bundle size to maintain lightweight feature
|
|
1108
|
+
- `pnpm validate` - Run full validation (lint + test + build + size check)
|
|
899
1109
|
|
|
900
1110
|
Read the project's [contributing guide](./CONTRIBUTING.md) for detailed development setup, testing guidelines, and contribution requirements.
|
|
901
1111
|
|
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Emoji data for context-aware logging
|
|
4
|
+
* Based on gitmoji.dev emoji set
|
|
5
|
+
* Each entry maps emoji to keywords that help identify when to use it
|
|
6
|
+
*/
|
|
7
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
8
|
+
exports.FALLBACK_EMOJI = exports.EMOJI_MAPPINGS = void 0;
|
|
9
|
+
/**
|
|
10
|
+
* Curated emoji mappings for context-aware logging
|
|
11
|
+
* Based on the gitmoji set from https://gitmoji.dev
|
|
12
|
+
* Ordered by specificity - more specific keywords first
|
|
13
|
+
*/
|
|
14
|
+
exports.EMOJI_MAPPINGS = [
|
|
15
|
+
// More specific contexts first
|
|
16
|
+
// Database (specific)
|
|
17
|
+
{ emoji: 'đī¸', code: ':card_file_box:', description: 'Database related', keywords: ['database', 'db', 'sql', 'query', 'table', 'schema', 'migration', 'mongo', 'postgres', 'mysql'] },
|
|
18
|
+
// Deployment and releases (specific)
|
|
19
|
+
{ emoji: 'đ', code: ':rocket:', description: 'Deploy or release', keywords: ['deploy', 'deployed', 'deployment', 'release', 'launched', 'production'] },
|
|
20
|
+
// Performance (specific)
|
|
21
|
+
{ emoji: 'âĄī¸', code: ':zap:', description: 'Improve performance', keywords: ['performance', 'speed', 'optimize', 'fast', 'slow', 'latency', 'throughput'] },
|
|
22
|
+
// Security (specific)
|
|
23
|
+
{ emoji: 'đī¸', code: ':lock:', description: 'Fix security issues', keywords: ['security', 'secure', 'vulnerability', 'exploit', 'auth', 'authentication', 'authorization', 'permission'] },
|
|
24
|
+
// Critical issues (specific)
|
|
25
|
+
{ emoji: 'đī¸', code: ':ambulance:', description: 'Critical hotfix', keywords: ['critical', 'hotfix', 'urgent', 'emergency', 'crash', 'fatal'] },
|
|
26
|
+
// Bugs and fixes (specific)
|
|
27
|
+
{ emoji: 'đ', code: ':bug:', description: 'Fix a bug', keywords: ['bug', 'fix', 'fixed', 'fixing', 'defect', 'issue'] },
|
|
28
|
+
// Less specific/generic contexts last
|
|
29
|
+
// Errors and failures (generic)
|
|
30
|
+
{ emoji: 'â', code: ':x:', description: 'Error or failure', keywords: ['error', 'fail', 'failed', 'failure', 'exception', 'reject'] },
|
|
31
|
+
{ emoji: 'đĨ', code: ':fire:', description: 'Remove code or files', keywords: ['remove', 'delete', 'deprecated', 'obsolete'] },
|
|
32
|
+
{ emoji: 'đ', code: ':snail:', description: 'Slow performance', keywords: ['timeout', 'hang', 'freeze'] },
|
|
33
|
+
{ emoji: 'đī¸', code: ':unlock:', description: 'Unlock or access', keywords: ['unlock', 'access', 'grant', 'allow'] },
|
|
34
|
+
{ emoji: 'đž', code: ':floppy_disk:', description: 'Save or persist data', keywords: ['save', 'saved', 'saving', 'persist', 'write', 'store'] },
|
|
35
|
+
{ emoji: 'đ', code: ':tada:', description: 'Initial commit or milestone', keywords: ['initial', 'milestone', 'celebrate', 'success', 'complete'] },
|
|
36
|
+
// Configuration
|
|
37
|
+
{ emoji: 'đ§', code: ':wrench:', description: 'Configuration changes', keywords: ['config', 'configuration', 'setting', 'settings', 'configure'] },
|
|
38
|
+
{ emoji: 'âī¸', code: ':gear:', description: 'Configuration or settings', keywords: ['setup', 'init', 'initialize'] },
|
|
39
|
+
// API and network
|
|
40
|
+
{ emoji: 'đ', code: ':globe_with_meridians:', description: 'Network or internet', keywords: ['network', 'internet', 'http', 'https', 'request', 'response', 'api', 'endpoint'] },
|
|
41
|
+
{ emoji: 'đ', code: ':electric_plug:', description: 'Connection or plugin', keywords: ['connect', 'connection', 'disconnect', 'plugin', 'integration'] },
|
|
42
|
+
// Testing
|
|
43
|
+
{ emoji: 'â
', code: ':white_check_mark:', description: 'Tests passing', keywords: ['tests', 'testing', 'pass', 'passed', 'validation', 'validate'] },
|
|
44
|
+
{ emoji: 'đ§Ē', code: ':test_tube:', description: 'Running tests', keywords: ['experiment', 'trial', 'spec'] },
|
|
45
|
+
// Documentation
|
|
46
|
+
{ emoji: 'đ', code: ':memo:', description: 'Add or update documentation', keywords: ['document', 'documentation', 'docs', 'readme', 'comment'] },
|
|
47
|
+
{ emoji: 'đĄ', code: ':bulb:', description: 'New idea or insight', keywords: ['idea', 'insight', 'suggestion', 'tip', 'hint'] },
|
|
48
|
+
// Dependencies
|
|
49
|
+
{ emoji: 'â', code: ':heavy_plus_sign:', description: 'Add dependency', keywords: ['add', 'added', 'adding', 'install', 'dependency', 'package'] },
|
|
50
|
+
{ emoji: 'â', code: ':heavy_minus_sign:', description: 'Remove dependency', keywords: ['uninstall', 'removed'] },
|
|
51
|
+
{ emoji: 'âŦī¸', code: ':arrow_up:', description: 'Upgrade dependencies', keywords: ['upgrade', 'update', 'updated'] },
|
|
52
|
+
{ emoji: 'âŦī¸', code: ':arrow_down:', description: 'Downgrade dependencies', keywords: ['downgrade', 'rollback'] },
|
|
53
|
+
// Files and structure
|
|
54
|
+
{ emoji: 'đĻ', code: ':package:', description: 'Update compiled files', keywords: ['package', 'build', 'compile', 'bundle'] },
|
|
55
|
+
{ emoji: 'đ', code: ':truck:', description: 'Move or rename files', keywords: ['move', 'moved', 'rename', 'renamed', 'relocate'] },
|
|
56
|
+
// Work in progress
|
|
57
|
+
{ emoji: 'đ§', code: ':construction:', description: 'Work in progress', keywords: ['wip', 'progress', 'working', 'ongoing', 'incomplete'] },
|
|
58
|
+
// Breaking changes
|
|
59
|
+
{ emoji: 'đĨ', code: ':boom:', description: 'Breaking changes', keywords: ['breaking', 'break', 'incompatible'] },
|
|
60
|
+
// Accessibility
|
|
61
|
+
{ emoji: 'âŋī¸', code: ':wheelchair:', description: 'Improve accessibility', keywords: ['accessibility', 'a11y', 'accessible'] },
|
|
62
|
+
// Internationalization
|
|
63
|
+
{ emoji: 'đ', code: ':earth_africa:', description: 'Internationalization', keywords: ['i18n', 'localization', 'l10n', 'translation', 'language'] },
|
|
64
|
+
// UI and styling
|
|
65
|
+
{ emoji: 'đ', code: ':lipstick:', description: 'Update UI and style', keywords: ['ui', 'style', 'css', 'design', 'interface', 'layout'] },
|
|
66
|
+
{ emoji: 'đ¨', code: ':art:', description: 'Improve structure', keywords: ['refactor', 'refactoring', 'restructure', 'format'] },
|
|
67
|
+
// Logging and monitoring
|
|
68
|
+
{ emoji: 'đ', code: ':loud_sound:', description: 'Add or update logs', keywords: ['logging', 'trace'] },
|
|
69
|
+
{ emoji: 'đ', code: ':mute:', description: 'Remove logs', keywords: ['silent', 'quiet', 'mute'] },
|
|
70
|
+
{ emoji: 'đ', code: ':bar_chart:', description: 'Analytics or metrics', keywords: ['analytics', 'metrics', 'stats', 'statistics', 'monitor', 'monitoring'] },
|
|
71
|
+
// Code review
|
|
72
|
+
{ emoji: 'đ', code: ':ok_hand:', description: 'Code review changes', keywords: ['review', 'approve', 'approved', 'lgtm'] },
|
|
73
|
+
// Catch-all for new features (put last)
|
|
74
|
+
{ emoji: 'â¨', code: ':sparkles:', description: 'New feature', keywords: ['feature', 'new', 'enhancement', 'improve', 'improved'] },
|
|
75
|
+
];
|
|
76
|
+
/**
|
|
77
|
+
* Default fallback emoji for each log level
|
|
78
|
+
* These are used when no context-specific emoji matches
|
|
79
|
+
*/
|
|
80
|
+
exports.FALLBACK_EMOJI = {
|
|
81
|
+
DEBUG: 'đ',
|
|
82
|
+
INFO: 'âšī¸',
|
|
83
|
+
WARN: 'â ī¸',
|
|
84
|
+
ERROR: 'â',
|
|
85
|
+
LOG: 'â
'
|
|
86
|
+
};
|
|
87
|
+
//# sourceMappingURL=emoji-data.js.map
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Emoji data for context-aware logging
|
|
3
|
+
* Based on gitmoji.dev emoji set
|
|
4
|
+
* Each entry maps emoji to keywords that help identify when to use it
|
|
5
|
+
*/
|
|
6
|
+
import { EmojiMapping } from '../types';
|
|
7
|
+
/**
|
|
8
|
+
* Curated emoji mappings for context-aware logging
|
|
9
|
+
* Based on the gitmoji set from https://gitmoji.dev
|
|
10
|
+
* Ordered by specificity - more specific keywords first
|
|
11
|
+
*/
|
|
12
|
+
export declare const EMOJI_MAPPINGS: EmojiMapping[];
|
|
13
|
+
/**
|
|
14
|
+
* Default fallback emoji for each log level
|
|
15
|
+
* These are used when no context-specific emoji matches
|
|
16
|
+
*/
|
|
17
|
+
export declare const FALLBACK_EMOJI: Record<'DEBUG' | 'INFO' | 'WARN' | 'ERROR' | 'LOG', string>;
|
|
18
|
+
//# sourceMappingURL=emoji-data.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"emoji-data.d.ts","sourceRoot":"","sources":["../../../src/formatter/emoji-data.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,EAAE,YAAY,EAAE,MAAM,UAAU,CAAC;AAExC;;;;GAIG;AACH,eAAO,MAAM,cAAc,EAAE,YAAY,EAsFxC,CAAC;AAEF;;;GAGG;AACH,eAAO,MAAM,cAAc,EAAE,MAAM,CAAC,OAAO,GAAG,MAAM,GAAG,MAAM,GAAG,OAAO,GAAG,KAAK,EAAE,MAAM,CAMtF,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"emoji-data.js","sourceRoot":"","sources":["../../../src/formatter/emoji-data.ts"],"names":[],"mappings":";AAAA;;;;GAIG;;;AAIH;;;;GAIG;AACU,QAAA,cAAc,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AAM,CAAC,EAAE;IAClG,EAAE,KAAK,EAAE,IAAI,EAAE,IAAI,EAAE,aAAa,EAAE,WAAW,EAAE,sBAAsB,EAAE,QAAQ,EAAE,CAAC,WAAW,EAAE,SAAS,EAAE,OAAO,EAAE,YAAY,EAAE,SAAS,EAAE,YAAY,CAAC,EAAE;IAE7J,cAAc;IACd,EAAE,KAAK,EAAE,IAAI,EAAE,IAAI,EAAE,WAAW,EAAE,WAAW,EAAE,qBAAqB,EAAE,QAAQ,EAAE,CAAC,QAAQ,EAAE,SAAS,EAAE,UAAU,EAAE,MAAM,CAAC,EAAE;IAE3H,wCAAwC;IACxC,EAAE,KAAK,EAAE,GAAG,EAAE,IAAI,EAAE,YAAY,EAAE,WAAW,EAAE,aAAa,EAAE,QAAQ,EAAE,CAAC,SAAS,EAAE,KAAK,EAAE,aAAa,EAAE,SAAS,EAAE,UAAU,CAAC,EAAE;CACnI,CAAC;AAEF;;;GAGG;AACU,QAAA,cAAc,GAAgE;IACzF,KAAK,EAAE,IAAI;IACX,IAAI,EAAE,IAAI;IACV,IAAI,EAAE,IAAI;IACV,KAAK,EAAE,GAAG;IACV,GAAG,EAAE,GAAG;CACT,CAAC"}
|
|
@@ -0,0 +1,212 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Emoji selector for context-aware logging
|
|
4
|
+
* Analyzes log messages to select appropriate emoji based on context
|
|
5
|
+
*/
|
|
6
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
7
|
+
exports.EmojiSelector = void 0;
|
|
8
|
+
const types_1 = require("../types/index.cjs");
|
|
9
|
+
const emoji_data_1 = require("./emoji-data.cjs");
|
|
10
|
+
/**
|
|
11
|
+
* Emoji selector class
|
|
12
|
+
* Provides context-aware emoji selection for log messages
|
|
13
|
+
*/
|
|
14
|
+
class EmojiSelector {
|
|
15
|
+
/**
|
|
16
|
+
* Configure the emoji selector
|
|
17
|
+
* @param config - Configuration options
|
|
18
|
+
*/
|
|
19
|
+
static configure(config) {
|
|
20
|
+
EmojiSelector.config = {
|
|
21
|
+
...EmojiSelector.config,
|
|
22
|
+
...config
|
|
23
|
+
};
|
|
24
|
+
// Invalidate compiled cache when config changes
|
|
25
|
+
EmojiSelector.compiledMappings = null;
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
* Get current configuration
|
|
29
|
+
* @returns Current emoji configuration
|
|
30
|
+
*/
|
|
31
|
+
static getConfig() {
|
|
32
|
+
const { customMappings = [], customFallbacks = {}, ...rest } = EmojiSelector.config;
|
|
33
|
+
return {
|
|
34
|
+
...rest,
|
|
35
|
+
customMappings: [...customMappings],
|
|
36
|
+
customFallbacks: { ...customFallbacks }
|
|
37
|
+
};
|
|
38
|
+
}
|
|
39
|
+
/**
|
|
40
|
+
* Reset configuration to defaults
|
|
41
|
+
*/
|
|
42
|
+
static reset() {
|
|
43
|
+
EmojiSelector.config = {
|
|
44
|
+
customMappings: [],
|
|
45
|
+
customFallbacks: {},
|
|
46
|
+
useCustomOnly: false
|
|
47
|
+
};
|
|
48
|
+
// Clear compiled cache
|
|
49
|
+
EmojiSelector.compiledMappings = null;
|
|
50
|
+
}
|
|
51
|
+
/**
|
|
52
|
+
* Get compiled emoji mappings with precompiled regex patterns
|
|
53
|
+
* This is cached to avoid recompiling regex on every log line
|
|
54
|
+
*/
|
|
55
|
+
static getCompiledMappings() {
|
|
56
|
+
if (EmojiSelector.compiledMappings) {
|
|
57
|
+
return EmojiSelector.compiledMappings;
|
|
58
|
+
}
|
|
59
|
+
const { customMappings = [], useCustomOnly } = EmojiSelector.config;
|
|
60
|
+
const mappings = useCustomOnly ? customMappings : [...customMappings, ...emoji_data_1.EMOJI_MAPPINGS];
|
|
61
|
+
EmojiSelector.compiledMappings = mappings.map(mapping => ({
|
|
62
|
+
...mapping,
|
|
63
|
+
regexes: mapping.keywords.map(keyword => {
|
|
64
|
+
// Escape regex metacharacters to prevent ReDoS and invalid patterns
|
|
65
|
+
const escapedKeyword = keyword.replace(/[.*+?^${}()|[\]\\]/g, '\\$&');
|
|
66
|
+
// Precompile regex for performance
|
|
67
|
+
return new RegExp(`\\b${escapedKeyword}\\b`, 'i');
|
|
68
|
+
})
|
|
69
|
+
}));
|
|
70
|
+
return EmojiSelector.compiledMappings;
|
|
71
|
+
}
|
|
72
|
+
/**
|
|
73
|
+
* Select appropriate emoji based on log level and message content
|
|
74
|
+
* @param level - Log level
|
|
75
|
+
* @param message - Log message
|
|
76
|
+
* @param data - Optional log data
|
|
77
|
+
* @returns Selected emoji or empty string
|
|
78
|
+
*/
|
|
79
|
+
static selectEmoji(level, message, data) {
|
|
80
|
+
// Try to find context-aware emoji
|
|
81
|
+
const contextEmoji = EmojiSelector.findContextEmoji(message, data);
|
|
82
|
+
if (contextEmoji) {
|
|
83
|
+
return contextEmoji;
|
|
84
|
+
}
|
|
85
|
+
// Fall back to level-based emoji
|
|
86
|
+
return EmojiSelector.getFallbackEmoji(level);
|
|
87
|
+
}
|
|
88
|
+
/**
|
|
89
|
+
* Find emoji based on message and data context
|
|
90
|
+
* @param message - Log message
|
|
91
|
+
* @param data - Optional log data
|
|
92
|
+
* @returns Emoji if match found, null otherwise
|
|
93
|
+
*/
|
|
94
|
+
static findContextEmoji(message, data) {
|
|
95
|
+
const searchText = EmojiSelector.prepareSearchText(message, data);
|
|
96
|
+
const compiledMappings = EmojiSelector.getCompiledMappings();
|
|
97
|
+
// Search through compiled mappings for keyword matches
|
|
98
|
+
for (const mapping of compiledMappings) {
|
|
99
|
+
if (EmojiSelector.matchesWithCompiledRegexes(searchText, mapping.regexes)) {
|
|
100
|
+
return mapping.emoji;
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
return null;
|
|
104
|
+
}
|
|
105
|
+
/**
|
|
106
|
+
* Get combined mappings (custom + default or custom only)
|
|
107
|
+
* @returns Array of emoji mappings
|
|
108
|
+
* @deprecated Use getCompiledMappings() for better performance
|
|
109
|
+
*/
|
|
110
|
+
static getMappings() {
|
|
111
|
+
const { customMappings = [], useCustomOnly = false } = EmojiSelector.config;
|
|
112
|
+
if (useCustomOnly) {
|
|
113
|
+
return customMappings;
|
|
114
|
+
}
|
|
115
|
+
// Merge custom mappings first (higher priority) with defaults
|
|
116
|
+
return [...customMappings, ...emoji_data_1.EMOJI_MAPPINGS];
|
|
117
|
+
}
|
|
118
|
+
/**
|
|
119
|
+
* Prepare text for searching by combining message and data
|
|
120
|
+
* @param message - Log message
|
|
121
|
+
* @param data - Optional log data
|
|
122
|
+
* @returns Lowercase combined text
|
|
123
|
+
*/
|
|
124
|
+
static prepareSearchText(message, data) {
|
|
125
|
+
let text = message.toLowerCase();
|
|
126
|
+
// If data is provided and is an object, include its keys and string values
|
|
127
|
+
if (data && typeof data === 'object') {
|
|
128
|
+
try {
|
|
129
|
+
const dataStr = JSON.stringify(data).toLowerCase();
|
|
130
|
+
text += ' ' + dataStr;
|
|
131
|
+
}
|
|
132
|
+
catch {
|
|
133
|
+
// Ignore circular references or stringify errors
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
else if (data && typeof data === 'string') {
|
|
137
|
+
text += ' ' + data.toLowerCase();
|
|
138
|
+
}
|
|
139
|
+
return text;
|
|
140
|
+
}
|
|
141
|
+
/**
|
|
142
|
+
* Check if search text matches any of the precompiled regexes
|
|
143
|
+
* @param searchText - Lowercase text to search in
|
|
144
|
+
* @param regexes - Precompiled regex patterns
|
|
145
|
+
* @returns true if any regex matches
|
|
146
|
+
*/
|
|
147
|
+
static matchesWithCompiledRegexes(searchText, regexes) {
|
|
148
|
+
return regexes.some(regex => regex.test(searchText));
|
|
149
|
+
}
|
|
150
|
+
/**
|
|
151
|
+
* Check if search text matches any of the keywords
|
|
152
|
+
* @param searchText - Lowercase text to search in
|
|
153
|
+
* @param keywords - Keywords to look for
|
|
154
|
+
* @returns true if any keyword matches
|
|
155
|
+
* @deprecated Use matchesWithCompiledRegexes() for better performance
|
|
156
|
+
*/
|
|
157
|
+
static matchesKeywords(searchText, keywords) {
|
|
158
|
+
return keywords.some(keyword => {
|
|
159
|
+
// Escape regex metacharacters to prevent ReDoS and invalid patterns
|
|
160
|
+
const escapedKeyword = keyword.replace(/[.*+?^${}()|[\]\\]/g, '\\$&');
|
|
161
|
+
// Use word boundary matching for more accurate results
|
|
162
|
+
// Safe: escapedKeyword is sanitized by regex escape above
|
|
163
|
+
const regex = new RegExp(`\\b${escapedKeyword}\\b`, 'i');
|
|
164
|
+
return regex.test(searchText);
|
|
165
|
+
});
|
|
166
|
+
}
|
|
167
|
+
/**
|
|
168
|
+
* Get fallback emoji for a given log level
|
|
169
|
+
* @param level - Log level
|
|
170
|
+
* @returns Fallback emoji for the level
|
|
171
|
+
*/
|
|
172
|
+
static getFallbackEmoji(level) {
|
|
173
|
+
const levelName = EmojiSelector.getLevelName(level);
|
|
174
|
+
// Explicitly handle unknown levels: no emoji by default
|
|
175
|
+
if (levelName === 'UNKNOWN') {
|
|
176
|
+
return '';
|
|
177
|
+
}
|
|
178
|
+
const { customFallbacks = {} } = EmojiSelector.config;
|
|
179
|
+
// Check custom fallbacks first
|
|
180
|
+
// Safe: levelName is constrained to specific log level strings
|
|
181
|
+
if (levelName in customFallbacks && customFallbacks[levelName]) {
|
|
182
|
+
return customFallbacks[levelName] || '';
|
|
183
|
+
}
|
|
184
|
+
// Use default fallback
|
|
185
|
+
// Safe: levelName is constrained to specific log level strings
|
|
186
|
+
return emoji_data_1.FALLBACK_EMOJI[levelName] || '';
|
|
187
|
+
}
|
|
188
|
+
/**
|
|
189
|
+
* Convert LogLevel enum to string
|
|
190
|
+
* @param level - Log level
|
|
191
|
+
* @returns Level name as string
|
|
192
|
+
*/
|
|
193
|
+
static getLevelName(level) {
|
|
194
|
+
switch (level) {
|
|
195
|
+
case types_1.LogLevel.DEBUG: return 'DEBUG';
|
|
196
|
+
case types_1.LogLevel.INFO: return 'INFO';
|
|
197
|
+
case types_1.LogLevel.WARN: return 'WARN';
|
|
198
|
+
case types_1.LogLevel.ERROR: return 'ERROR';
|
|
199
|
+
case types_1.LogLevel.LOG: return 'LOG';
|
|
200
|
+
default: return 'UNKNOWN';
|
|
201
|
+
}
|
|
202
|
+
}
|
|
203
|
+
}
|
|
204
|
+
exports.EmojiSelector = EmojiSelector;
|
|
205
|
+
EmojiSelector.config = {
|
|
206
|
+
customMappings: [],
|
|
207
|
+
customFallbacks: {},
|
|
208
|
+
useCustomOnly: false
|
|
209
|
+
};
|
|
210
|
+
// Cache for precompiled regex patterns
|
|
211
|
+
EmojiSelector.compiledMappings = null;
|
|
212
|
+
//# sourceMappingURL=emoji-selector.js.map
|