@crimsonsunset/jsg-logger 1.0.8
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/CHANGELOG.md +55 -0
- package/CONTRIBUTING.md +58 -0
- package/LICENSE +15 -0
- package/README.md +428 -0
- package/config/component-schemes.js +26 -0
- package/config/config-manager.js +378 -0
- package/config/default-config.json +92 -0
- package/docs/next-session.md +136 -0
- package/docs/roadmap.md +404 -0
- package/examples/advanced-config.json +151 -0
- package/formatters/browser-formatter.js +227 -0
- package/formatters/cli-formatter.js +43 -0
- package/formatters/server-formatter.js +42 -0
- package/index.js +413 -0
- package/package.json +74 -0
- package/stores/log-store.js +148 -0
- package/utils/environment-detector.js +38 -0
package/CHANGELOG.md
ADDED
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
# Changelog
|
|
2
|
+
|
|
3
|
+
All notable changes to the JSG Logger project will be documented in this file.
|
|
4
|
+
|
|
5
|
+
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
|
|
6
|
+
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
|
|
7
|
+
|
|
8
|
+
## [Unreleased]
|
|
9
|
+
|
|
10
|
+
### Added
|
|
11
|
+
- None
|
|
12
|
+
|
|
13
|
+
### Changed
|
|
14
|
+
- None
|
|
15
|
+
|
|
16
|
+
### Fixed
|
|
17
|
+
- None
|
|
18
|
+
|
|
19
|
+
## [1.0.8] - 2025-08-06
|
|
20
|
+
|
|
21
|
+
### Changed
|
|
22
|
+
- **Package Name** - Changed from `@crimsonsunset/smart-logger` to `@crimsonsunset/jsg-logger`
|
|
23
|
+
- **Project Branding** - Updated all documentation and references from "Smart Logger" to "JSG Logger"
|
|
24
|
+
- **Package Description** - Updated to reflect JSG Logger branding
|
|
25
|
+
|
|
26
|
+
## [1.0.6] - 2025-08-06
|
|
27
|
+
|
|
28
|
+
### Added
|
|
29
|
+
- **Publishing Scripts** - Automated npm publishing with `npm run release`
|
|
30
|
+
- **Documentation Structure** - Added LICENSE, CHANGELOG, CONTRIBUTING, and docs/ folder
|
|
31
|
+
|
|
32
|
+
### Changed
|
|
33
|
+
- Package scripts for easier version management and publishing
|
|
34
|
+
|
|
35
|
+
### Fixed
|
|
36
|
+
- Internal import paths for config and formatter modules
|
|
37
|
+
|
|
38
|
+
## [1.0.0] - 1.0.6 - 2025-08-06
|
|
39
|
+
|
|
40
|
+
### Added
|
|
41
|
+
- **Multi-Environment Logger** - Smart detection of browser, CLI, and server environments
|
|
42
|
+
- **Direct Browser Logger** - 100% console control bypassing Pino for perfect formatting
|
|
43
|
+
- **Component Organization** - Separate loggers for different system components
|
|
44
|
+
- **File-Level Overrides** - Granular control with glob pattern support
|
|
45
|
+
- **Runtime Controls** - Complete API for dynamic configuration changes
|
|
46
|
+
- **Beautiful Formatting** - Emojis, colors, and structured context display
|
|
47
|
+
- **Log Store** - In-memory storage for debugging and popup interfaces
|
|
48
|
+
- **Timestamp Modes** - Absolute, readable, relative, or disabled options
|
|
49
|
+
- **External Configuration** - JSON-based configuration system
|
|
50
|
+
- **Smart Level Resolution** - Hierarchical level determination (file > component > global)
|
|
51
|
+
|
|
52
|
+
### Technical Details
|
|
53
|
+
- **Environment Detection** - Automatic browser/CLI/server environment recognition
|
|
54
|
+
- **ISC License** - "AS IS" disclaimer for liability protection
|
|
55
|
+
- **NPM Package** - Published as `@crimsonsunset/jsg-logger`
|
package/CONTRIBUTING.md
ADDED
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
# Contributing to JSG Logger
|
|
2
|
+
|
|
3
|
+
## ๐ฏ Current Status
|
|
4
|
+
|
|
5
|
+
**This is a personal utility project that has been extracted and published for reuse.**
|
|
6
|
+
|
|
7
|
+
Contributions are welcome, but please note:
|
|
8
|
+
- This project emerged from a specific use case (Chrome Audio Control Platform)
|
|
9
|
+
- The core functionality is stable and feature-complete for most use cases
|
|
10
|
+
- Major architectural changes should be discussed in an issue first
|
|
11
|
+
|
|
12
|
+
## ๐ How to Contribute
|
|
13
|
+
|
|
14
|
+
### Issues
|
|
15
|
+
- **Bug Reports**: Clearly describe the issue with environment details and reproduction steps
|
|
16
|
+
- **Feature Requests**: Explain the use case and why it would benefit the broader community
|
|
17
|
+
- **Questions**: Feel free to ask about usage or implementation details
|
|
18
|
+
|
|
19
|
+
### Pull Requests
|
|
20
|
+
- **Small Fixes**: Documentation, typos, minor bugs - submit directly
|
|
21
|
+
- **New Features**: Open an issue first to discuss the approach
|
|
22
|
+
- **Breaking Changes**: Require significant discussion and justification
|
|
23
|
+
|
|
24
|
+
## ๐ ๏ธ Development Setup
|
|
25
|
+
|
|
26
|
+
```bash
|
|
27
|
+
# Clone the repository
|
|
28
|
+
git clone https://github.com/crimsonsunset/jsg-logger.git
|
|
29
|
+
cd jsg-logger
|
|
30
|
+
|
|
31
|
+
# Install dependencies
|
|
32
|
+
npm install
|
|
33
|
+
|
|
34
|
+
# Test your changes
|
|
35
|
+
npm run check
|
|
36
|
+
```
|
|
37
|
+
|
|
38
|
+
## ๐ Code Style
|
|
39
|
+
|
|
40
|
+
- **ES Modules**: Use import/export syntax
|
|
41
|
+
- **JSDoc**: Document all functions
|
|
42
|
+
- **Descriptive Names**: Clear variable and function names
|
|
43
|
+
- **Early Returns**: Prefer early returns for readability
|
|
44
|
+
|
|
45
|
+
## ๐ Release Process
|
|
46
|
+
|
|
47
|
+
Maintainer-only process:
|
|
48
|
+
```bash
|
|
49
|
+
npm run release # Patch version (1.0.x)
|
|
50
|
+
npm run release:minor # Minor version (1.x.0)
|
|
51
|
+
npm run release:major # Major version (x.0.0)
|
|
52
|
+
```
|
|
53
|
+
|
|
54
|
+
## โ ๏ธ Legal
|
|
55
|
+
|
|
56
|
+
By contributing, you agree that your contributions will be licensed under the ISC License.
|
|
57
|
+
|
|
58
|
+
All contributions are provided "AS IS" without warranty, consistent with the project license.
|
package/LICENSE
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
ISC License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2025 Joe Sangiorgio
|
|
4
|
+
|
|
5
|
+
Permission to use, copy, modify, and/or distribute this software for any
|
|
6
|
+
purpose with or without fee is hereby granted, provided that the above
|
|
7
|
+
copyright notice and this permission notice appear in all copies.
|
|
8
|
+
|
|
9
|
+
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
|
|
10
|
+
WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
|
|
11
|
+
MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
|
|
12
|
+
ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
|
13
|
+
WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
|
|
14
|
+
ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
|
|
15
|
+
OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,428 @@
|
|
|
1
|
+
# JSG Logger
|
|
2
|
+
|
|
3
|
+
**Intelligent Multi-Environment Logger with Advanced Configuration**
|
|
4
|
+
|
|
5
|
+
A sophisticated logging system that automatically detects its environment (browser, CLI, server) and provides optimal logging experience for each, with powerful file-level overrides and granular control.
|
|
6
|
+
|
|
7
|
+
## โจ Features
|
|
8
|
+
|
|
9
|
+
- ๐ง **Smart Environment Detection** - Auto-adapts to browser, CLI, or server
|
|
10
|
+
- ๐จ **Beautiful Visual Output** - Emoji, colors, and structured context display
|
|
11
|
+
- ๐ฑ **Multi-Environment** - Browser console, terminal, and production JSON
|
|
12
|
+
- ๐ช **Log Store** - In-memory storage for debugging and popup interfaces
|
|
13
|
+
- โ๏ธ **Runtime Controls** - Dynamic log level adjustment and configuration
|
|
14
|
+
- ๐ **Component Organization** - Separate loggers for different system components
|
|
15
|
+
- ๐ง **External Configuration** - JSON-based configuration system
|
|
16
|
+
- ๐ **File-Level Overrides** - Per-file and pattern-based control
|
|
17
|
+
- โฐ **Timestamp Modes** - Absolute, readable, relative, or disabled
|
|
18
|
+
- ๐๏ธ **Display Toggles** - Control every aspect of log output
|
|
19
|
+
- ๐ฏ **Smart Level Resolution** - Hierarchical level determination
|
|
20
|
+
|
|
21
|
+
## ๐ Quick Start
|
|
22
|
+
|
|
23
|
+
```javascript
|
|
24
|
+
import logger from '@crimsonsunset/jsg-logger';
|
|
25
|
+
|
|
26
|
+
// Use component-specific loggers with smart level resolution
|
|
27
|
+
const log = logger.api;
|
|
28
|
+
log.info('API handler initialized', {
|
|
29
|
+
endpoint: 'https://api.example.com',
|
|
30
|
+
isReady: true
|
|
31
|
+
});
|
|
32
|
+
|
|
33
|
+
// Runtime controls
|
|
34
|
+
logger.controls.enableDebugMode(); // Enable debug for all components
|
|
35
|
+
logger.controls.setLevel('websocket', 'trace'); // Set specific component level
|
|
36
|
+
logger.controls.addFileOverride('src/popup.js', { level: 'trace' }); // File-specific control
|
|
37
|
+
```
|
|
38
|
+
|
|
39
|
+
## ๐ฏ **Level Resolution Hierarchy**
|
|
40
|
+
|
|
41
|
+
The logger uses intelligent level resolution with the following priority:
|
|
42
|
+
|
|
43
|
+
1. **File Override** - `fileOverrides["src/popup.js"].level`
|
|
44
|
+
2. **Component Level** - `components["websocket"].level`
|
|
45
|
+
3. **Global Level** - `globalLevel`
|
|
46
|
+
|
|
47
|
+
This allows surgical debugging - you can turn on trace logging for just one problematic file while keeping everything else quiet.
|
|
48
|
+
|
|
49
|
+
## โ๏ธ **Advanced Configuration**
|
|
50
|
+
|
|
51
|
+
### **Full Configuration Example**
|
|
52
|
+
|
|
53
|
+
```json
|
|
54
|
+
{
|
|
55
|
+
"projectName": "My Advanced Project",
|
|
56
|
+
"globalLevel": "info",
|
|
57
|
+
"timestampMode": "absolute",
|
|
58
|
+
"display": {
|
|
59
|
+
"timestamp": true,
|
|
60
|
+
"emoji": true,
|
|
61
|
+
"component": true,
|
|
62
|
+
"level": false,
|
|
63
|
+
"message": true,
|
|
64
|
+
"jsonPayload": true,
|
|
65
|
+
"stackTrace": true
|
|
66
|
+
},
|
|
67
|
+
"components": {
|
|
68
|
+
"api": {
|
|
69
|
+
"emoji": "๐",
|
|
70
|
+
"color": "#4A90E2",
|
|
71
|
+
"name": "API",
|
|
72
|
+
"level": "debug"
|
|
73
|
+
},
|
|
74
|
+
"database": {
|
|
75
|
+
"emoji": "๐พ",
|
|
76
|
+
"color": "#00C896",
|
|
77
|
+
"name": "Database",
|
|
78
|
+
"level": "warn"
|
|
79
|
+
}
|
|
80
|
+
},
|
|
81
|
+
"fileOverrides": {
|
|
82
|
+
"src/auth/login.js": {
|
|
83
|
+
"level": "trace",
|
|
84
|
+
"emoji": "๐",
|
|
85
|
+
"display": {
|
|
86
|
+
"level": true,
|
|
87
|
+
"jsonPayload": true
|
|
88
|
+
}
|
|
89
|
+
},
|
|
90
|
+
"src/managers/*.js": {
|
|
91
|
+
"level": "warn",
|
|
92
|
+
"display": {
|
|
93
|
+
"jsonPayload": false
|
|
94
|
+
}
|
|
95
|
+
},
|
|
96
|
+
"src/popup.js": {
|
|
97
|
+
"level": "debug",
|
|
98
|
+
"timestampMode": "relative",
|
|
99
|
+
"display": {
|
|
100
|
+
"jsonPayload": false
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
```
|
|
106
|
+
|
|
107
|
+
### **File Override Patterns**
|
|
108
|
+
|
|
109
|
+
File overrides support powerful pattern matching:
|
|
110
|
+
|
|
111
|
+
- **Exact files**: `"src/popup.js"`
|
|
112
|
+
- **Wildcards**: `"src/managers/*.js"`
|
|
113
|
+
- **Patterns**: `"src/test-*.js"`
|
|
114
|
+
- **Directories**: `"src/sites/*.js"`
|
|
115
|
+
|
|
116
|
+
Each override can specify:
|
|
117
|
+
- `level` - Log level for this file/pattern
|
|
118
|
+
- `emoji` - Custom emoji override
|
|
119
|
+
- `timestampMode` - File-specific timestamp mode
|
|
120
|
+
- `display` - Individual display toggles
|
|
121
|
+
|
|
122
|
+
## โฐ **Timestamp Modes**
|
|
123
|
+
|
|
124
|
+
Control how timestamps are displayed:
|
|
125
|
+
|
|
126
|
+
- **`absolute`** - `22:15:30.123` (default)
|
|
127
|
+
- **`readable`** - `10:15 PM`
|
|
128
|
+
- **`relative`** - `2s ago`, `5m ago`
|
|
129
|
+
- **`disable`** - No timestamp
|
|
130
|
+
|
|
131
|
+
```javascript
|
|
132
|
+
// Set globally
|
|
133
|
+
logger.controls.setTimestampMode('relative');
|
|
134
|
+
|
|
135
|
+
// Or per-file in config
|
|
136
|
+
"fileOverrides": {
|
|
137
|
+
"src/popup.js": { "timestampMode": "relative" }
|
|
138
|
+
}
|
|
139
|
+
```
|
|
140
|
+
|
|
141
|
+
## ๐๏ธ **Display Controls**
|
|
142
|
+
|
|
143
|
+
Toggle individual parts of log output:
|
|
144
|
+
|
|
145
|
+
```javascript
|
|
146
|
+
// Available display options
|
|
147
|
+
const displayConfig = {
|
|
148
|
+
timestamp: true, // Show/hide timestamp
|
|
149
|
+
emoji: true, // Show/hide level emoji
|
|
150
|
+
component: true, // Show/hide [COMPONENT-NAME]
|
|
151
|
+
level: false, // Show/hide level name (DEBUG, INFO, etc.)
|
|
152
|
+
message: true, // Show/hide log message
|
|
153
|
+
jsonPayload: true, // Show/hide context data trees
|
|
154
|
+
stackTrace: true // Show/hide error stack traces
|
|
155
|
+
};
|
|
156
|
+
|
|
157
|
+
// Runtime control
|
|
158
|
+
logger.controls.setDisplayOption('jsonPayload', false);
|
|
159
|
+
logger.controls.toggleDisplayOption('level');
|
|
160
|
+
```
|
|
161
|
+
|
|
162
|
+
## ๐๏ธ Architecture
|
|
163
|
+
|
|
164
|
+
```
|
|
165
|
+
logger/
|
|
166
|
+
โโโ index.js # Main entry point with smart initialization
|
|
167
|
+
โโโ config/
|
|
168
|
+
โ โโโ config-manager.js # Smart configuration system
|
|
169
|
+
โ โโโ default-config.json # Default configuration
|
|
170
|
+
โ โโโ component-schemes.js # Component styling definitions
|
|
171
|
+
โโโ formatters/
|
|
172
|
+
โ โโโ browser-formatter.js # Advanced browser console output
|
|
173
|
+
โ โโโ cli-formatter.js # Terminal output with pino-colada
|
|
174
|
+
โ โโโ server-formatter.js # Production JSON logging
|
|
175
|
+
โโโ stores/
|
|
176
|
+
โ โโโ log-store.js # In-memory log storage with filtering
|
|
177
|
+
โโโ utils/
|
|
178
|
+
โ โโโ environment-detector.js # Environment detection
|
|
179
|
+
โโโ examples/
|
|
180
|
+
โโโ advanced-config.json # Full configuration example
|
|
181
|
+
```
|
|
182
|
+
|
|
183
|
+
## ๐ฏ **Usage Examples**
|
|
184
|
+
|
|
185
|
+
### **Per-Component Level Control**
|
|
186
|
+
```javascript
|
|
187
|
+
// Different components at different levels
|
|
188
|
+
logger.controls.setComponentLevel('websocket', 'warn'); // Quiet websocket
|
|
189
|
+
logger.controls.setComponentLevel('soundcloud', 'trace'); // Verbose SoundCloud
|
|
190
|
+
logger.controls.setComponentLevel('popup', 'debug'); // Debug popup
|
|
191
|
+
```
|
|
192
|
+
|
|
193
|
+
### **Surgical File Debugging**
|
|
194
|
+
```javascript
|
|
195
|
+
// Turn on trace logging for just one problematic file
|
|
196
|
+
logger.controls.addFileOverride('src/sites/soundcloud.js', {
|
|
197
|
+
level: 'trace',
|
|
198
|
+
display: { level: true, jsonPayload: true }
|
|
199
|
+
});
|
|
200
|
+
|
|
201
|
+
// Quiet all manager files
|
|
202
|
+
logger.controls.addFileOverride('src/managers/*.js', {
|
|
203
|
+
level: 'warn',
|
|
204
|
+
display: { jsonPayload: false }
|
|
205
|
+
});
|
|
206
|
+
```
|
|
207
|
+
|
|
208
|
+
### **Dynamic Display Control**
|
|
209
|
+
```javascript
|
|
210
|
+
// Hide JSON payloads but keep error stacks
|
|
211
|
+
logger.controls.setDisplayOption('jsonPayload', false);
|
|
212
|
+
logger.controls.setDisplayOption('stackTrace', true);
|
|
213
|
+
|
|
214
|
+
// Show level names for debugging
|
|
215
|
+
logger.controls.setDisplayOption('level', true);
|
|
216
|
+
|
|
217
|
+
// Use relative timestamps for popup
|
|
218
|
+
logger.controls.addFileOverride('src/popup.js', {
|
|
219
|
+
timestampMode: 'relative'
|
|
220
|
+
});
|
|
221
|
+
```
|
|
222
|
+
|
|
223
|
+
### **Context Data**
|
|
224
|
+
```javascript
|
|
225
|
+
logger.api.error('Request failed', {
|
|
226
|
+
url: window.location.href,
|
|
227
|
+
selectors: {
|
|
228
|
+
title: '.track-title',
|
|
229
|
+
artist: '.track-artist'
|
|
230
|
+
},
|
|
231
|
+
retryCount: 3,
|
|
232
|
+
lastError: error.message,
|
|
233
|
+
userAgent: navigator.userAgent
|
|
234
|
+
});
|
|
235
|
+
|
|
236
|
+
// With file override for src/sites/soundcloud.js level: "trace":
|
|
237
|
+
// 22:15:30.123 ๐จ [API] Request failed
|
|
238
|
+
// โโ url: https://soundcloud.com/track/example
|
|
239
|
+
// โโ selectors: {title: ".track-title", artist: ".track-artist"}
|
|
240
|
+
// โโ retryCount: 3
|
|
241
|
+
// โโ lastError: "Element not found"
|
|
242
|
+
// โโ userAgent: "Mozilla/5.0..."
|
|
243
|
+
```
|
|
244
|
+
|
|
245
|
+
## ๐๏ธ **Runtime Controls API**
|
|
246
|
+
|
|
247
|
+
### **Level Controls**
|
|
248
|
+
```javascript
|
|
249
|
+
logger.controls.setLevel(component, level) // Set component level
|
|
250
|
+
logger.controls.getLevel(component) // Get effective level
|
|
251
|
+
logger.controls.setComponentLevel(component, level) // Set in config
|
|
252
|
+
logger.controls.enableDebugMode() // All components โ debug
|
|
253
|
+
logger.controls.enableTraceMode() // All components โ trace
|
|
254
|
+
```
|
|
255
|
+
|
|
256
|
+
### **File Override Controls**
|
|
257
|
+
```javascript
|
|
258
|
+
logger.controls.addFileOverride(path, config) // Add file override
|
|
259
|
+
logger.controls.removeFileOverride(path) // Remove override
|
|
260
|
+
logger.controls.listFileOverrides() // List all overrides
|
|
261
|
+
```
|
|
262
|
+
|
|
263
|
+
### **Display Controls**
|
|
264
|
+
```javascript
|
|
265
|
+
logger.controls.setDisplayOption(option, enabled) // Set display option
|
|
266
|
+
logger.controls.getDisplayConfig() // Get current config
|
|
267
|
+
logger.controls.toggleDisplayOption(option) // Toggle option
|
|
268
|
+
```
|
|
269
|
+
|
|
270
|
+
### **Timestamp Controls**
|
|
271
|
+
```javascript
|
|
272
|
+
logger.controls.setTimestampMode(mode) // Set timestamp mode
|
|
273
|
+
logger.controls.getTimestampMode() // Get current mode
|
|
274
|
+
logger.controls.getTimestampModes() // List available modes
|
|
275
|
+
```
|
|
276
|
+
|
|
277
|
+
### **System Controls**
|
|
278
|
+
```javascript
|
|
279
|
+
logger.controls.refresh() // Refresh all loggers
|
|
280
|
+
logger.controls.reset() // Reset to defaults
|
|
281
|
+
logger.controls.getConfigSummary() // Get config summary
|
|
282
|
+
logger.controls.getStats() // Get logging stats
|
|
283
|
+
```
|
|
284
|
+
|
|
285
|
+
## ๐ **Log Store & Statistics**
|
|
286
|
+
|
|
287
|
+
### **Advanced Log Filtering**
|
|
288
|
+
```javascript
|
|
289
|
+
// Get recent logs with file context
|
|
290
|
+
const recentLogs = logger.logStore.getRecent(20);
|
|
291
|
+
const websocketLogs = logger.logStore.getByComponent('websocket', 10);
|
|
292
|
+
const errorLogs = logger.logStore.getByLevel(50, 5); // Errors only
|
|
293
|
+
|
|
294
|
+
// Enhanced log entries include:
|
|
295
|
+
// - filePath: 'src/sites/soundcloud.js'
|
|
296
|
+
// - effectiveLevel: 'trace'
|
|
297
|
+
// - component: 'soundcloud'
|
|
298
|
+
// - displayConfig: { timestamp: true, ... }
|
|
299
|
+
```
|
|
300
|
+
|
|
301
|
+
### **Real-time Statistics**
|
|
302
|
+
```javascript
|
|
303
|
+
const stats = logger.controls.getStats();
|
|
304
|
+
// Returns:
|
|
305
|
+
// {
|
|
306
|
+
// total: 156,
|
|
307
|
+
// byLevel: { debug: 45, info: 89, warn: 15, error: 7 },
|
|
308
|
+
// byComponent: { soundcloud: 67, websocket: 23, popup: 66 },
|
|
309
|
+
// timeRange: { start: 1627846260000, end: 1627846320000 }
|
|
310
|
+
// }
|
|
311
|
+
```
|
|
312
|
+
|
|
313
|
+
## ๐จ **Output Examples**
|
|
314
|
+
|
|
315
|
+
### **๐ BREAKTHROUGH: Perfect Browser Formatting**
|
|
316
|
+
```
|
|
317
|
+
// Direct browser logger with 100% style control:
|
|
318
|
+
12:00 AM ๐ฏ [CACP-CORE] โจ CACP Extension v0.3.2 - Logger Ready!
|
|
319
|
+
12:00 AM ๐ต [SOUNDCLOUD] MediaSession track change detected
|
|
320
|
+
โโ title: Alt-J - Breezeblocks (Gkat Remix)
|
|
321
|
+
โโ artist: Gkat
|
|
322
|
+
โโ hasArtwork: true
|
|
323
|
+
12:00 AM ๐ฏ [CACP-CORE] ๐งช Testing JSON context display
|
|
324
|
+
โโ testData: {nested: {...}, simple: 'test string', boolean: true}
|
|
325
|
+
โโ location: {href: 'https://soundcloud.com/discover', hostname: 'soundcloud.com'}
|
|
326
|
+
โโ timestamp: 2025-07-29T06:00:53.837Z
|
|
327
|
+
```
|
|
328
|
+
|
|
329
|
+
### **File Override in Action**
|
|
330
|
+
```
|
|
331
|
+
// src/sites/soundcloud.js with level: "trace" override:
|
|
332
|
+
12:00 AM ๐ต TRACE [SOUNDCLOUD] Detailed selector matching
|
|
333
|
+
โโ selector: ".playButton"
|
|
334
|
+
โโ found: true
|
|
335
|
+
โโ timing: 2.3ms
|
|
336
|
+
|
|
337
|
+
// src/managers/websocket-manager.js with level: "warn" (quiet):
|
|
338
|
+
(no debug/info logs shown)
|
|
339
|
+
|
|
340
|
+
// src/popup.js with timestampMode: "relative":
|
|
341
|
+
2s ago ๐๏ธ [POPUP] User clicked debug button
|
|
342
|
+
โโ component: "soundcloud"
|
|
343
|
+
```
|
|
344
|
+
|
|
345
|
+
### **Display Toggles in Action**
|
|
346
|
+
```javascript
|
|
347
|
+
// With display: { level: true, jsonPayload: false }:
|
|
348
|
+
12:00 AM ๐จ ERROR [SOUNDCLOUD] Track extraction failed
|
|
349
|
+
|
|
350
|
+
// With display: { timestamp: false, level: true, jsonPayload: true }:
|
|
351
|
+
๐จ ERROR [SOUNDCLOUD] Track extraction failed
|
|
352
|
+
โโ url: https://soundcloud.com/track/example
|
|
353
|
+
โโ retryCount: 3
|
|
354
|
+
```
|
|
355
|
+
|
|
356
|
+
## ๐ฆ Installation
|
|
357
|
+
|
|
358
|
+
```bash
|
|
359
|
+
npm install @cacp/logger
|
|
360
|
+
```
|
|
361
|
+
|
|
362
|
+
## ๐ฏ Environment Detection
|
|
363
|
+
|
|
364
|
+
The logger automatically detects its environment and uses optimal implementations:
|
|
365
|
+
|
|
366
|
+
- **Browser**: **๐ BREAKTHROUGH** - Custom direct logger (bypasses Pino) for 100% console styling control
|
|
367
|
+
- **CLI**: Uses pino-colada for beautiful terminal output
|
|
368
|
+
- **Server**: Uses structured JSON for production logging
|
|
369
|
+
|
|
370
|
+
**Why Browser is Different:**
|
|
371
|
+
Our testing revealed that Pino's browser detection was interfering with custom formatters, especially in Chrome extensions. By creating a custom direct browser logger that bypasses Pino entirely, we achieved:
|
|
372
|
+
- Perfect emoji and color display
|
|
373
|
+
- Readable timestamp formatting (`12:00 AM`)
|
|
374
|
+
- Beautiful JSON tree expansion
|
|
375
|
+
- Seamless Chrome extension integration
|
|
376
|
+
- Zero compromises on functionality
|
|
377
|
+
|
|
378
|
+
## ๐ Advanced Features
|
|
379
|
+
|
|
380
|
+
### **Automatic File Detection**
|
|
381
|
+
The browser formatter automatically detects which file is logging by analyzing the call stack, enabling seamless file override functionality.
|
|
382
|
+
|
|
383
|
+
### **Smart Level Resolution**
|
|
384
|
+
The three-tier hierarchy (file โ component โ global) provides maximum flexibility with sensible defaults.
|
|
385
|
+
|
|
386
|
+
### **Pattern Matching**
|
|
387
|
+
File overrides support glob patterns with `*` and `?` wildcards for powerful bulk configuration.
|
|
388
|
+
|
|
389
|
+
### **Runtime Reconfiguration**
|
|
390
|
+
All settings can be changed at runtime without restarting, perfect for debugging complex issues.
|
|
391
|
+
|
|
392
|
+
## ๐ฏ **Migration from Basic Logger**
|
|
393
|
+
|
|
394
|
+
If you're upgrading from a basic logger:
|
|
395
|
+
|
|
396
|
+
```javascript
|
|
397
|
+
// Before: Simple global level
|
|
398
|
+
logger.level = 'debug';
|
|
399
|
+
|
|
400
|
+
// After: Granular control
|
|
401
|
+
logger.controls.setComponentLevel('websocket', 'warn'); // Quiet websocket
|
|
402
|
+
logger.controls.addFileOverride('src/popup.js', { // Debug popup
|
|
403
|
+
level: 'debug',
|
|
404
|
+
timestampMode: 'relative'
|
|
405
|
+
});
|
|
406
|
+
```
|
|
407
|
+
|
|
408
|
+
## ๐ง **Browser Developer Tools**
|
|
409
|
+
|
|
410
|
+
In browser environments, runtime controls are available globally:
|
|
411
|
+
|
|
412
|
+
```javascript
|
|
413
|
+
// Available as window.CACP_Logger
|
|
414
|
+
CACP_Logger.enableDebugMode();
|
|
415
|
+
CACP_Logger.setDisplayOption('level', true);
|
|
416
|
+
CACP_Logger.addFileOverride('src/popup.js', { level: 'trace' });
|
|
417
|
+
CACP_Logger.getStats();
|
|
418
|
+
```
|
|
419
|
+
|
|
420
|
+
## โ ๏ธ **Disclaimer**
|
|
421
|
+
|
|
422
|
+
This software is provided **"AS IS"** without warranty of any kind. Use at your own risk. The author is not responsible for any damages, data loss, or issues that may result from using this logger. See the LICENSE file for full legal terms.
|
|
423
|
+
|
|
424
|
+
---
|
|
425
|
+
|
|
426
|
+
**License**: ISC
|
|
427
|
+
|
|
428
|
+
This logger system provides the foundation for sophisticated debugging and monitoring across complex multi-file applications with surgical precision and beautiful output.
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Component and Level Schemes for CACP Logger
|
|
3
|
+
* Defines visual styling and organization for all logger components
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
export const COMPONENT_SCHEME = {
|
|
7
|
+
'cacp': { emoji: '๐ฏ', color: '#8E44AD', name: 'CACP-CORE' },
|
|
8
|
+
'soundcloud': { emoji: '๐ต', color: '#FF5500', name: 'SoundCloud' },
|
|
9
|
+
'youtube': { emoji: '๐น', color: '#FF0000', name: 'YouTube' },
|
|
10
|
+
'site-detector': { emoji: '๐', color: '#00C896', name: 'SiteDetector' },
|
|
11
|
+
'websocket': { emoji: '๐', color: '#9B59B6', name: 'WebSocket' },
|
|
12
|
+
'popup': { emoji: '๐๏ธ', color: '#FF6B6B', name: 'Popup' },
|
|
13
|
+
'background': { emoji: '๐ง', color: '#4ECDC4', name: 'Background' },
|
|
14
|
+
'priority-manager': { emoji: 'โ๏ธ', color: '#45B7D1', name: 'PriorityManager' },
|
|
15
|
+
'settings': { emoji: 'โ๏ธ', color: '#96CEB4', name: 'Settings' },
|
|
16
|
+
'test': { emoji: '๐งช', color: '#FFEAA7', name: 'Test' }
|
|
17
|
+
};
|
|
18
|
+
|
|
19
|
+
export const LEVEL_SCHEME = {
|
|
20
|
+
10: { emoji: '๐', color: '#6C7B7F', name: 'TRACE' },
|
|
21
|
+
20: { emoji: '๐', color: '#74B9FF', name: 'DEBUG' },
|
|
22
|
+
30: { emoji: 'โจ', color: '#00B894', name: 'INFO' },
|
|
23
|
+
40: { emoji: 'โ ๏ธ', color: '#FDCB6E', name: 'WARN' },
|
|
24
|
+
50: { emoji: '๐จ', color: '#E17055', name: 'ERROR' },
|
|
25
|
+
60: { emoji: '๐', color: '#D63031', name: 'FATAL' }
|
|
26
|
+
};
|