@crimsonsunset/jsg-logger 1.7.0 → 1.7.4

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 CHANGED
@@ -5,7 +5,32 @@ All notable changes to the JSG Logger project will be documented in this file.
5
5
  The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
6
6
  and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
7
7
 
8
- ## [1.6.0] - 2025-01-XX 🎯 **Config-Driven Tree-Shaking & Enhanced Logging**
8
+ ## [1.7.3] - 2025-11-06 🎛️ **DevTools Logging Cleanup**
9
+
10
+ ### Fixed
11
+ - **Meta-Logger Scope** - Clarified meta-logger is for bootstrap logs only
12
+ - Removed `'logger'` mode option (now just `true`/`false`)
13
+ - Updated JSDoc to emphasize "BOOTSTRAP ONLY" usage
14
+ - Post-init errors now use actual logger if available, fallback to console
15
+ - **DevTools Component-Based Logging** - Fixed DevTools to use proper component logging
16
+ - Added `devtools-ui` component to `COMPONENT_SCHEME` (🎛️ emoji, purple color)
17
+ - DevTools controls API (`enableDevPanel`, `disableDevPanel`) now use `devtools-ui` component instead of `core`
18
+ - All DevTools files now import logger directly instead of using window globals
19
+ - Removed manual `[JSG-DEVTOOLS]` prefixes from all log messages (logger adds component name automatically)
20
+ - DevTools logs now show as `🎛️ [DEVTOOLS]` instead of `🎯 [CORE] [JSG-LOGGER]`
21
+
22
+ ### Changed
23
+ - **DevTools Logging Pattern** - Standardized DevTools logging approach
24
+ - Pattern: `import logger from '../../index.js'; const devtoolsLogger = logger.getComponent('devtools-ui');`
25
+ - No console fallbacks needed (`getComponent` always returns valid logger)
26
+ - Clean component-based logging throughout DevTools lifecycle
27
+
28
+ ### Technical Details
29
+ - **Files Modified**: `utils/meta-logger.js`, `index.js`, `config/config-manager.js`, `config/component-schemes.js`
30
+ - **DevTools Files**: `devtools/src/panel-entry.jsx`, `devtools/src/App.jsx`, `devtools/components/GlobalControls.js`, `devtools/components/DevToolsPanel.js`
31
+ - **Result**: Consistent, component-based logging with proper formatting and no manual prefixes
32
+
33
+ ## [1.7.0] - 2025-01-XX 🎯 **Config-Driven Tree-Shaking & Enhanced Logging**
9
34
 
10
35
  ### Added
11
36
  - **Config-Driven Tree-Shaking** - DevTools panel tree-shaking now based on default config at module load time
@@ -56,13 +81,118 @@ No breaking changes. Existing code continues to work.
56
81
  - No special Vite config needed for production builds
57
82
  - npm link users: add `server.fs.allow: ['..']` to Vite config for dev
58
83
 
59
- ## [Unreleased]
84
+ ## [1.7.1] - 2025-11-05 🎯 **TypeScript Support & Zero-Optional-Chaining API**
60
85
 
61
- ## [1.5.2] - 2025-10-25 🐛 **PATCH: CLI Formatter Custom Component Display**
86
+ ### Added
87
+ - **TypeScript Definitions** - Full TypeScript support with `index.d.ts`
88
+ - Complete type definitions for all logger interfaces
89
+ - `LoggerInstance`, `LoggerComponents`, `LoggerInstanceType` interfaces
90
+ - Proper exports configuration in `package.json` with `types` field
91
+ - **Safe Component Getters** - Component getters initialized in constructor
92
+ - `_initializeSafeComponentGetters()` ensures components accessible before initialization
93
+ - Common components (reactComponents, astroComponents, etc.) always available
94
+ - Returns no-op logger factories if logger not initialized yet
95
+
96
+ ### Changed
97
+ - **getComponent Always Available** - `getComponent` is now non-optional in TypeScript types
98
+ - Removed `?` optional marker from `getComponent` in `LoggerInstanceType`
99
+ - Always returns a logger instance (no-op if not initialized)
100
+ - Consumers can call `loggerInstance.getComponent('componentName')` without optional chaining
101
+ - **Fallback Logger Enhancement** - `createFallbackLogger()` now includes `getComponent`
102
+ - Ensures `getComponent` exists even when initialization fails
103
+ - Returns no-op logger factory for safe fallback behavior
104
+ - **Enhanced getComponent Safety** - Improved error handling and edge cases
105
+ - Returns no-op logger if instance not initialized
106
+ - Returns no-op logger if logger creation fails
107
+ - Prevents crashes when logger unavailable
108
+
109
+ ### Fixed
110
+ - **Optional Chaining Burden** - Eliminated need for `?.` optional chaining in consumer code
111
+ - Consumers can now use `loggerInstance.getComponent('componentName').debug(...)` directly
112
+ - No more `loggerInstance?.getComponent?.('componentName')?.debug(...)` chains
113
+ - TypeScript types guarantee `getComponent` always exists
114
+
115
+ ### Technical Details
116
+ - **File**: `index.d.ts` (NEW)
117
+ - Complete TypeScript definitions for the logger package
118
+ - Non-optional `getComponent` method signature
119
+ - Proper interface documentation
120
+
121
+ - **File**: `index.js`
122
+ - Added `_initializeSafeComponentGetters()` method called in constructor
123
+ - Enhanced `getComponent()` to always return logger (no-op fallback)
124
+ - Added `_createNoOpLogger()` private method for safe fallbacks
125
+ - Updated `createFallbackLogger()` to include `getComponent`
126
+ - Modified `_createAutoDiscoveryGetters()` to preserve safe getters
127
+
128
+ - **File**: `package.json`
129
+ - Added `"types": "./index.d.ts"` field
130
+ - Added `index.d.ts` to `files` array
131
+ - Updated `exports` to include proper TypeScript types export
132
+
133
+ ### Migration Notes
134
+ No breaking changes. Existing code continues to work, but optional chaining is now optional (pun intended).
135
+
136
+ **For consumers:**
137
+ - Can now use `loggerInstance.getComponent('componentName')` without `?.`
138
+ - TypeScript users get full type safety and autocomplete
139
+ - No-op logger returned if logger not initialized (safe to call)
140
+ - Recommended: Use `getInstanceSync()` for synchronous access instead of `getInstance()` when possible
141
+
142
+ ## [1.7.0] - 2025-01-XX 🎯 **Config-Driven Tree-Shaking & Enhanced Logging**
143
+
144
+ ### Added
145
+ - **Config-Driven Tree-Shaking** - DevTools panel tree-shaking now based on default config at module load time
146
+ - Tree-shaking determined by `defaultConfig.devtools.enabled` (default: `false`)
147
+ - When disabled, devtools code completely tree-shaken (zero bundle impact)
148
+ - When enabled via runtime config, loads dynamically on demand
149
+ - Static import analysis allows bundlers to eliminate unused code paths
150
+ - **Comprehensive DevTools Logging** - Added detailed logging throughout DevTools lifecycle
151
+ - Module load: logs default config tree-shaking status
152
+ - Config loading: logs when devtools enabled/disabled via user config
153
+ - DevTools activation: logs pre-load status, dynamic loading, and initialization steps
154
+ - Config merge: logs devtools status changes between defaults and user config
155
+
156
+ ### Changed
157
+ - **DevTools Import Strategy** - Simplified to relative path imports
158
+ - Removed complex Function constructor + package export path logic
159
+ - Uses simple relative path: `./devtools/dist/panel-entry.js`
160
+ - Works in production builds, requires `server.fs.allow: ['..']` for npm link dev
161
+ - **Config Loading Logging** - Enhanced visibility into config loading process
162
+ - Logs config source (file path vs inline object)
163
+ - Logs devtools status before/after config merge
164
+ - Logs initialization start with config source information
62
165
 
63
166
  ### Fixed
64
- - **CLI formatter custom component names** - Formatter was using hardcoded `COMPONENT_SCHEME` instead of `configManager`, causing custom component names to display as `[JSG-CORE]` instead of user-defined names like `[SETUP]`
65
- - **Browser formatter** - Removed redundant component name transformation
167
+ - **Tree-Shaking Detection** - Bundlers can now properly analyze and eliminate devtools code when disabled
168
+ - **DevTools Pre-loading** - Non-blocking pre-load when default config enables devtools
169
+ - **Runtime Config Override** - Dynamic loading works correctly when runtime config enables devtools but default disabled
170
+
171
+ ### Technical Details
172
+ - **File**: `index.js`
173
+ - Added conditional static import based on `defaultConfig.devtools.enabled`
174
+ - Lazy initialization pattern to avoid top-level await
175
+ - Enhanced `enableDevPanel()` with comprehensive logging
176
+ - Pre-loads devtools module when default config enables it
177
+
178
+ - **File**: `config/config-manager.js`
179
+ - Added logging for config loading (file vs inline)
180
+ - Added devtools status logging before/after config merge
181
+ - Enhanced visibility into config changes
182
+
183
+ ### Migration Notes
184
+ No breaking changes. Existing code continues to work.
185
+
186
+ **For consumers:**
187
+ - DevTools code tree-shaken by default (zero bundle impact)
188
+ - Enable via runtime config: `{ devtools: { enabled: true } }`
189
+ - DevTools loads dynamically when `enableDevPanel()` called
190
+ - No special Vite config needed for production builds
191
+ - npm link users: add `server.fs.allow: ['..']` to Vite config for dev
192
+
193
+ ## [Unreleased]
194
+
195
+ ## [1.5.2] - 2025-10-25 🐛 **PATCH: CLI Formatter Custom Component Display**
66
196
 
67
197
  ### Technical Changes
68
198
  - `formatters/cli-formatter.js` - Use `configManager.getComponentConfig()` instead of static `COMPONENT_SCHEME`
@@ -16,7 +16,8 @@ export const COMPONENT_SCHEME = {
16
16
  'websocket': { emoji: '🔗', color: '#1ABC9C', name: 'WEBSOCKET' },
17
17
  'notification': { emoji: '🔔', color: '#E74C3C', name: 'NOTIFICATION' },
18
18
  'router': { emoji: '🛣️', color: '#3498DB', name: 'ROUTER' },
19
- 'cache': { emoji: '💨', color: '#95A5A6', name: 'CACHE' }
19
+ 'cache': { emoji: '💨', color: '#95A5A6', name: 'CACHE' },
20
+ 'devtools-ui': { emoji: '🎛️', color: '#8E44AD', name: 'DEVTOOLS' }
20
21
  };
21
22
 
22
23
  export const LEVEL_SCHEME = {
@@ -6,6 +6,7 @@
6
6
 
7
7
  import defaultConfig from './default-config.json' with { type: 'json' };
8
8
  import {COMPONENT_SCHEME, LEVEL_SCHEME} from './component-schemes.js';
9
+ import {metaLog} from '../utils/meta-logger.js';
9
10
 
10
11
  export class ConfigManager {
11
12
  constructor() {
@@ -25,11 +26,11 @@ export class ConfigManager {
25
26
 
26
27
  if (typeof configSource === 'string') {
27
28
  // Load from file path - handle all path formats
28
- console.log(`[JSG-LOGGER] Loading config from file: ${configSource}`);
29
+ metaLog(`[JSG-LOGGER] Loading config from file: ${configSource}`);
29
30
  externalConfig = await this._loadConfigFromPath(configSource);
30
31
  } else if (typeof configSource === 'object') {
31
32
  // Direct config object
32
- console.log('[JSG-LOGGER] Loading inline config object:', Object.keys(configSource));
33
+ metaLog('[JSG-LOGGER] Loading inline config object:', Object.keys(configSource));
33
34
  externalConfig = configSource;
34
35
  }
35
36
 
@@ -46,17 +47,17 @@ export class ConfigManager {
46
47
  // Log devtools activation status
47
48
  const finalDevtoolsEnabled = this.config.devtools?.enabled ?? false;
48
49
  if (finalDevtoolsEnabled !== devtoolsBefore) {
49
- console.log(`[JSG-LOGGER] DevTools ${finalDevtoolsEnabled ? 'ENABLED' : 'DISABLED'} via user config (was ${devtoolsBefore ? 'enabled' : 'disabled'} in defaults)`);
50
+ metaLog(`[JSG-LOGGER] DevTools ${finalDevtoolsEnabled ? 'ENABLED' : 'DISABLED'} via user config (was ${devtoolsBefore ? 'enabled' : 'disabled'} in defaults)`);
50
51
  if (finalDevtoolsEnabled) {
51
- console.log('[JSG-LOGGER] DevTools will be available when enableDevPanel() is called');
52
+ metaLog('[JSG-LOGGER] DevTools will be available when enableDevPanel() is called');
52
53
  }
53
54
  } else {
54
- console.log(`[JSG-LOGGER] DevTools status: ${finalDevtoolsEnabled ? 'ENABLED' : 'DISABLED'} (using default config)`);
55
+ metaLog(`[JSG-LOGGER] DevTools status: ${finalDevtoolsEnabled ? 'ENABLED' : 'DISABLED'} (using default config)`);
55
56
  }
56
57
 
57
58
  return this.config;
58
59
  } catch (error) {
59
- console.error('ConfigManager: Error loading configuration:', error);
60
+ metaError('ConfigManager: Error loading configuration:', error);
60
61
  return this.config; // Return default config on error
61
62
  }
62
63
  }
@@ -92,14 +93,14 @@ export class ConfigManager {
92
93
 
93
94
  if (config) {
94
95
  this.loadedPaths.push(configPath);
95
- console.log(`[JSG-LOGGER] Successfully loaded config from: ${configPath}`);
96
+ metaLog(`[JSG-LOGGER] Successfully loaded config from: ${configPath}`);
96
97
  return config;
97
98
  } else {
98
- console.warn(`[JSG-LOGGER] Could not load config from: ${configPath} - using defaults`);
99
+ metaLog(`[JSG-LOGGER] Could not load config from: ${configPath} - using defaults`);
99
100
  return {};
100
101
  }
101
102
  } catch (error) {
102
- console.warn(`[JSG-LOGGER] Failed to load config from ${configPath}:`, error.message);
103
+ metaLog(`[JSG-LOGGER] Failed to load config from ${configPath}:`, error.message);
103
104
  return {};
104
105
  }
105
106
  }
@@ -199,7 +200,7 @@ export class ConfigManager {
199
200
  if (config.environments) {
200
201
  // For now, just log that environment configs exist
201
202
  // TODO: Implement environment-based config selection
202
- console.log(`[JSG-LOGGER] Found environment configs for: ${Object.keys(config.environments).join(', ')}`);
203
+ metaLog(`[JSG-LOGGER] Found environment configs for: ${Object.keys(config.environments).join(', ')}`);
203
204
  }
204
205
 
205
206
  // Normalize component configurations
@@ -2,6 +2,7 @@
2
2
  "projectName": "JSG Logger",
3
3
  "globalLevel": "info",
4
4
  "autoRegister": true,
5
+ "metaLogging": true,
5
6
  "format": {
6
7
  "style": "brackets",
7
8
  "componentCase": "upper",
@@ -0,0 +1,5 @@
1
+ const __viteBrowserExternal = {};
2
+ export {
3
+ __viteBrowserExternal as default
4
+ };
5
+ //# sourceMappingURL=__vite-browser-external-2Ng8QIWW.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"__vite-browser-external-2Ng8QIWW.js","sources":["../__vite-browser-external"],"sourcesContent":["export default {}"],"names":[],"mappings":"AAAA,MAAA,wBAAe,CAAA;"}