@crimsonsunset/jsg-logger 1.2.0 โ 1.6.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +174 -0
- package/README.md +149 -19
- package/config/component-schemes.js +13 -1
- package/config/config-manager.js +17 -1
- package/config/default-config.json +1 -2
- package/docs/devtools-roadmap.md +337 -0
- package/docs/next-session.md +149 -123
- package/docs/roadmap.md +73 -5
- package/formatters/cli-formatter.js +64 -42
- package/index.js +163 -29
- package/package.json +18 -6
- package/utils/environment-detector.js +33 -1
package/CHANGELOG.md
CHANGED
|
@@ -16,6 +16,180 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|
|
16
16
|
### Fixed
|
|
17
17
|
- None
|
|
18
18
|
|
|
19
|
+
## [1.5.0] - 2025-10-25 ๐ฏ **CRITICAL FIX: CLI Tool Support**
|
|
20
|
+
|
|
21
|
+
### ๐จ **Critical Fixes**
|
|
22
|
+
These fixes resolve major blockers for CLI tool usage reported in production.
|
|
23
|
+
|
|
24
|
+
#### **Fixed: CLI Formatter Context Data Display** (Critical)
|
|
25
|
+
- **Replaced pino-colada** with custom formatter that displays context data
|
|
26
|
+
- Context objects now render as indented tree format in terminal
|
|
27
|
+
- Example output:
|
|
28
|
+
```
|
|
29
|
+
21:32:11.6 โจ [SYSTEM] โ macOS version compatible
|
|
30
|
+
โโ version: 14.2
|
|
31
|
+
โโ build: 23C64
|
|
32
|
+
โโ command: sw_vers
|
|
33
|
+
```
|
|
34
|
+
- **Problem solved**: Context data was being silently ignored by pino-colada
|
|
35
|
+
- **Impact**: Terminal applications now show full diagnostic information, not just messages
|
|
36
|
+
|
|
37
|
+
#### **Fixed: Environment Detection for CLI Tools** (Critical)
|
|
38
|
+
- **Enhanced `isCLI()` detection** - Now checks multiple signals:
|
|
39
|
+
- `process.stdout.isTTY` OR `process.stderr.isTTY` (not just stdout)
|
|
40
|
+
- `process.env.TERM` or `process.env.COLORTERM` environment variables
|
|
41
|
+
- Not running in CI/GitHub Actions context
|
|
42
|
+
- **Problem solved**: CLI tools were being detected as "server" mode โ outputting JSON instead of pretty terminal formatting
|
|
43
|
+
- **Impact**: Terminal applications now properly display colored, formatted output instead of raw JSON blobs
|
|
44
|
+
|
|
45
|
+
#### **Added: Force Environment Override** (Critical)
|
|
46
|
+
- **New config option**: `forceEnvironment: 'cli' | 'browser' | 'server'`
|
|
47
|
+
- Allows explicit environment override when auto-detection fails
|
|
48
|
+
- Works in both inline config and `logger-config.json`
|
|
49
|
+
- **Use case**: Essential for CLI tools in non-TTY contexts (piped output, automation scripts, etc.)
|
|
50
|
+
|
|
51
|
+
#### **Added: Custom Component Name Support** (High Priority)
|
|
52
|
+
- **Auto-create loggers for ANY component name** - No longer restricted to `COMPONENT_SCHEME`
|
|
53
|
+
- Components not in config get auto-generated with sensible defaults:
|
|
54
|
+
- Default emoji: ๐ฆ
|
|
55
|
+
- Default color: #999999
|
|
56
|
+
- Uppercase display name
|
|
57
|
+
- Global level inheritance
|
|
58
|
+
- **Problem solved**: Custom components like 'system', 'installer', 'nvm' now work without pre-definition
|
|
59
|
+
- **Impact**: True zero-configuration for component names
|
|
60
|
+
|
|
61
|
+
### โจ **API Enhancements**
|
|
62
|
+
|
|
63
|
+
#### **Updated: `getComponent()` Method**
|
|
64
|
+
- Now auto-creates loggers for undefined components instead of returning error loggers
|
|
65
|
+
- Adds new components to auto-discovery getters dynamically
|
|
66
|
+
- Seamless experience for custom component names
|
|
67
|
+
|
|
68
|
+
#### **Updated: `getComponentConfig()` Method**
|
|
69
|
+
- Added 3-tier priority system:
|
|
70
|
+
1. Config components (project-defined)
|
|
71
|
+
2. COMPONENT_SCHEME defaults (built-in)
|
|
72
|
+
3. Auto-generated (for custom components)
|
|
73
|
+
- Always returns valid config, never null/undefined
|
|
74
|
+
|
|
75
|
+
#### **Updated: `init()` and `initSync()` Methods**
|
|
76
|
+
- Now load config BEFORE environment detection
|
|
77
|
+
- Apply `forceEnvironment` config before determining environment
|
|
78
|
+
- `initSync()` properly handles inline config objects
|
|
79
|
+
|
|
80
|
+
### ๐ **Documentation**
|
|
81
|
+
- **Updated README** - New v1.5.0 Quick Start section highlighting CLI tool fixes
|
|
82
|
+
- **Added Force Environment docs** - When and how to override environment detection
|
|
83
|
+
- **Added Custom Components docs** - Examples of using arbitrary component names
|
|
84
|
+
- **Updated Environment Detection section** - Document enhanced CLI detection logic
|
|
85
|
+
|
|
86
|
+
### ๐ฏ **Real-World Impact**
|
|
87
|
+
**Before v1.5.0 (Broken for CLI tools):**
|
|
88
|
+
```javascript
|
|
89
|
+
const logger = JSGLogger.getInstanceSync({ components: { system: {...} } });
|
|
90
|
+
logger.getComponent('system').info('โ macOS compatible', { version: '14.2', build: '23C64' });
|
|
91
|
+
// Output: {"level":30,"time":...,"msg":"โ macOS compatible"} โ JSON blob
|
|
92
|
+
// Component 'system' not found error โ
|
|
93
|
+
// Context data not visible โ
|
|
94
|
+
```
|
|
95
|
+
|
|
96
|
+
**After v1.5.0 (All Fixed!):**
|
|
97
|
+
```javascript
|
|
98
|
+
const logger = JSGLogger.getInstanceSync({
|
|
99
|
+
forceEnvironment: 'cli',
|
|
100
|
+
components: { system: { emoji: 'โ๏ธ' } }
|
|
101
|
+
});
|
|
102
|
+
logger.getComponent('system').info('โ macOS compatible', { version: '14.2', build: '23C64' });
|
|
103
|
+
// Output:
|
|
104
|
+
// 21:32:11.6 โ๏ธ [SYSTEM] โ macOS compatible โ
Pretty formatted
|
|
105
|
+
// โโ version: 14.2 โ
Context data visible
|
|
106
|
+
// โโ build: 23C64 โ
Tree formatting
|
|
107
|
+
// Custom component works โ
|
|
108
|
+
```
|
|
109
|
+
|
|
110
|
+
### ๐ง **Technical Changes**
|
|
111
|
+
- **File**: `formatters/cli-formatter.js` โญ NEW FIX
|
|
112
|
+
- Removed pino-colada dependency (wasn't showing context data)
|
|
113
|
+
- Implemented custom formatter with context tree rendering
|
|
114
|
+
- Context data now displays with tree formatting (โโ and โโ)
|
|
115
|
+
- Filters out pino internal fields (level, time, msg, pid, hostname, name, v, environment)
|
|
116
|
+
|
|
117
|
+
- **File**: `utils/environment-detector.js`
|
|
118
|
+
- Added `forceEnvironment()` function for manual override
|
|
119
|
+
- Enhanced `isCLI()` with multi-signal detection
|
|
120
|
+
- All detection functions now respect forced environment
|
|
121
|
+
|
|
122
|
+
- **File**: `config/config-manager.js`
|
|
123
|
+
- `getComponentConfig()` now has 3-tier fallback with auto-generation
|
|
124
|
+
|
|
125
|
+
- **File**: `index.js`
|
|
126
|
+
- Import `forceEnvironment` from environment detector
|
|
127
|
+
- Config loading moved BEFORE environment detection
|
|
128
|
+
- `getComponent()` auto-creates loggers instead of error loggers
|
|
129
|
+
- Added dynamic auto-discovery getter registration
|
|
130
|
+
|
|
131
|
+
- **File**: `package.json`
|
|
132
|
+
- Removed pino-colada from dependencies (no longer required)
|
|
133
|
+
|
|
134
|
+
### ๐ **Migration Guide**
|
|
135
|
+
**No breaking changes** - This is a backward-compatible enhancement.
|
|
136
|
+
|
|
137
|
+
**Recommended for CLI tools:**
|
|
138
|
+
```javascript
|
|
139
|
+
// Add this to your config for reliable terminal output
|
|
140
|
+
const logger = JSGLogger.getInstanceSync({
|
|
141
|
+
forceEnvironment: 'cli', // โ Add this line
|
|
142
|
+
// ... rest of your config
|
|
143
|
+
});
|
|
144
|
+
```
|
|
145
|
+
|
|
146
|
+
## [1.2.0] - 2025-08-21 ๐ฏ **MAJOR: Fully Generic Logger**
|
|
147
|
+
|
|
148
|
+
### ๐ **BREAKING CHANGES**
|
|
149
|
+
- **Minimal default config**: Only 'core' component included by default
|
|
150
|
+
- **Projects must define components**: Custom components now required in logger-config.json
|
|
151
|
+
- **Legacy component removal**: All 10 hardcoded legacy components removed
|
|
152
|
+
- **Core component rename**: 'cacp' โ 'core' throughout functional code
|
|
153
|
+
|
|
154
|
+
### โจ **Added**
|
|
155
|
+
- **100% Generic Design**: Zero legacy/project-specific references
|
|
156
|
+
- **Dynamic Alias Generation**: Auto-generate camelCase from kebab-case component names
|
|
157
|
+
- **Smart Component Creation**: Missing components auto-created with sensible defaults
|
|
158
|
+
- **Enhanced Config Normalization**: Better handling of various config formats
|
|
159
|
+
- **Generic Examples**: Updated advanced-config.json with modern component examples
|
|
160
|
+
|
|
161
|
+
### ๐ง **Changed**
|
|
162
|
+
- **Default Configuration**: Minimal config with only 'core' component
|
|
163
|
+
- **Component Schemes**: Cleaned to minimal generic set
|
|
164
|
+
- **Class Names**: CACPLogger โ JSGLogger throughout (completed in 1.1.4-1.1.7)
|
|
165
|
+
- **Browser Global**: window.CACP_Logger โ window.JSG_Logger
|
|
166
|
+
- **Fallback Logic**: Uses 'core' component instead of hardcoded 'cacp'
|
|
167
|
+
|
|
168
|
+
### ๐๏ธ **Removed**
|
|
169
|
+
- **Legacy Components**: soundcloud, youtube, site-detector, websocket, popup, background, priority-manager, settings, test
|
|
170
|
+
- **Hardcoded Aliases**: Replaced siteDetector/priorityManager with dynamic generation
|
|
171
|
+
- **Project-Specific Logic**: All hardcoded references to specific use cases
|
|
172
|
+
|
|
173
|
+
### ๐ **Documentation**
|
|
174
|
+
- **Updated Roadmap**: Phase 9 complete, Phase 10 DX enhancements planned
|
|
175
|
+
- **Migration Guide**: Clear upgrade path for existing projects
|
|
176
|
+
- **Generic Examples**: Modern component examples for common project types
|
|
177
|
+
|
|
178
|
+
### ๐ฏ **Migration Notes**
|
|
179
|
+
Existing projects need to update their logger-config.json to define components:
|
|
180
|
+
|
|
181
|
+
```json
|
|
182
|
+
{
|
|
183
|
+
"components": {
|
|
184
|
+
"core": { "emoji": "๐ฏ", "level": "info" },
|
|
185
|
+
"api": { "emoji": "๐", "level": "debug" },
|
|
186
|
+
"ui": { "emoji": "๐จ", "level": "info" }
|
|
187
|
+
}
|
|
188
|
+
}
|
|
189
|
+
```
|
|
190
|
+
|
|
191
|
+
The logger will auto-create missing components, but explicit definition is recommended.
|
|
192
|
+
|
|
19
193
|
## [1.0.8] - 2025-08-06
|
|
20
194
|
|
|
21
195
|
### Changed
|
package/README.md
CHANGED
|
@@ -1,16 +1,19 @@
|
|
|
1
1
|
# JSG Logger
|
|
2
2
|
|
|
3
|
-
**
|
|
3
|
+
**100% Generic Multi-Environment Logger with Advanced Configuration**
|
|
4
4
|
|
|
5
|
-
A sophisticated logging system that automatically detects its environment (browser, CLI, server) and provides optimal logging experience for
|
|
5
|
+
A sophisticated, fully generic logging system that automatically detects its environment (browser, CLI, server) and provides optimal logging experience for any JavaScript project, with powerful file-level overrides and granular control.
|
|
6
6
|
|
|
7
7
|
## โจ Features
|
|
8
8
|
|
|
9
|
-
-
|
|
10
|
-
-
|
|
11
|
-
-
|
|
12
|
-
-
|
|
13
|
-
-
|
|
9
|
+
- ๐ฏ **100% Generic** - *New in v1.2.0!* Zero hardcoded assumptions, works with any project type
|
|
10
|
+
- ๐ **Zero-Boilerplate Integration** - Eliminates 200+ lines of project setup code
|
|
11
|
+
- ๐ง **Auto-Discovery Components** - Both camelCase and kebab-case component access
|
|
12
|
+
- โก **Built-in Performance Logging** - Static utilities with auto-getInstance
|
|
13
|
+
- ๐ก๏ธ **Non-Destructive Error Handling** - Missing components log but don't break apps
|
|
14
|
+
- ๐จ **Custom Component Names** - *New in v1.5.0!* Use ANY component name, auto-generated styling
|
|
15
|
+
- ๐ง **Force Environment Override** - *New in v1.5.0!* Override auto-detection for CLI tools
|
|
16
|
+
- ๐ง **Enhanced Environment Detection** - *New in v1.5.0!* Robust CLI detection with fallbacks
|
|
14
17
|
- ๐จ **Beautiful Visual Output** - Emoji, colors, and structured context display
|
|
15
18
|
- ๐ฑ **Multi-Environment** - Browser console, terminal, and production JSON
|
|
16
19
|
- ๐ช **Log Store** - In-memory storage for debugging and popup interfaces
|
|
@@ -24,28 +27,66 @@ A sophisticated logging system that automatically detects its environment (brows
|
|
|
24
27
|
|
|
25
28
|
## ๐ Quick Start
|
|
26
29
|
|
|
27
|
-
### **
|
|
30
|
+
### **v1.5.0: Custom Components & Force Environment - Perfect for CLI Tools!**
|
|
31
|
+
|
|
32
|
+
> **โจ New in v1.5.0:** Use ANY component name (not just pre-defined ones) and force CLI mode for terminal applications!
|
|
33
|
+
|
|
34
|
+
```javascript
|
|
35
|
+
import JSGLogger from '@crimsonsunset/jsg-logger';
|
|
36
|
+
|
|
37
|
+
// โจ NEW: Force environment for CLI tools (fixes terminal detection)
|
|
38
|
+
const logger = JSGLogger.getInstanceSync({
|
|
39
|
+
forceEnvironment: 'cli', // Forces pretty terminal output
|
|
40
|
+
globalLevel: 'info',
|
|
41
|
+
components: {
|
|
42
|
+
system: { emoji: 'โ๏ธ', level: 'info' }, // Custom component names!
|
|
43
|
+
installer: { emoji: '๐ฆ', level: 'info' }, // No need to pre-define
|
|
44
|
+
ssh: { emoji: '๐', level: 'info' }, // Auto-generated styling
|
|
45
|
+
nvm: { emoji: '๐ข', level: 'info' }
|
|
46
|
+
}
|
|
47
|
+
});
|
|
48
|
+
|
|
49
|
+
// โจ NEW: Custom components work immediately
|
|
50
|
+
const sysLog = logger.getComponent('system');
|
|
51
|
+
sysLog.info('โ macOS version compatible', { version: '14.2', build: '23C64' });
|
|
52
|
+
// Output: Pretty formatted terminal output with colors AND context data!
|
|
53
|
+
// 21:32:11.6 โ๏ธ [SYSTEM] โ macOS version compatible
|
|
54
|
+
// โโ version: 14.2
|
|
55
|
+
// โโ build: 23C64
|
|
56
|
+
|
|
57
|
+
const installLog = logger.getComponent('installer');
|
|
58
|
+
installLog.info('โ Applications installed', { installed: 25, duration: '5m' });
|
|
59
|
+
// 21:32:11.8 ๐ฆ [INSTALLER] โ Applications installed
|
|
60
|
+
// โโ installed: 25
|
|
61
|
+
// โโ duration: 5m
|
|
62
|
+
// No more JSON blobs in terminal! ๐
|
|
63
|
+
```
|
|
64
|
+
|
|
65
|
+
### **v1.2.0: Fully Generic Design - Works with Any Project!**
|
|
66
|
+
|
|
67
|
+
> **โ ๏ธ Breaking Change:** v1.2.0 requires defining components in your logger-config.json. The logger is now 100% generic with no hardcoded assumptions.
|
|
28
68
|
|
|
29
69
|
```javascript
|
|
30
70
|
import JSGLogger from '@crimsonsunset/jsg-logger';
|
|
31
71
|
|
|
32
72
|
// Enhanced singleton with built-in configuration loading
|
|
33
|
-
const logger = JSGLogger.getInstance({
|
|
73
|
+
const logger = await JSGLogger.getInstance({
|
|
34
74
|
configPath: './logger-config.json'
|
|
35
75
|
});
|
|
36
76
|
|
|
37
|
-
//
|
|
38
|
-
logger.
|
|
39
|
-
logger.
|
|
77
|
+
// Use your project-specific components immediately
|
|
78
|
+
logger.api.info('Server started on port 3000');
|
|
79
|
+
logger.database.debug('Query executed', { query: 'SELECT * FROM users' });
|
|
80
|
+
logger.ui.info('Component mounted', { component: 'UserProfile' });
|
|
40
81
|
|
|
41
|
-
// Built-in static performance logging
|
|
82
|
+
// Built-in static performance logging
|
|
42
83
|
const startTime = performance.now();
|
|
43
84
|
// ... do work ...
|
|
44
|
-
JSGLogger.logPerformance('Page Generation', startTime, '
|
|
85
|
+
JSGLogger.logPerformance('Page Generation', startTime, 'api');
|
|
45
86
|
|
|
46
|
-
//
|
|
47
|
-
const
|
|
48
|
-
|
|
87
|
+
// โจ NEW: Custom components auto-created on demand
|
|
88
|
+
const dynamicLogger = logger.getComponent('new-feature');
|
|
89
|
+
dynamicLogger.info('Auto-created component!'); // Works immediately
|
|
49
90
|
```
|
|
50
91
|
|
|
51
92
|
### **Traditional Usage (Still Supported)**
|
|
@@ -78,10 +119,68 @@ This allows surgical debugging - you can turn on trace logging for just one prob
|
|
|
78
119
|
|
|
79
120
|
## โ๏ธ **Advanced Configuration**
|
|
80
121
|
|
|
122
|
+
### **Force Environment Override** โจ *New in v1.5.0*
|
|
123
|
+
|
|
124
|
+
Perfect for CLI tools that get mis-detected as "server" mode:
|
|
125
|
+
|
|
126
|
+
```javascript
|
|
127
|
+
// Inline config approach (recommended for CLI tools)
|
|
128
|
+
const logger = JSGLogger.getInstanceSync({
|
|
129
|
+
forceEnvironment: 'cli', // Options: 'browser', 'cli', 'server'
|
|
130
|
+
globalLevel: 'info',
|
|
131
|
+
components: {
|
|
132
|
+
system: { emoji: 'โ๏ธ', level: 'info' }
|
|
133
|
+
}
|
|
134
|
+
});
|
|
135
|
+
```
|
|
136
|
+
|
|
137
|
+
Or in `logger-config.json`:
|
|
138
|
+
|
|
139
|
+
```json
|
|
140
|
+
{
|
|
141
|
+
"forceEnvironment": "cli",
|
|
142
|
+
"projectName": "My CLI Tool",
|
|
143
|
+
"globalLevel": "info",
|
|
144
|
+
"components": {
|
|
145
|
+
"system": { "emoji": "โ๏ธ", "level": "info" }
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
```
|
|
149
|
+
|
|
150
|
+
**When to use `forceEnvironment`:**
|
|
151
|
+
- CLI tools running in non-TTY contexts (CI, piped output, etc.)
|
|
152
|
+
- Override incorrect environment detection
|
|
153
|
+
- Testing different output formats
|
|
154
|
+
- Production deployments with specific requirements
|
|
155
|
+
|
|
156
|
+
### **Custom Component Names** โจ *New in v1.5.0*
|
|
157
|
+
|
|
158
|
+
Use ANY component name - no need to pre-define in COMPONENT_SCHEME:
|
|
159
|
+
|
|
160
|
+
```javascript
|
|
161
|
+
const logger = JSGLogger.getInstanceSync({
|
|
162
|
+
components: {
|
|
163
|
+
'my-custom-component': { emoji: '๐ฏ', level: 'debug' },
|
|
164
|
+
'another-one': { emoji: '๐', level: 'info' },
|
|
165
|
+
'system-checker': { emoji: 'โ๏ธ', level: 'trace' }
|
|
166
|
+
}
|
|
167
|
+
});
|
|
168
|
+
|
|
169
|
+
// All these work immediately - auto-created with sensible defaults
|
|
170
|
+
const log1 = logger.getComponent('my-custom-component');
|
|
171
|
+
const log2 = logger.getComponent('another-one');
|
|
172
|
+
const log3 = logger.getComponent('system-checker');
|
|
173
|
+
|
|
174
|
+
// Even undefined components work (auto-generated with ๐ฆ emoji)
|
|
175
|
+
const log4 = logger.getComponent('undefined-component');
|
|
176
|
+
log4.info('This works!'); // Uses auto-generated styling
|
|
177
|
+
```
|
|
178
|
+
|
|
81
179
|
### **Full Configuration Example**
|
|
82
180
|
|
|
83
181
|
```json
|
|
84
182
|
{
|
|
183
|
+
"forceEnvironment": "cli",
|
|
85
184
|
"projectName": "My Advanced Project",
|
|
86
185
|
"globalLevel": "info",
|
|
87
186
|
"timestampMode": "absolute",
|
|
@@ -251,6 +350,9 @@ logger.controls.addFileOverride('src/popup.js', {
|
|
|
251
350
|
```
|
|
252
351
|
|
|
253
352
|
### **Context Data**
|
|
353
|
+
|
|
354
|
+
โจ **New in v1.5.0:** Context data now displays in CLI/terminal mode with tree formatting!
|
|
355
|
+
|
|
254
356
|
```javascript
|
|
255
357
|
logger.api.error('Request failed', {
|
|
256
358
|
url: window.location.href,
|
|
@@ -263,7 +365,15 @@ logger.api.error('Request failed', {
|
|
|
263
365
|
userAgent: navigator.userAgent
|
|
264
366
|
});
|
|
265
367
|
|
|
266
|
-
//
|
|
368
|
+
// CLI/Terminal output (v1.5.0+):
|
|
369
|
+
// 22:15:30.1 ๐จ [API] Request failed
|
|
370
|
+
// โโ url: https://soundcloud.com/track/example
|
|
371
|
+
// โโ selectors: {"title":".track-title","artist":".track-artist"}
|
|
372
|
+
// โโ retryCount: 3
|
|
373
|
+
// โโ lastError: Element not found
|
|
374
|
+
// โโ userAgent: Mozilla/5.0...
|
|
375
|
+
|
|
376
|
+
// Browser Console output:
|
|
267
377
|
// 22:15:30.123 ๐จ [API] Request failed
|
|
268
378
|
// โโ url: https://soundcloud.com/track/example
|
|
269
379
|
// โโ selectors: {title: ".track-title", artist: ".track-artist"}
|
|
@@ -389,7 +499,7 @@ const stats = logger.controls.getStats();
|
|
|
389
499
|
npm install @crimsonsunset/jsg-logger
|
|
390
500
|
```
|
|
391
501
|
|
|
392
|
-
**Latest**: v1.
|
|
502
|
+
**Latest**: v1.5.0 includes critical CLI tool fixes and custom component support!
|
|
393
503
|
|
|
394
504
|
## ๐ฏ Environment Detection
|
|
395
505
|
|
|
@@ -399,6 +509,26 @@ The logger automatically detects its environment and uses optimal implementation
|
|
|
399
509
|
- **CLI**: Uses pino-colada for beautiful terminal output
|
|
400
510
|
- **Server**: Uses structured JSON for production logging
|
|
401
511
|
|
|
512
|
+
### **Enhanced CLI Detection** โจ *Improved in v1.5.0*
|
|
513
|
+
|
|
514
|
+
The CLI detection now checks multiple signals:
|
|
515
|
+
1. **TTY Check**: `process.stdout.isTTY` or `process.stderr.isTTY`
|
|
516
|
+
2. **Terminal Environment**: `process.env.TERM` or `process.env.COLORTERM`
|
|
517
|
+
3. **Non-CI Context**: Not running in CI/GitHub Actions
|
|
518
|
+
|
|
519
|
+
This fixes detection issues in various terminal contexts where `isTTY` may be undefined.
|
|
520
|
+
|
|
521
|
+
### **Force Environment Override** โจ *New in v1.5.0*
|
|
522
|
+
|
|
523
|
+
If auto-detection fails, you can force the environment:
|
|
524
|
+
|
|
525
|
+
```javascript
|
|
526
|
+
const logger = JSGLogger.getInstanceSync({
|
|
527
|
+
forceEnvironment: 'cli', // Override auto-detection
|
|
528
|
+
// ... rest of config
|
|
529
|
+
});
|
|
530
|
+
```
|
|
531
|
+
|
|
402
532
|
**Why Browser is Different:**
|
|
403
533
|
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:
|
|
404
534
|
- Perfect emoji and color display
|
|
@@ -4,7 +4,19 @@
|
|
|
4
4
|
*/
|
|
5
5
|
|
|
6
6
|
export const COMPONENT_SCHEME = {
|
|
7
|
-
'core': { emoji: '๐ฏ', color: '#
|
|
7
|
+
'core': { emoji: '๐ฏ', color: '#4A90E2', name: 'JSG-CORE' },
|
|
8
|
+
'api': { emoji: '๐', color: '#FF5500', name: 'API' },
|
|
9
|
+
'ui': { emoji: '๐จ', color: '#FF6B6B', name: 'UI' },
|
|
10
|
+
'database': { emoji: '๐พ', color: '#00C896', name: 'DATABASE' },
|
|
11
|
+
'test': { emoji: '๐งช', color: '#FFEAA7', name: 'TEST' },
|
|
12
|
+
'preact': { emoji: 'โ๏ธ', color: '#673ab8', name: 'PREACT' },
|
|
13
|
+
'auth': { emoji: '๐', color: '#E67E22', name: 'AUTH' },
|
|
14
|
+
'analytics': { emoji: '๐', color: '#9B59B6', name: 'ANALYTICS' },
|
|
15
|
+
'performance': { emoji: 'โก', color: '#F39C12', name: 'PERFORMANCE' },
|
|
16
|
+
'websocket': { emoji: '๐', color: '#1ABC9C', name: 'WEBSOCKET' },
|
|
17
|
+
'notification': { emoji: '๐', color: '#E74C3C', name: 'NOTIFICATION' },
|
|
18
|
+
'router': { emoji: '๐ฃ๏ธ', color: '#3498DB', name: 'ROUTER' },
|
|
19
|
+
'cache': { emoji: '๐จ', color: '#95A5A6', name: 'CACHE' }
|
|
8
20
|
};
|
|
9
21
|
|
|
10
22
|
export const LEVEL_SCHEME = {
|
package/config/config-manager.js
CHANGED
|
@@ -406,7 +406,23 @@ export class ConfigManager {
|
|
|
406
406
|
* @returns {Object} Component configuration
|
|
407
407
|
*/
|
|
408
408
|
getComponentConfig(componentName, filePath = null) {
|
|
409
|
-
|
|
409
|
+
// Priority 1: Config components
|
|
410
|
+
let baseComponent = this.config.components?.[componentName];
|
|
411
|
+
|
|
412
|
+
// Priority 2: COMPONENT_SCHEME defaults
|
|
413
|
+
if (!baseComponent) {
|
|
414
|
+
baseComponent = COMPONENT_SCHEME[componentName];
|
|
415
|
+
}
|
|
416
|
+
|
|
417
|
+
// Priority 3: Auto-generate for custom components
|
|
418
|
+
if (!baseComponent) {
|
|
419
|
+
baseComponent = {
|
|
420
|
+
emoji: '๐ฆ',
|
|
421
|
+
color: '#999999',
|
|
422
|
+
name: componentName.toUpperCase().replace(/-/g, '-'),
|
|
423
|
+
level: this.config.globalLevel || 'info'
|
|
424
|
+
};
|
|
425
|
+
}
|
|
410
426
|
|
|
411
427
|
// Check for file-specific overrides
|
|
412
428
|
const checkFile = filePath || this.currentFile;
|