@mks2508/better-logger 5.0.0 → 5.0.2
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/dist/chunks/{Logger-Cbi1f10o.js → Logger-CKqzXDh3.js} +2 -2
- package/dist/chunks/{Logger-Cbi1f10o.js.map → Logger-CKqzXDh3.js.map} +1 -1
- package/dist/chunks/{Logger-BZ7B7OXE.js → Logger-D_vuKP4l.js} +2 -2
- package/dist/chunks/{Logger-BZ7B7OXE.js.map → Logger-D_vuKP4l.js.map} +1 -1
- package/dist/chunks/cli-module-B-njrTWb.js +2 -0
- package/dist/chunks/cli-module-B-njrTWb.js.map +1 -0
- package/dist/chunks/{cli-module-ClIJmaT8.js → cli-module-Cx7qotPY.js} +16 -9
- package/dist/chunks/cli-module-Cx7qotPY.js.map +1 -0
- package/dist/cli.cjs +1 -1
- package/dist/cli.js +1 -1
- package/dist/exports.cjs +1 -1
- package/dist/exports.js +1 -1
- package/dist/index.cjs +1 -1
- package/dist/index.js +3 -3
- package/dist/styling.cjs +1 -1
- package/dist/styling.js +2 -2
- package/dist/terminal/formatter.d.ts.map +1 -1
- package/package.json +5 -1
- package/.claude/settings.local.json +0 -48
- package/.github/workflows/ci-quality.yml +0 -357
- package/.github/workflows/docs-demo.yml +0 -119
- package/.github/workflows/releases-core.yml +0 -512
- package/.github/workflows/releases-full.yml +0 -582
- package/.github/workflows-backup/ci.yml +0 -221
- package/.github/workflows-backup/nightly.yml +0 -196
- package/.github/workflows-backup/release-optimized.yml +0 -373
- package/.github/workflows-backup/release.yml +0 -269
- package/.release-notes-0.2.0.md +0 -129
- package/.yamllint +0 -28
- package/CHANGELOG.json +0 -1076
- package/CHANGELOG.md +0 -209
- package/CLAUDE.md +0 -217
- package/bun.lock +0 -333
- package/demo.html +0 -847
- package/dist/chunks/cli-module-CadqgZ1Z.js +0 -2
- package/dist/chunks/cli-module-CadqgZ1Z.js.map +0 -1
- package/dist/chunks/cli-module-ClIJmaT8.js.map +0 -1
- package/docs/API.md +0 -918
- package/docs/CORE.md +0 -264
- package/docs/DEVELOPMENT.md +0 -731
- package/docs/EXPORTS.md +0 -467
- package/docs/PACKAGES.md +0 -244
- package/docs/STYLING.md +0 -405
- package/docs/_config.yml +0 -36
- package/docs/index.md +0 -179
- package/examples/README.md +0 -208
- package/examples/basic-logging.js +0 -75
- package/examples/data-export.js +0 -234
- package/examples/package.json +0 -16
- package/examples/performance-timing.js +0 -170
- package/examples/simplified-api.js +0 -124
- package/examples/styling-themes.js +0 -207
- package/index.html +0 -358
- package/packages/core/package.json +0 -57
- package/packages/exports/package.json +0 -41
- package/packages/nodejs-opentui/README.md +0 -232
- package/packages/nodejs-opentui/package.json +0 -72
- package/packages/nodejs-opentui/src/LogRenderer.ts +0 -171
- package/packages/nodejs-opentui/src/OpenTUILogHandler.ts +0 -178
- package/packages/nodejs-opentui/src/components/LogBadge.tsx +0 -131
- package/packages/nodejs-opentui/src/index.ts +0 -133
- package/packages/nodejs-opentui/src/types.ts +0 -158
- package/packages/nodejs-opentui/tsconfig.json +0 -20
- package/packages/styling/package.json +0 -41
- package/playground/demo-all.ts +0 -95
- package/playground/demo-box.ts +0 -85
- package/playground/demo-levels.ts +0 -56
- package/playground/demo-real-world.ts +0 -98
- package/playground/demo-spinner.ts +0 -77
- package/playground/demo-steps.ts +0 -72
- package/playground/demo-table.ts +0 -83
- package/project-utils/README.md +0 -172
- package/project-utils/auto-release-gemini.ts +0 -1193
- package/project-utils/auto-release-ui.ts +0 -1329
- package/project-utils/commit-generator.ts +0 -1385
- package/project-utils/commit-ui.ts +0 -264
- package/project-utils/git-utils.ts +0 -199
- package/project-utils/github-release-manager.ts +0 -466
- package/project-utils/project-config.ts +0 -260
- package/project-utils/prompt-templates.js +0 -345
- package/project-utils/prompt-templates.ts +0 -422
- package/project-utils/version-manager.ts +0 -1078
- package/public/vite.svg +0 -1
- package/src/Logger.ts +0 -1858
- package/src/ScopedLogger.ts +0 -256
- package/src/cli/CommandProcessor.ts +0 -248
- package/src/cli/commands/ConfigCommand.ts +0 -93
- package/src/cli/commands/ExportCommand.ts +0 -276
- package/src/cli/commands/HistoryCommand.ts +0 -117
- package/src/cli/commands/StatusCommand.ts +0 -112
- package/src/cli/commands/ThemeCommand.ts +0 -88
- package/src/cli/help.ts +0 -127
- package/src/cli/index.ts +0 -71
- package/src/cli-module.ts +0 -21
- package/src/cli-primitives/box.ts +0 -86
- package/src/cli-primitives/cli-table.ts +0 -62
- package/src/cli-primitives/divider.ts +0 -17
- package/src/cli-primitives/header.ts +0 -18
- package/src/cli-primitives/index.ts +0 -13
- package/src/cli-primitives/server-fallback.ts +0 -54
- package/src/cli-primitives/spinner.ts +0 -133
- package/src/cli-primitives/step.ts +0 -22
- package/src/constants.ts +0 -313
- package/src/core.ts +0 -397
- package/src/example.ts +0 -210
- package/src/exports-module.ts +0 -311
- package/src/handlers/AnalyticsLogHandler.ts +0 -22
- package/src/handlers/ExportLogHandler.ts +0 -610
- package/src/handlers/FileLogHandler.ts +0 -169
- package/src/handlers/RemoteLogHandler.ts +0 -42
- package/src/handlers/index.ts +0 -8
- package/src/hooks/HookManager.ts +0 -177
- package/src/hooks/index.ts +0 -1
- package/src/index.ts +0 -395
- package/src/main.ts +0 -196
- package/src/serializers/SerializerRegistry.ts +0 -173
- package/src/serializers/index.ts +0 -1
- package/src/style.css +0 -96
- package/src/styling/LogStyleBuilder.ts +0 -355
- package/src/styling/SemanticStyles.ts +0 -380
- package/src/styling/SmartPresets.ts +0 -288
- package/src/styling/StyleBuilder.ts +0 -319
- package/src/styling/StyleCache.ts +0 -131
- package/src/styling/banners.ts +0 -168
- package/src/styling/index.ts +0 -27
- package/src/styling/themes.ts +0 -235
- package/src/styling-module.ts +0 -244
- package/src/terminal/color-converter.ts +0 -315
- package/src/terminal/formatter.ts +0 -236
- package/src/terminal/terminal-renderer.ts +0 -342
- package/src/transports/ConsoleTransport.ts +0 -28
- package/src/transports/FileTransport.ts +0 -53
- package/src/transports/HttpTransport.ts +0 -56
- package/src/transports/TransportManager.ts +0 -130
- package/src/transports/index.ts +0 -4
- package/src/types/core.ts +0 -417
- package/src/types/handlers.ts +0 -95
- package/src/types/hooks.ts +0 -45
- package/src/types/index.ts +0 -83
- package/src/types/serializers.ts +0 -30
- package/src/types/transports.ts +0 -52
- package/src/typescript.svg +0 -1
- package/src/utils/adapter.ts +0 -291
- package/src/utils/ansi-colors.ts +0 -333
- package/src/utils/environment-detector.ts +0 -170
- package/src/utils/environment.ts +0 -94
- package/src/utils/formatting.ts +0 -332
- package/src/utils/index.ts +0 -33
- package/src/utils/opentui-detection.ts +0 -138
- package/src/utils/output.ts +0 -227
- package/src/utils/stackTrace.ts +0 -144
- package/src/utils/timestamps.ts +0 -80
- package/src/vite-env.d.ts +0 -1
- package/src/writers/BufferWriter.ts +0 -157
- package/src/writers/index.ts +0 -6
- package/test-core-browser.html +0 -237
- package/test-core-node.js +0 -63
- package/tests/test-conflict-resolution.ts +0 -391
- package/tests/validate-workflows.sh +0 -131
- package/tests/yaml-autofix.sh +0 -146
- package/tsconfig.json +0 -50
- package/vite.config.ts +0 -256
package/examples/README.md
DELETED
|
@@ -1,208 +0,0 @@
|
|
|
1
|
-
# 📚 Better Logger Examples
|
|
2
|
-
|
|
3
|
-
This directory contains practical examples demonstrating various features of Better Logger.
|
|
4
|
-
|
|
5
|
-
## 🚀 Quick Start
|
|
6
|
-
|
|
7
|
-
```bash
|
|
8
|
-
# Install dependencies
|
|
9
|
-
cd examples
|
|
10
|
-
npm install
|
|
11
|
-
|
|
12
|
-
# Run all examples
|
|
13
|
-
npm run all
|
|
14
|
-
|
|
15
|
-
# Or run individual examples
|
|
16
|
-
npm run basic # Basic logging features
|
|
17
|
-
npm run performance # Performance timing
|
|
18
|
-
npm run styling # Themes and visual styling
|
|
19
|
-
npm run export # Data export and remote logging
|
|
20
|
-
```
|
|
21
|
-
|
|
22
|
-
## 📋 Available Examples
|
|
23
|
-
|
|
24
|
-
### 1. 🔤 Basic Logging (`basic-logging.js`)
|
|
25
|
-
|
|
26
|
-
Learn the fundamentals of logging with Better Logger:
|
|
27
|
-
|
|
28
|
-
- **Log Levels**: debug, info, warn, error, critical, success
|
|
29
|
-
- **Data Types**: Strings, numbers, booleans, arrays, objects, errors
|
|
30
|
-
- **Message Formatting**: Multiple arguments and structured data
|
|
31
|
-
- **Practical Usage**: Real-world logging scenarios
|
|
32
|
-
|
|
33
|
-
**Key Features Demonstrated:**
|
|
34
|
-
```javascript
|
|
35
|
-
logger.info('User login', { userId: 123, method: 'oauth' });
|
|
36
|
-
logger.error('Connection failed', error);
|
|
37
|
-
logger.success('Operation completed', { duration: '2.5s' });
|
|
38
|
-
```
|
|
39
|
-
|
|
40
|
-
**Run:** `npm run basic`
|
|
41
|
-
|
|
42
|
-
---
|
|
43
|
-
|
|
44
|
-
### 2. ⏱️ Performance Timing (`performance-timing.js`)
|
|
45
|
-
|
|
46
|
-
Master performance monitoring and timing operations:
|
|
47
|
-
|
|
48
|
-
- **Basic Timing**: `time()` and `timeEnd()` operations
|
|
49
|
-
- **Intermediate Timing**: `timeLog()` for step-by-step tracking
|
|
50
|
-
- **Concurrent Operations**: Multiple timers running simultaneously
|
|
51
|
-
- **Nested Timing**: Parent and child operation tracking
|
|
52
|
-
- **Performance Comparison**: Benchmarking different approaches
|
|
53
|
-
|
|
54
|
-
**Key Features Demonstrated:**
|
|
55
|
-
```javascript
|
|
56
|
-
logger.time('database-query');
|
|
57
|
-
const result = await executeQuery();
|
|
58
|
-
logger.timeLog('database-query', 'Query executed');
|
|
59
|
-
logger.timeEnd('database-query');
|
|
60
|
-
```
|
|
61
|
-
|
|
62
|
-
**Run:** `npm run performance`
|
|
63
|
-
|
|
64
|
-
---
|
|
65
|
-
|
|
66
|
-
### 3. 🎨 Styling & Themes (`styling-themes.js`)
|
|
67
|
-
|
|
68
|
-
Explore visual customization and theming capabilities:
|
|
69
|
-
|
|
70
|
-
- **Theme System**: 5 built-in themes (default, dark, neon, cyberpunk, retro)
|
|
71
|
-
- **Banner Types**: ASCII, Unicode, SVG, and animated banners
|
|
72
|
-
- **Custom Styles**: StyleBuilder API for creating unique appearances
|
|
73
|
-
- **Style Presets**: Ready-to-use styles for common scenarios
|
|
74
|
-
- **SVG Integration**: Custom graphics in console output (browser)
|
|
75
|
-
|
|
76
|
-
**Key Features Demonstrated:**
|
|
77
|
-
```javascript
|
|
78
|
-
setTheme('cyberpunk');
|
|
79
|
-
const customStyle = createStyle()
|
|
80
|
-
.bg('linear-gradient(45deg, #ff6b6b, #feca57)')
|
|
81
|
-
.color('white')
|
|
82
|
-
.padding('12px 24px')
|
|
83
|
-
.rounded('8px')
|
|
84
|
-
.build();
|
|
85
|
-
```
|
|
86
|
-
|
|
87
|
-
**Run:** `npm run styling`
|
|
88
|
-
|
|
89
|
-
**Note:** Best viewed in browser console for full visual effects.
|
|
90
|
-
|
|
91
|
-
---
|
|
92
|
-
|
|
93
|
-
### 4. 📤 Data Export & Remote (`data-export.js`)
|
|
94
|
-
|
|
95
|
-
Learn data management, export, and remote logging:
|
|
96
|
-
|
|
97
|
-
- **Log Buffering**: Circular buffer management with configurable size
|
|
98
|
-
- **Export Formats**: CSV, JSON, XML with filtering options
|
|
99
|
-
- **Remote Logging**: HTTP and WebSocket endpoint simulation
|
|
100
|
-
- **Analytics**: Log statistics and performance metrics
|
|
101
|
-
- **Filtering**: Advanced search and filtering capabilities
|
|
102
|
-
|
|
103
|
-
**Key Features Demonstrated:**
|
|
104
|
-
```javascript
|
|
105
|
-
const csvData = await logger.exportLogs('csv', {
|
|
106
|
-
filter: { level: 'error', from: yesterday },
|
|
107
|
-
limit: 100
|
|
108
|
-
});
|
|
109
|
-
|
|
110
|
-
logger.addRemoteHandler('https://api.logs.com', {
|
|
111
|
-
apiKey: 'secret-key',
|
|
112
|
-
batchSize: 10
|
|
113
|
-
});
|
|
114
|
-
```
|
|
115
|
-
|
|
116
|
-
**Run:** `npm run export`
|
|
117
|
-
|
|
118
|
-
**Output:** Creates `exports/` directory with sample export files.
|
|
119
|
-
|
|
120
|
-
---
|
|
121
|
-
|
|
122
|
-
## 🎯 Learning Path
|
|
123
|
-
|
|
124
|
-
### Beginner (Start Here)
|
|
125
|
-
1. **Basic Logging** - Learn core logging methods
|
|
126
|
-
2. **Performance Timing** - Add timing to your applications
|
|
127
|
-
|
|
128
|
-
### Intermediate
|
|
129
|
-
3. **Styling & Themes** - Customize visual appearance
|
|
130
|
-
4. **Data Export** - Implement log management
|
|
131
|
-
|
|
132
|
-
### Advanced
|
|
133
|
-
- Combine examples to create comprehensive logging solutions
|
|
134
|
-
- Explore the full [API Reference](../docs/API.md)
|
|
135
|
-
- Check out the [Interactive Demo](https://mks2508.github.io/advanced-logger/)
|
|
136
|
-
|
|
137
|
-
## 💡 Tips for Running Examples
|
|
138
|
-
|
|
139
|
-
### Node.js Environment
|
|
140
|
-
All examples work in Node.js, but some visual features are optimized for browsers:
|
|
141
|
-
|
|
142
|
-
```bash
|
|
143
|
-
# Works everywhere
|
|
144
|
-
npm run basic
|
|
145
|
-
npm run performance
|
|
146
|
-
npm run export
|
|
147
|
-
|
|
148
|
-
# Limited visual effects in Node.js
|
|
149
|
-
npm run styling
|
|
150
|
-
```
|
|
151
|
-
|
|
152
|
-
### Browser Environment
|
|
153
|
-
For full visual experience with styling and animations:
|
|
154
|
-
|
|
155
|
-
1. Import Better Logger in your browser console:
|
|
156
|
-
```javascript
|
|
157
|
-
// Using CDN
|
|
158
|
-
import('https://unpkg.com/@mks2508/better-logger@latest')
|
|
159
|
-
```
|
|
160
|
-
|
|
161
|
-
2. Copy and paste example code from `styling-themes.js`
|
|
162
|
-
|
|
163
|
-
### File Outputs
|
|
164
|
-
The `data-export.js` example creates files in the `exports/` directory:
|
|
165
|
-
|
|
166
|
-
```
|
|
167
|
-
exports/
|
|
168
|
-
├── logs-all.csv # All logs in CSV format
|
|
169
|
-
├── logs-errors.json # Error logs in JSON format
|
|
170
|
-
├── logs-recent.xml # Recent logs in XML format
|
|
171
|
-
└── logs-24h.json # Last 24 hours in JSON format
|
|
172
|
-
```
|
|
173
|
-
|
|
174
|
-
## 🔗 Related Resources
|
|
175
|
-
|
|
176
|
-
- 📚 [API Reference](../docs/API.md) - Complete method documentation
|
|
177
|
-
- 🎮 [Interactive Demo](https://mks2508.github.io/advanced-logger/) - Try features live
|
|
178
|
-
- 📦 [NPM Package](https://www.npmjs.com/package/@mks2508/better-logger) - Installation guide
|
|
179
|
-
- 🐛 [Issues & Support](https://github.com/MKS2508/advanced-logger/issues) - Get help
|
|
180
|
-
|
|
181
|
-
## 🤝 Contributing Examples
|
|
182
|
-
|
|
183
|
-
Have a useful logging pattern or use case? We'd love to see your examples!
|
|
184
|
-
|
|
185
|
-
1. Create a new `.js` file following the existing pattern
|
|
186
|
-
2. Add a script to `package.json`
|
|
187
|
-
3. Update this README with documentation
|
|
188
|
-
4. Submit a pull request
|
|
189
|
-
|
|
190
|
-
**Example Template:**
|
|
191
|
-
```javascript
|
|
192
|
-
/**
|
|
193
|
-
* [Feature Name] Example
|
|
194
|
-
*
|
|
195
|
-
* Demonstrates [specific capabilities] including:
|
|
196
|
-
* - Feature 1
|
|
197
|
-
* - Feature 2
|
|
198
|
-
* - Feature 3
|
|
199
|
-
*
|
|
200
|
-
* Run: node examples/your-example.js
|
|
201
|
-
*/
|
|
202
|
-
|
|
203
|
-
// Your example code here
|
|
204
|
-
```
|
|
205
|
-
|
|
206
|
-
---
|
|
207
|
-
|
|
208
|
-
Happy logging! 🎉
|
|
@@ -1,75 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Basic Logging Example
|
|
3
|
-
*
|
|
4
|
-
* Demonstrates fundamental logging capabilities including:
|
|
5
|
-
* - Different log levels (debug, info, warn, error, critical)
|
|
6
|
-
* - Message formatting with additional arguments
|
|
7
|
-
* - Success logging for positive outcomes
|
|
8
|
-
*
|
|
9
|
-
* Run: node examples/basic-logging.js
|
|
10
|
-
*/
|
|
11
|
-
|
|
12
|
-
import { Logger } from '@mks2508/better-logger';
|
|
13
|
-
|
|
14
|
-
console.log('🚀 Better Logger - Basic Logging Example\n');
|
|
15
|
-
|
|
16
|
-
// Create a new logger instance
|
|
17
|
-
const logger = new Logger({
|
|
18
|
-
prefix: 'BASIC',
|
|
19
|
-
level: 'debug' // Show all log levels
|
|
20
|
-
});
|
|
21
|
-
|
|
22
|
-
// Basic logging methods demonstration
|
|
23
|
-
console.log('📝 Testing different log levels:');
|
|
24
|
-
|
|
25
|
-
logger.debug('This is a debug message with data:', { debugInfo: true, value: 42 });
|
|
26
|
-
|
|
27
|
-
logger.info('Application started successfully', {
|
|
28
|
-
version: '1.0.0',
|
|
29
|
-
environment: 'development'
|
|
30
|
-
});
|
|
31
|
-
|
|
32
|
-
logger.warn('Memory usage is high', {
|
|
33
|
-
usage: '85%',
|
|
34
|
-
threshold: '80%',
|
|
35
|
-
recommendation: 'Consider optimizing memory usage'
|
|
36
|
-
});
|
|
37
|
-
|
|
38
|
-
logger.error('Failed to connect to database', {
|
|
39
|
-
host: 'localhost',
|
|
40
|
-
port: 5432,
|
|
41
|
-
error: 'ECONNREFUSED',
|
|
42
|
-
retryAttempt: 3
|
|
43
|
-
});
|
|
44
|
-
|
|
45
|
-
logger.critical('System is out of disk space', {
|
|
46
|
-
available: '100MB',
|
|
47
|
-
required: '2GB',
|
|
48
|
-
action: 'immediate_attention_required'
|
|
49
|
-
});
|
|
50
|
-
|
|
51
|
-
logger.success('User authentication completed', {
|
|
52
|
-
userId: 'user_123',
|
|
53
|
-
method: 'oauth2',
|
|
54
|
-
timestamp: new Date().toISOString()
|
|
55
|
-
});
|
|
56
|
-
|
|
57
|
-
// Demonstrate logging with different data types
|
|
58
|
-
console.log('\n📊 Testing different data types:');
|
|
59
|
-
|
|
60
|
-
logger.info('String message');
|
|
61
|
-
logger.info('Number value:', 42);
|
|
62
|
-
logger.info('Boolean value:', true);
|
|
63
|
-
logger.info('Array data:', [1, 2, 3, 'hello']);
|
|
64
|
-
logger.info('Object data:', { name: 'John', age: 30, active: true });
|
|
65
|
-
logger.info('Multiple arguments:', 'user', 'action', { result: 'success' }, 123);
|
|
66
|
-
|
|
67
|
-
// Error object logging
|
|
68
|
-
console.log('\n❌ Testing error object logging:');
|
|
69
|
-
try {
|
|
70
|
-
throw new Error('Something went wrong!');
|
|
71
|
-
} catch (error) {
|
|
72
|
-
logger.error('Caught an error:', error);
|
|
73
|
-
}
|
|
74
|
-
|
|
75
|
-
console.log('\n✅ Basic logging examples completed!');
|
package/examples/data-export.js
DELETED
|
@@ -1,234 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Data Export and Remote Logging Example
|
|
3
|
-
*
|
|
4
|
-
* Demonstrates export and remote logging capabilities including:
|
|
5
|
-
* - Log buffering and management
|
|
6
|
-
* - Exporting logs in different formats (CSV, JSON, XML)
|
|
7
|
-
* - Remote logging to external services
|
|
8
|
-
* - Log filtering and analytics
|
|
9
|
-
* - Buffer statistics and management
|
|
10
|
-
*
|
|
11
|
-
* Run: node examples/data-export.js
|
|
12
|
-
*/
|
|
13
|
-
|
|
14
|
-
import { ExportLogger } from '@mks2508/better-logger/exports';
|
|
15
|
-
import fs from 'fs';
|
|
16
|
-
import path from 'path';
|
|
17
|
-
|
|
18
|
-
console.log('📤 Better Logger - Data Export Example\n');
|
|
19
|
-
|
|
20
|
-
// Create ExportLogger with buffering enabled
|
|
21
|
-
const logger = new ExportLogger({
|
|
22
|
-
bufferSize: 100,
|
|
23
|
-
bufferMode: 'circular',
|
|
24
|
-
prefix: 'EXPORT'
|
|
25
|
-
});
|
|
26
|
-
|
|
27
|
-
// Generate sample log data
|
|
28
|
-
console.log('📝 Generating sample log data:');
|
|
29
|
-
|
|
30
|
-
const sampleData = [
|
|
31
|
-
{ level: 'info', message: 'User login successful', data: { userId: 'user_123', ip: '192.168.1.100' } },
|
|
32
|
-
{ level: 'warn', message: 'High memory usage detected', data: { usage: '85%', threshold: '80%' } },
|
|
33
|
-
{ level: 'error', message: 'Database connection timeout', data: { host: 'db.example.com', timeout: 5000 } },
|
|
34
|
-
{ level: 'info', message: 'API request processed', data: { endpoint: '/api/users', method: 'GET', duration: 245 } },
|
|
35
|
-
{ level: 'critical', message: 'Disk space critically low', data: { available: '100MB', required: '2GB' } },
|
|
36
|
-
{ level: 'success', message: 'Backup completed successfully', data: { size: '2.3GB', duration: '5 minutes' } },
|
|
37
|
-
{ level: 'debug', message: 'Debug trace for user session', data: { sessionId: 'sess_789', debug: true } },
|
|
38
|
-
{ level: 'error', message: 'Payment processing failed', data: { orderId: 'ORD-456', error: 'CARD_DECLINED' } },
|
|
39
|
-
{ level: 'info', message: 'Cache invalidation completed', data: { keys: ['user:123', 'session:789'], count: 2 } },
|
|
40
|
-
{ level: 'warn', message: 'Rate limit approaching', data: { current: 95, limit: 100, window: '1 minute' } }
|
|
41
|
-
];
|
|
42
|
-
|
|
43
|
-
// Log all sample data
|
|
44
|
-
sampleData.forEach((item, index) => {
|
|
45
|
-
const logMethod = logger[item.level] || logger.info;
|
|
46
|
-
logMethod.call(logger, `Sample ${index + 1}: ${item.message}`, item.data);
|
|
47
|
-
});
|
|
48
|
-
|
|
49
|
-
console.log(`\n📊 Generated ${sampleData.length} log entries`);
|
|
50
|
-
|
|
51
|
-
// Show buffer statistics
|
|
52
|
-
const bufferStats = logger.getBufferStats();
|
|
53
|
-
console.log('\n📈 Buffer Statistics:');
|
|
54
|
-
console.log(`- Total entries: ${bufferStats.totalEntries}`);
|
|
55
|
-
console.log(`- Buffer usage: ${bufferStats.usage}%`);
|
|
56
|
-
console.log(`- Oldest entry: ${bufferStats.oldestEntry?.timestamp || 'N/A'}`);
|
|
57
|
-
console.log(`- Newest entry: ${bufferStats.newestEntry?.timestamp || 'N/A'}`);
|
|
58
|
-
|
|
59
|
-
// Show log statistics by level
|
|
60
|
-
const logStats = logger.getLogStats();
|
|
61
|
-
console.log('\n📋 Log Level Statistics:');
|
|
62
|
-
Object.entries(logStats).forEach(([level, count]) => {
|
|
63
|
-
if (typeof count === 'number' && count > 0) {
|
|
64
|
-
console.log(`- ${level.toUpperCase()}: ${count} entries`);
|
|
65
|
-
}
|
|
66
|
-
});
|
|
67
|
-
|
|
68
|
-
// Export logs in different formats
|
|
69
|
-
console.log('\n📄 Exporting logs in different formats:');
|
|
70
|
-
|
|
71
|
-
try {
|
|
72
|
-
// Create exports directory if it doesn't exist
|
|
73
|
-
const exportsDir = path.join(process.cwd(), 'exports');
|
|
74
|
-
if (!fs.existsSync(exportsDir)) {
|
|
75
|
-
fs.mkdirSync(exportsDir, { recursive: true });
|
|
76
|
-
}
|
|
77
|
-
|
|
78
|
-
// Export all logs as CSV
|
|
79
|
-
console.log('🔄 Exporting as CSV...');
|
|
80
|
-
const csvData = await logger.exportLogs('csv');
|
|
81
|
-
fs.writeFileSync(path.join(exportsDir, 'logs-all.csv'), csvData);
|
|
82
|
-
console.log('✅ CSV export saved to: exports/logs-all.csv');
|
|
83
|
-
|
|
84
|
-
// Export error logs as JSON
|
|
85
|
-
console.log('🔄 Exporting errors as JSON...');
|
|
86
|
-
const jsonErrorData = await logger.exportLogs('json', {
|
|
87
|
-
filter: { level: ['error', 'critical'] },
|
|
88
|
-
includeStackTrace: true
|
|
89
|
-
});
|
|
90
|
-
fs.writeFileSync(path.join(exportsDir, 'logs-errors.json'), jsonErrorData);
|
|
91
|
-
console.log('✅ JSON export (errors only) saved to: exports/logs-errors.json');
|
|
92
|
-
|
|
93
|
-
// Export recent logs as XML
|
|
94
|
-
console.log('🔄 Exporting recent logs as XML...');
|
|
95
|
-
const xmlData = await logger.exportLogs('xml', {
|
|
96
|
-
limit: 5,
|
|
97
|
-
groupBy: 'level'
|
|
98
|
-
});
|
|
99
|
-
fs.writeFileSync(path.join(exportsDir, 'logs-recent.xml'), xmlData);
|
|
100
|
-
console.log('✅ XML export (recent 5) saved to: exports/logs-recent.xml');
|
|
101
|
-
|
|
102
|
-
// Export with date filtering
|
|
103
|
-
const oneDayAgo = new Date(Date.now() - 24 * 60 * 60 * 1000);
|
|
104
|
-
console.log('🔄 Exporting last 24 hours as JSON...');
|
|
105
|
-
const recentJsonData = await logger.exportLogs('json', {
|
|
106
|
-
filter: { from: oneDayAgo },
|
|
107
|
-
groupBy: 'level'
|
|
108
|
-
});
|
|
109
|
-
fs.writeFileSync(path.join(exportsDir, 'logs-24h.json'), recentJsonData);
|
|
110
|
-
console.log('✅ JSON export (24h) saved to: exports/logs-24h.json');
|
|
111
|
-
|
|
112
|
-
} catch (error) {
|
|
113
|
-
console.error('❌ Export error:', error.message);
|
|
114
|
-
}
|
|
115
|
-
|
|
116
|
-
// Demonstrate remote logging (simulation)
|
|
117
|
-
console.log('\n📡 Remote Logging Simulation:');
|
|
118
|
-
|
|
119
|
-
// Simulate HTTP endpoint
|
|
120
|
-
const simulateHttpEndpoint = (data) => {
|
|
121
|
-
console.log('📤 HTTP POST to https://api.logs.example.com/collect');
|
|
122
|
-
console.log(`📊 Payload size: ${JSON.stringify(data).length} bytes`);
|
|
123
|
-
console.log(`📋 Entries: ${data.length}`);
|
|
124
|
-
return Promise.resolve({ status: 200, message: 'Logs received' });
|
|
125
|
-
};
|
|
126
|
-
|
|
127
|
-
// Simulate WebSocket endpoint
|
|
128
|
-
const simulateWebSocketEndpoint = (data) => {
|
|
129
|
-
console.log('🔗 WebSocket send to wss://realtime.logs.example.com');
|
|
130
|
-
console.log(`📊 Message size: ${JSON.stringify(data).length} bytes`);
|
|
131
|
-
return Promise.resolve({ connected: true, delivered: true });
|
|
132
|
-
};
|
|
133
|
-
|
|
134
|
-
// Add remote handlers (simulation)
|
|
135
|
-
logger.addRemoteHandler('https://api.logs.example.com/collect', {
|
|
136
|
-
apiKey: 'demo-key-123',
|
|
137
|
-
handler: simulateHttpEndpoint,
|
|
138
|
-
retries: 3,
|
|
139
|
-
batchSize: 5
|
|
140
|
-
});
|
|
141
|
-
|
|
142
|
-
logger.addRemoteHandler('wss://realtime.logs.example.com', {
|
|
143
|
-
handler: simulateWebSocketEndpoint,
|
|
144
|
-
immediate: true,
|
|
145
|
-
filter: (entry) => ['error', 'critical'].includes(entry.level)
|
|
146
|
-
});
|
|
147
|
-
|
|
148
|
-
// Simulate sending logs to remote endpoints
|
|
149
|
-
console.log('🚀 Sending logs to remote endpoints...');
|
|
150
|
-
|
|
151
|
-
// Get logs for remote transmission
|
|
152
|
-
const logsForRemote = logger.getLogs({
|
|
153
|
-
limit: 3,
|
|
154
|
-
level: ['error', 'warn', 'critical']
|
|
155
|
-
});
|
|
156
|
-
|
|
157
|
-
console.log(`📨 Preparing to send ${logsForRemote.length} priority logs`);
|
|
158
|
-
|
|
159
|
-
// Simulate batch sending
|
|
160
|
-
for (let i = 0; i < logsForRemote.length; i += 2) {
|
|
161
|
-
const batch = logsForRemote.slice(i, i + 2);
|
|
162
|
-
|
|
163
|
-
console.log(`\n📦 Batch ${Math.floor(i/2) + 1}:`);
|
|
164
|
-
await simulateHttpEndpoint(batch);
|
|
165
|
-
|
|
166
|
-
// Simulate delay between batches
|
|
167
|
-
await new Promise(resolve => setTimeout(resolve, 100));
|
|
168
|
-
}
|
|
169
|
-
|
|
170
|
-
// Simulate real-time critical alerts
|
|
171
|
-
console.log('\n🚨 Simulating critical alert...');
|
|
172
|
-
logger.critical('System failure detected', {
|
|
173
|
-
service: 'payment-processor',
|
|
174
|
-
error: 'CONNECTION_LOST',
|
|
175
|
-
impact: 'high',
|
|
176
|
-
requiresImmediate: true
|
|
177
|
-
});
|
|
178
|
-
|
|
179
|
-
// Advanced analytics demonstration
|
|
180
|
-
console.log('\n📈 Advanced Analytics:');
|
|
181
|
-
|
|
182
|
-
const analytics = logger.getAnalytics({
|
|
183
|
-
timeframe: '1h',
|
|
184
|
-
groupBy: 'level',
|
|
185
|
-
includeMetrics: true
|
|
186
|
-
});
|
|
187
|
-
|
|
188
|
-
console.log('🔍 Analytics Summary:');
|
|
189
|
-
console.log(`- Total logs analyzed: ${analytics.summary.totalLogs}`);
|
|
190
|
-
console.log(`- Error rate: ${(analytics.summary.errorRate * 100).toFixed(2)}%`);
|
|
191
|
-
console.log(`- Average per hour: ${analytics.summary.averagePerHour}`);
|
|
192
|
-
|
|
193
|
-
console.log('\n📊 Level Distribution:');
|
|
194
|
-
Object.entries(analytics.distribution).forEach(([level, count]) => {
|
|
195
|
-
const percentage = ((count / analytics.summary.totalLogs) * 100).toFixed(1);
|
|
196
|
-
console.log(`- ${level.toUpperCase()}: ${count} (${percentage}%)`);
|
|
197
|
-
});
|
|
198
|
-
|
|
199
|
-
// Log search and filtering
|
|
200
|
-
console.log('\n🔍 Log Search and Filtering:');
|
|
201
|
-
|
|
202
|
-
// Search by content
|
|
203
|
-
const paymentLogs = logger.getLogs({
|
|
204
|
-
content: 'payment',
|
|
205
|
-
limit: 10
|
|
206
|
-
});
|
|
207
|
-
console.log(`Found ${paymentLogs.length} logs containing 'payment'`);
|
|
208
|
-
|
|
209
|
-
// Filter by level and prefix
|
|
210
|
-
const errorLogs = logger.getLogs({
|
|
211
|
-
level: ['error', 'critical'],
|
|
212
|
-
prefix: 'EXPORT'
|
|
213
|
-
});
|
|
214
|
-
console.log(`Found ${errorLogs.length} error/critical logs with EXPORT prefix`);
|
|
215
|
-
|
|
216
|
-
// Memory management
|
|
217
|
-
console.log('\n🧹 Buffer Management:');
|
|
218
|
-
console.log(`Current buffer size: ${logger.getBufferStats().totalEntries} entries`);
|
|
219
|
-
|
|
220
|
-
// Clear old logs (simulate retention policy)
|
|
221
|
-
const oneHourAgo = new Date(Date.now() - 60 * 60 * 1000);
|
|
222
|
-
const clearedCount = logger.clearLogs({
|
|
223
|
-
before: oneHourAgo,
|
|
224
|
-
level: 'debug' // Clear only debug logs older than 1 hour
|
|
225
|
-
});
|
|
226
|
-
console.log(`Cleared ${clearedCount} old debug logs`);
|
|
227
|
-
|
|
228
|
-
// Final buffer stats
|
|
229
|
-
const finalStats = logger.getBufferStats();
|
|
230
|
-
console.log(`Buffer after cleanup: ${finalStats.totalEntries} entries`);
|
|
231
|
-
|
|
232
|
-
console.log('\n✅ Data export and remote logging examples completed!');
|
|
233
|
-
console.log('📁 Check the exports/ directory for generated files');
|
|
234
|
-
console.log('🔍 Examine the exported files to see different format outputs');
|
package/examples/package.json
DELETED
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"name": "better-logger-examples",
|
|
3
|
-
"version": "1.0.0",
|
|
4
|
-
"description": "Examples for Better Logger package",
|
|
5
|
-
"type": "module",
|
|
6
|
-
"scripts": {
|
|
7
|
-
"basic": "node basic-logging.js",
|
|
8
|
-
"performance": "node performance-timing.js",
|
|
9
|
-
"styling": "node styling-themes.js",
|
|
10
|
-
"export": "node data-export.js",
|
|
11
|
-
"all": "npm run basic && npm run performance && npm run styling && npm run export"
|
|
12
|
-
},
|
|
13
|
-
"dependencies": {
|
|
14
|
-
"@mks2508/better-logger": "^0.0.2-alpha.2"
|
|
15
|
-
}
|
|
16
|
-
}
|
|
@@ -1,170 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Performance Timing Example
|
|
3
|
-
*
|
|
4
|
-
* Demonstrates performance monitoring capabilities including:
|
|
5
|
-
* - Basic timing operations with time() and timeEnd()
|
|
6
|
-
* - Intermediate timing with timeLog()
|
|
7
|
-
* - Nested timing operations
|
|
8
|
-
* - Performance comparison between operations
|
|
9
|
-
*
|
|
10
|
-
* Run: node examples/performance-timing.js
|
|
11
|
-
*/
|
|
12
|
-
|
|
13
|
-
import { Logger } from '@mks2508/better-logger';
|
|
14
|
-
|
|
15
|
-
console.log('⏱️ Better Logger - Performance Timing Example\n');
|
|
16
|
-
|
|
17
|
-
// Create logger with performance tracking enabled
|
|
18
|
-
const logger = new Logger({
|
|
19
|
-
prefix: 'PERF',
|
|
20
|
-
enablePerformance: true
|
|
21
|
-
});
|
|
22
|
-
|
|
23
|
-
// Simulate async operations
|
|
24
|
-
const simulateWork = (ms) => new Promise(resolve => setTimeout(resolve, ms));
|
|
25
|
-
const simulateHeavyWork = (ms) => {
|
|
26
|
-
const start = Date.now();
|
|
27
|
-
while (Date.now() - start < ms) {
|
|
28
|
-
// CPU intensive work
|
|
29
|
-
Math.random();
|
|
30
|
-
}
|
|
31
|
-
};
|
|
32
|
-
|
|
33
|
-
// Basic timing example
|
|
34
|
-
console.log('🔄 Basic timing operations:');
|
|
35
|
-
|
|
36
|
-
logger.time('basic-operation');
|
|
37
|
-
await simulateWork(100);
|
|
38
|
-
logger.timeEnd('basic-operation');
|
|
39
|
-
|
|
40
|
-
// Multiple timers running simultaneously
|
|
41
|
-
console.log('\n⚡ Concurrent operations:');
|
|
42
|
-
|
|
43
|
-
logger.time('operation-1');
|
|
44
|
-
logger.time('operation-2');
|
|
45
|
-
logger.time('operation-3');
|
|
46
|
-
|
|
47
|
-
await simulateWork(80);
|
|
48
|
-
logger.timeEnd('operation-1');
|
|
49
|
-
|
|
50
|
-
await simulateWork(50);
|
|
51
|
-
logger.timeEnd('operation-2');
|
|
52
|
-
|
|
53
|
-
await simulateWork(120);
|
|
54
|
-
logger.timeEnd('operation-3');
|
|
55
|
-
|
|
56
|
-
// Intermediate timing with timeLog
|
|
57
|
-
console.log('\n📊 Step-by-step timing:');
|
|
58
|
-
|
|
59
|
-
logger.time('multi-step-process');
|
|
60
|
-
|
|
61
|
-
logger.info('Starting data processing...');
|
|
62
|
-
await simulateWork(50);
|
|
63
|
-
logger.timeLog('multi-step-process', 'Step 1: Data validation complete');
|
|
64
|
-
|
|
65
|
-
logger.info('Processing records...');
|
|
66
|
-
await simulateWork(80);
|
|
67
|
-
logger.timeLog('multi-step-process', 'Step 2: Record processing complete');
|
|
68
|
-
|
|
69
|
-
logger.info('Generating reports...');
|
|
70
|
-
await simulateWork(60);
|
|
71
|
-
logger.timeLog('multi-step-process', 'Step 3: Report generation complete');
|
|
72
|
-
|
|
73
|
-
logger.info('Sending notifications...');
|
|
74
|
-
await simulateWork(30);
|
|
75
|
-
logger.timeEnd('multi-step-process');
|
|
76
|
-
|
|
77
|
-
// Nested timing operations
|
|
78
|
-
console.log('\n🔗 Nested timing operations:');
|
|
79
|
-
|
|
80
|
-
logger.time('parent-operation');
|
|
81
|
-
|
|
82
|
-
logger.info('Starting parent operation');
|
|
83
|
-
|
|
84
|
-
logger.time('child-operation-1');
|
|
85
|
-
await simulateWork(40);
|
|
86
|
-
logger.timeEnd('child-operation-1');
|
|
87
|
-
|
|
88
|
-
logger.time('child-operation-2');
|
|
89
|
-
await simulateWork(60);
|
|
90
|
-
logger.timeEnd('child-operation-2');
|
|
91
|
-
|
|
92
|
-
logger.time('child-operation-3');
|
|
93
|
-
await simulateWork(35);
|
|
94
|
-
logger.timeEnd('child-operation-3');
|
|
95
|
-
|
|
96
|
-
logger.timeEnd('parent-operation');
|
|
97
|
-
|
|
98
|
-
// Performance comparison
|
|
99
|
-
console.log('\n🏃 Performance comparison:');
|
|
100
|
-
|
|
101
|
-
// Method A: Array.push in loop
|
|
102
|
-
logger.time('method-a-push');
|
|
103
|
-
const arrayA = [];
|
|
104
|
-
for (let i = 0; i < 10000; i++) {
|
|
105
|
-
arrayA.push(i);
|
|
106
|
-
}
|
|
107
|
-
logger.timeEnd('method-a-push');
|
|
108
|
-
|
|
109
|
-
// Method B: Array.from
|
|
110
|
-
logger.time('method-b-from');
|
|
111
|
-
const arrayB = Array.from({ length: 10000 }, (_, i) => i);
|
|
112
|
-
logger.timeEnd('method-b-from');
|
|
113
|
-
|
|
114
|
-
// Method C: Spread operator
|
|
115
|
-
logger.time('method-c-spread');
|
|
116
|
-
const arrayC = [...Array(10000).keys()];
|
|
117
|
-
logger.timeEnd('method-c-spread');
|
|
118
|
-
|
|
119
|
-
// CPU vs I/O comparison
|
|
120
|
-
console.log('\n🖥️ CPU vs I/O operations:');
|
|
121
|
-
|
|
122
|
-
logger.time('cpu-intensive');
|
|
123
|
-
simulateHeavyWork(50); // Synchronous CPU work
|
|
124
|
-
logger.timeEnd('cpu-intensive');
|
|
125
|
-
|
|
126
|
-
logger.time('io-simulation');
|
|
127
|
-
await simulateWork(50); // Asynchronous I/O simulation
|
|
128
|
-
logger.timeEnd('io-simulation');
|
|
129
|
-
|
|
130
|
-
// Real-world scenario: Database simulation
|
|
131
|
-
console.log('\n🗄️ Database operation simulation:');
|
|
132
|
-
|
|
133
|
-
const simulateDatabaseQuery = async (query, delay) => {
|
|
134
|
-
const timerId = `db-query-${Math.random().toString(36).substr(2, 9)}`;
|
|
135
|
-
|
|
136
|
-
logger.time(timerId);
|
|
137
|
-
logger.info(`Executing query: ${query}`);
|
|
138
|
-
|
|
139
|
-
// Simulate network delay
|
|
140
|
-
await simulateWork(delay);
|
|
141
|
-
|
|
142
|
-
logger.timeEnd(timerId);
|
|
143
|
-
|
|
144
|
-
return { query, rows: Math.floor(Math.random() * 1000) };
|
|
145
|
-
};
|
|
146
|
-
|
|
147
|
-
// Simulate multiple database operations
|
|
148
|
-
const queries = [
|
|
149
|
-
{ query: 'SELECT * FROM users WHERE active = true', delay: 45 },
|
|
150
|
-
{ query: 'SELECT COUNT(*) FROM orders WHERE date > NOW() - INTERVAL 30 DAY', delay: 120 },
|
|
151
|
-
{ query: 'UPDATE users SET last_login = NOW() WHERE id = ?', delay: 25 },
|
|
152
|
-
{ query: 'INSERT INTO audit_log (action, user_id, timestamp) VALUES (?, ?, ?)', delay: 15 }
|
|
153
|
-
];
|
|
154
|
-
|
|
155
|
-
logger.time('batch-database-operations');
|
|
156
|
-
|
|
157
|
-
for (const { query, delay } of queries) {
|
|
158
|
-
const result = await simulateDatabaseQuery(query, delay);
|
|
159
|
-
logger.info(`Query result: ${result.rows} rows affected`);
|
|
160
|
-
}
|
|
161
|
-
|
|
162
|
-
logger.timeEnd('batch-database-operations');
|
|
163
|
-
|
|
164
|
-
console.log('\n✅ Performance timing examples completed!');
|
|
165
|
-
|
|
166
|
-
// Final timing statistics
|
|
167
|
-
console.log('\n📈 Timing Statistics Summary:');
|
|
168
|
-
logger.info('All timing operations have been logged above');
|
|
169
|
-
logger.info('Each timer shows the exact duration in milliseconds');
|
|
170
|
-
logger.info('Use these techniques to identify performance bottlenecks in your applications');
|