@wgtechlabs/log-engine 2.2.2-pr.4adaa01 â 2.2.2-pr.84b390b
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 +202 -0
- 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 +184 -0
- package/dist/cjs/formatter/emoji-selector.d.ts +74 -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 +74 -0
- package/dist/esm/formatter/emoji-selector.d.ts.map +1 -0
- package/dist/esm/formatter/emoji-selector.js +180 -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 +1 -1
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.
|
|
@@ -414,6 +415,207 @@ LogEngine.error('Connection failed');
|
|
|
414
415
|
|
|
415
416
|
**Note**: Log levels (`[DEBUG]`, `[INFO]`, `[WARN]`, `[ERROR]`, `[LOG]`) are always included regardless of configuration to maintain log clarity and filtering capabilities.
|
|
416
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
|
+
|
|
417
619
|
## đ Advanced Data Redaction
|
|
418
620
|
|
|
419
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.
|
|
@@ -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,eAA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BAAyB;IACzB,EAAE,KAAK,EAAE,IAAI,EAAE,IAAI,EAAE,cAAc,EAAE,WAAW,EAAE,oBAAoB,EAAE,QAAQ,EAAE,CAAC,SAAS,EAAE,OAAO,CAAC,EAAE;IACxG,EAAE,KAAK,EAAE,IAAI,EAAE,IAAI,EAAE,QAAQ,EAAE,WAAW,EAAE,aAAa,EAAE,QAAQ,EAAE,CAAC,QAAQ,EAAE,OAAO,EAAE,MAAM,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,184 @@
|
|
|
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
|
+
// eslint-disable-next-line security/detect-non-literal-regexp -- Safe: keyword is escaped above to prevent ReDoS
|
|
68
|
+
return new RegExp(`\\b${escapedKeyword}\\b`, 'i');
|
|
69
|
+
})
|
|
70
|
+
}));
|
|
71
|
+
return EmojiSelector.compiledMappings;
|
|
72
|
+
}
|
|
73
|
+
/**
|
|
74
|
+
* Select appropriate emoji based on log level and message content
|
|
75
|
+
* @param level - Log level
|
|
76
|
+
* @param message - Log message
|
|
77
|
+
* @param data - Optional log data
|
|
78
|
+
* @returns Selected emoji or empty string
|
|
79
|
+
*/
|
|
80
|
+
static selectEmoji(level, message, data) {
|
|
81
|
+
// Try to find context-aware emoji
|
|
82
|
+
const contextEmoji = EmojiSelector.findContextEmoji(message, data);
|
|
83
|
+
if (contextEmoji) {
|
|
84
|
+
return contextEmoji;
|
|
85
|
+
}
|
|
86
|
+
// Fall back to level-based emoji
|
|
87
|
+
return EmojiSelector.getFallbackEmoji(level);
|
|
88
|
+
}
|
|
89
|
+
/**
|
|
90
|
+
* Find emoji based on message and data context
|
|
91
|
+
* @param message - Log message
|
|
92
|
+
* @param data - Optional log data
|
|
93
|
+
* @returns Emoji if match found, null otherwise
|
|
94
|
+
*/
|
|
95
|
+
static findContextEmoji(message, data) {
|
|
96
|
+
const searchText = EmojiSelector.prepareSearchText(message, data);
|
|
97
|
+
const compiledMappings = EmojiSelector.getCompiledMappings();
|
|
98
|
+
// Search through compiled mappings for keyword matches
|
|
99
|
+
for (const mapping of compiledMappings) {
|
|
100
|
+
if (EmojiSelector.matchesWithCompiledRegexes(searchText, mapping.regexes)) {
|
|
101
|
+
return mapping.emoji;
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
return null;
|
|
105
|
+
}
|
|
106
|
+
/**
|
|
107
|
+
* Prepare text for searching by combining message and data
|
|
108
|
+
* @param message - Log message
|
|
109
|
+
* @param data - Optional log data
|
|
110
|
+
* @returns Lowercase combined text
|
|
111
|
+
*/
|
|
112
|
+
static prepareSearchText(message, data) {
|
|
113
|
+
let text = message.toLowerCase();
|
|
114
|
+
// If data is provided and is an object, include its keys and string values
|
|
115
|
+
if (data && typeof data === 'object') {
|
|
116
|
+
try {
|
|
117
|
+
const dataStr = JSON.stringify(data).toLowerCase();
|
|
118
|
+
text += ' ' + dataStr;
|
|
119
|
+
}
|
|
120
|
+
catch {
|
|
121
|
+
// Ignore circular references or stringify errors
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
else if (data && typeof data === 'string') {
|
|
125
|
+
text += ' ' + data.toLowerCase();
|
|
126
|
+
}
|
|
127
|
+
return text;
|
|
128
|
+
}
|
|
129
|
+
/**
|
|
130
|
+
* Check if search text matches any of the precompiled regexes
|
|
131
|
+
* @param searchText - Lowercase text to search in
|
|
132
|
+
* @param regexes - Precompiled regex patterns
|
|
133
|
+
* @returns true if any regex matches
|
|
134
|
+
*/
|
|
135
|
+
static matchesWithCompiledRegexes(searchText, regexes) {
|
|
136
|
+
return regexes.some(regex => regex.test(searchText));
|
|
137
|
+
}
|
|
138
|
+
/**
|
|
139
|
+
* Get fallback emoji for a given log level
|
|
140
|
+
* @param level - Log level
|
|
141
|
+
* @returns Fallback emoji for the level
|
|
142
|
+
*/
|
|
143
|
+
static getFallbackEmoji(level) {
|
|
144
|
+
const levelName = EmojiSelector.getLevelName(level);
|
|
145
|
+
// Explicitly handle unknown levels: no emoji by default
|
|
146
|
+
if (levelName === 'UNKNOWN') {
|
|
147
|
+
return '';
|
|
148
|
+
}
|
|
149
|
+
const { customFallbacks = {} } = EmojiSelector.config;
|
|
150
|
+
// Check custom fallbacks first
|
|
151
|
+
// eslint-disable-next-line security/detect-object-injection -- Safe: levelName is type-constrained to log level strings
|
|
152
|
+
if (levelName in customFallbacks && customFallbacks[levelName]) {
|
|
153
|
+
// eslint-disable-next-line security/detect-object-injection -- Safe: levelName is type-constrained to log level strings
|
|
154
|
+
return customFallbacks[levelName] || '';
|
|
155
|
+
}
|
|
156
|
+
// Use default fallback
|
|
157
|
+
// eslint-disable-next-line security/detect-object-injection -- Safe: levelName is type-constrained to log level strings
|
|
158
|
+
return emoji_data_1.FALLBACK_EMOJI[levelName] || '';
|
|
159
|
+
}
|
|
160
|
+
/**
|
|
161
|
+
* Convert LogLevel enum to string
|
|
162
|
+
* @param level - Log level
|
|
163
|
+
* @returns Level name as string
|
|
164
|
+
*/
|
|
165
|
+
static getLevelName(level) {
|
|
166
|
+
switch (level) {
|
|
167
|
+
case types_1.LogLevel.DEBUG: return 'DEBUG';
|
|
168
|
+
case types_1.LogLevel.INFO: return 'INFO';
|
|
169
|
+
case types_1.LogLevel.WARN: return 'WARN';
|
|
170
|
+
case types_1.LogLevel.ERROR: return 'ERROR';
|
|
171
|
+
case types_1.LogLevel.LOG: return 'LOG';
|
|
172
|
+
default: return 'UNKNOWN';
|
|
173
|
+
}
|
|
174
|
+
}
|
|
175
|
+
}
|
|
176
|
+
exports.EmojiSelector = EmojiSelector;
|
|
177
|
+
EmojiSelector.config = {
|
|
178
|
+
customMappings: [],
|
|
179
|
+
customFallbacks: {},
|
|
180
|
+
useCustomOnly: false
|
|
181
|
+
};
|
|
182
|
+
// Cache for precompiled regex patterns
|
|
183
|
+
EmojiSelector.compiledMappings = null;
|
|
184
|
+
//# sourceMappingURL=emoji-selector.js.map
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Emoji selector for context-aware logging
|
|
3
|
+
* Analyzes log messages to select appropriate emoji based on context
|
|
4
|
+
*/
|
|
5
|
+
import { LogLevel, LogData, EmojiConfig } from '../types';
|
|
6
|
+
/**
|
|
7
|
+
* Emoji selector class
|
|
8
|
+
* Provides context-aware emoji selection for log messages
|
|
9
|
+
*/
|
|
10
|
+
export declare class EmojiSelector {
|
|
11
|
+
private static config;
|
|
12
|
+
private static compiledMappings;
|
|
13
|
+
/**
|
|
14
|
+
* Configure the emoji selector
|
|
15
|
+
* @param config - Configuration options
|
|
16
|
+
*/
|
|
17
|
+
static configure(config: Partial<EmojiConfig>): void;
|
|
18
|
+
/**
|
|
19
|
+
* Get current configuration
|
|
20
|
+
* @returns Current emoji configuration
|
|
21
|
+
*/
|
|
22
|
+
static getConfig(): EmojiConfig;
|
|
23
|
+
/**
|
|
24
|
+
* Reset configuration to defaults
|
|
25
|
+
*/
|
|
26
|
+
static reset(): void;
|
|
27
|
+
/**
|
|
28
|
+
* Get compiled emoji mappings with precompiled regex patterns
|
|
29
|
+
* This is cached to avoid recompiling regex on every log line
|
|
30
|
+
*/
|
|
31
|
+
private static getCompiledMappings;
|
|
32
|
+
/**
|
|
33
|
+
* Select appropriate emoji based on log level and message content
|
|
34
|
+
* @param level - Log level
|
|
35
|
+
* @param message - Log message
|
|
36
|
+
* @param data - Optional log data
|
|
37
|
+
* @returns Selected emoji or empty string
|
|
38
|
+
*/
|
|
39
|
+
static selectEmoji(level: LogLevel, message: string, data?: LogData): string;
|
|
40
|
+
/**
|
|
41
|
+
* Find emoji based on message and data context
|
|
42
|
+
* @param message - Log message
|
|
43
|
+
* @param data - Optional log data
|
|
44
|
+
* @returns Emoji if match found, null otherwise
|
|
45
|
+
*/
|
|
46
|
+
private static findContextEmoji;
|
|
47
|
+
/**
|
|
48
|
+
* Prepare text for searching by combining message and data
|
|
49
|
+
* @param message - Log message
|
|
50
|
+
* @param data - Optional log data
|
|
51
|
+
* @returns Lowercase combined text
|
|
52
|
+
*/
|
|
53
|
+
private static prepareSearchText;
|
|
54
|
+
/**
|
|
55
|
+
* Check if search text matches any of the precompiled regexes
|
|
56
|
+
* @param searchText - Lowercase text to search in
|
|
57
|
+
* @param regexes - Precompiled regex patterns
|
|
58
|
+
* @returns true if any regex matches
|
|
59
|
+
*/
|
|
60
|
+
private static matchesWithCompiledRegexes;
|
|
61
|
+
/**
|
|
62
|
+
* Get fallback emoji for a given log level
|
|
63
|
+
* @param level - Log level
|
|
64
|
+
* @returns Fallback emoji for the level
|
|
65
|
+
*/
|
|
66
|
+
private static getFallbackEmoji;
|
|
67
|
+
/**
|
|
68
|
+
* Convert LogLevel enum to string
|
|
69
|
+
* @param level - Log level
|
|
70
|
+
* @returns Level name as string
|
|
71
|
+
*/
|
|
72
|
+
private static getLevelName;
|
|
73
|
+
}
|
|
74
|
+
//# sourceMappingURL=emoji-selector.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"emoji-selector.d.ts","sourceRoot":"","sources":["../../../src/formatter/emoji-selector.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EAAE,QAAQ,EAAE,OAAO,EAAE,WAAW,EAAE,MAAM,UAAU,CAAC;AAc1D;;;GAGG;AACH,qBAAa,aAAa;IACxB,OAAO,CAAC,MAAM,CAAC,MAAM,CAInB;IAGF,OAAO,CAAC,MAAM,CAAC,gBAAgB,CAAuC;IAEtE;;;OAGG;IACH,MAAM,CAAC,SAAS,CAAC,MAAM,EAAE,OAAO,CAAC,WAAW,CAAC,GAAG,IAAI;IASpD;;;OAGG;IACH,MAAM,CAAC,SAAS,IAAI,WAAW;IAU/B;;OAEG;IACH,MAAM,CAAC,KAAK,IAAI,IAAI;IAUpB;;;OAGG;IACH,OAAO,CAAC,MAAM,CAAC,mBAAmB;IAsBlC;;;;;;OAMG;IACH,MAAM,CAAC,WAAW,CAAC,KAAK,EAAE,QAAQ,EAAE,OAAO,EAAE,MAAM,EAAE,IAAI,CAAC,EAAE,OAAO,GAAG,MAAM;IAW5E;;;;;OAKG;IACH,OAAO,CAAC,MAAM,CAAC,gBAAgB;IAc/B;;;;;OAKG;IACH,OAAO,CAAC,MAAM,CAAC,iBAAiB;IAkBhC;;;;;OAKG;IACH,OAAO,CAAC,MAAM,CAAC,0BAA0B;IAIzC;;;;OAIG;IACH,OAAO,CAAC,MAAM,CAAC,gBAAgB;IAsB/B;;;;OAIG;IACH,OAAO,CAAC,MAAM,CAAC,YAAY;CAU5B"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"emoji-selector.js","sourceRoot":"","sources":["../../../src/formatter/emoji-selector.ts"],"names":[],"mappings":";AAAA;;;GAGG;;;AAEH,oCAA0D;AAC1D,6CAA8D;AAa9D;;;GAGG;AACH,MAAa,aAAa;IAUxB;;;OAGG;IACH,MAAM,CAAC,SAAS,CAAC,MAA4B;QAC3C,aAAa,CAAC,MAAM,GAAG;YACrB,GAAG,aAAa,CAAC,MAAM;YACvB,GAAG,MAAM;SACV,CAAC;QACF,gDAAgD;QAChD,aAAa,CAAC,gBAAgB,GAAG,IAAI,CAAC;IACxC,CAAC;IAED;;;OAGG;IACH,MAAM,CAAC,SAAS;QACd,MAAM,EAAE,cAAc,GAAG,EAAE,EAAE,eAAe,GAAG,EAAE,EAAE,GAAG,IAAI,EAAE,GAAG,aAAa,CAAC,MAAM,CAAC;QAEpF,OAAO;YACL,GAAG,IAAI;YACP,cAAc,EAAE,CAAC,GAAG,cAAc,CAAC;YACnC,eAAe,EAAE,EAAE,GAAG,eAAe,EAAE;SACxC,CAAC;IACJ,CAAC;IAED;;OAEG;IACH,MAAM,CAAC,KAAK;QACV,aAAa,CAAC,MAAM,GAAG;YACrB,cAAc,EAAE,EAAE;YAClB,eAAe,EAAE,EAAE;YACnB,aAAa,EAAE,KAAK;SACrB,CAAC;QACF,uBAAuB;QACvB,aAAa,CAAC,gBAAgB,GAAG,IAAI,CAAC;IACxC,CAAC;IAED;;;OAGG;IACK,MAAM,CAAC,mBAAmB;QAChC,IAAI,aAAa,CAAC,gBAA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;YAC5B,OAAO,EAAE,CAAC;QACZ,CAAC;QAED,MAAM,EAAE,eAAe,GAAG,EAAE,EAAE,GAAG,aAAa,CAAC,MAAM,CAAC;QAEtD,+BAA+B;QAC/B,wHAAwH;QACxH,IAAI,SAAS,IAAI,eAAe,IAAI,eAAe,CAAC,SAAS,CAAC,EAAE,CAAC;YAC/D,wHAAwH;YACxH,OAAO,eAAe,CAAC,SAAS,CAAC,IAAI,EAAE,CAAC;QAC1C,CAAC;QAED,uBAAuB;QACvB,wHAAwH;QACxH,OAAO,2BAAc,CAAC,SAAS,CAAC,IAAI,EAAE,CAAC;IACzC,CAAC;IAED;;;;OAIG;IACK,MAAM,CAAC,YAAY,CAAC,KAAe;QACzC,QAAQ,KAAK,EAAE,CAAC;YAChB,KAAK,gBAAQ,CAAC,KAAK,CAAC,CAAC,OAAO,OAAO,CAAC;YACpC,KAAK,gBAAQ,CAAC,IAAI,CAAC,CAAC,OAAO,MAAM,CAAC;YAClC,KAAK,gBAAQ,CAAC,IAAI,CAAC,CAAC,OAAO,MAAM,CAAC;YAClC,KAAK,gBAAQ,CAAC,KAAK,CAAC,CAAC,OAAO,OAAO,CAAC;YACpC,KAAK,gBAAQ,CAAC,GAAG,CAAC,CAAC,OAAO,KAAK,CAAC;YAChC,OAAO,CAAC,CAAC,OAAO,SAAS,CAAC;QAC1B,CAAC;IACH,CAAC;;AA7LH,sCA8LC;AA7LgB,oBAAM,GAAgB;IACnC,cAAc,EAAE,EAAE;IAClB,eAAe,EAAE,EAAE;IACnB,aAAa,EAAE,KAAK;CACrB,CAAC;AAEF,uCAAuC;AACxB,8BAAgB,GAAkC,IAAI,CAAC"}
|
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
* Provides centralized access to all formatting functionality
|
|
5
5
|
*/
|
|
6
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;
|
|
7
|
+
exports.LogFormatter = exports.FALLBACK_EMOJI = exports.EMOJI_MAPPINGS = exports.EmojiSelector = exports.styleData = exports.formatData = exports.formatTimestamp = exports.getTimestampComponents = exports.colorScheme = exports.colors = exports.MessageFormatter = void 0;
|
|
8
8
|
var message_formatter_1 = require("./message-formatter.cjs");
|
|
9
9
|
Object.defineProperty(exports, "MessageFormatter", { enumerable: true, get: function () { return message_formatter_1.MessageFormatter; } });
|
|
10
10
|
var colors_1 = require("./colors.cjs");
|
|
@@ -16,6 +16,11 @@ Object.defineProperty(exports, "formatTimestamp", { enumerable: true, get: funct
|
|
|
16
16
|
var data_formatter_1 = require("./data-formatter.cjs");
|
|
17
17
|
Object.defineProperty(exports, "formatData", { enumerable: true, get: function () { return data_formatter_1.formatData; } });
|
|
18
18
|
Object.defineProperty(exports, "styleData", { enumerable: true, get: function () { return data_formatter_1.styleData; } });
|
|
19
|
+
var emoji_selector_1 = require("./emoji-selector.cjs");
|
|
20
|
+
Object.defineProperty(exports, "EmojiSelector", { enumerable: true, get: function () { return emoji_selector_1.EmojiSelector; } });
|
|
21
|
+
var emoji_data_1 = require("./emoji-data.cjs");
|
|
22
|
+
Object.defineProperty(exports, "EMOJI_MAPPINGS", { enumerable: true, get: function () { return emoji_data_1.EMOJI_MAPPINGS; } });
|
|
23
|
+
Object.defineProperty(exports, "FALLBACK_EMOJI", { enumerable: true, get: function () { return emoji_data_1.FALLBACK_EMOJI; } });
|
|
19
24
|
// Backward compatibility - maintain the original LogFormatter class interface
|
|
20
25
|
var message_formatter_2 = require("./message-formatter.cjs");
|
|
21
26
|
Object.defineProperty(exports, "LogFormatter", { enumerable: true, get: function () { return message_formatter_2.MessageFormatter; } });
|
|
@@ -6,5 +6,7 @@ export { MessageFormatter } from './message-formatter';
|
|
|
6
6
|
export { colors, colorScheme } from './colors';
|
|
7
7
|
export { getTimestampComponents, formatTimestamp } from './timestamp';
|
|
8
8
|
export { formatData, styleData } from './data-formatter';
|
|
9
|
+
export { EmojiSelector } from './emoji-selector';
|
|
10
|
+
export { EMOJI_MAPPINGS, FALLBACK_EMOJI } from './emoji-data';
|
|
9
11
|
export { MessageFormatter as LogFormatter } from './message-formatter';
|
|
10
12
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1 +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;
|
|
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;AACzD,OAAO,EAAE,aAAa,EAAE,MAAM,kBAAkB,CAAC;AACjD,OAAO,EAAE,cAAc,EAAE,cAAc,EAAE,MAAM,cAAc,CAAC;AAG9D,OAAO,EAAE,gBAAgB,IAAI,YAAY,EAAE,MAAM,qBAAqB,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/formatter/index.ts"],"names":[],"mappings":";AAAA;;;GAGG;;;AAEH,yDAAuD;AAA9C,qHAAA,gBAAgB,OAAA;AACzB,mCAA+C;AAAtC,gGAAA,MAAM,OAAA;AAAE,qGAAA,WAAW,OAAA;AAC5B,yCAAsE;AAA7D,mHAAA,sBAAsB,OAAA;AAAE,4GAAA,eAAe,OAAA;AAChD,mDAAyD;AAAhD,4GAAA,UAAU,OAAA;AAAE,2GAAA,SAAS,OAAA;
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/formatter/index.ts"],"names":[],"mappings":";AAAA;;;GAGG;;;AAEH,yDAAuD;AAA9C,qHAAA,gBAAgB,OAAA;AACzB,mCAA+C;AAAtC,gGAAA,MAAM,OAAA;AAAE,qGAAA,WAAW,OAAA;AAC5B,yCAAsE;AAA7D,mHAAA,sBAAsB,OAAA;AAAE,4GAAA,eAAe,OAAA;AAChD,mDAAyD;AAAhD,4GAAA,UAAU,OAAA;AAAE,2GAAA,SAAS,OAAA;AAC9B,mDAAiD;AAAxC,+GAAA,aAAa,OAAA;AACtB,2CAA8D;AAArD,4GAAA,cAAc,OAAA;AAAE,4GAAA,cAAc,OAAA;AAEvC,8EAA8E;AAC9E,yDAAuE;AAA9D,iHAAA,gBAAgB,OAAgB"}
|