@crimsonsunset/jsg-logger 1.8.3 → 1.8.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/README.md CHANGED
@@ -642,6 +642,68 @@ Our testing revealed that Pino's browser detection was interfering with custom f
642
642
  - Seamless Chrome extension integration
643
643
  - Zero compromises on functionality
644
644
 
645
+ ## 🔌 **External Transport Integration**
646
+
647
+ Connect any external log service (PostHog, Datadog, Sentry, etc.) by implementing the `LogTransport` interface and registering it with the singleton.
648
+
649
+ ### **Implementing a Transport**
650
+
651
+ ```typescript
652
+ import type { LogEntry, LogTransport } from '@crimsonsunset/jsg-logger';
653
+
654
+ class MyServiceTransport implements LogTransport {
655
+ level = 'warn' as const; // Only receive warn/error/fatal entries
656
+
657
+ send(entry: LogEntry): void {
658
+ if (!entry.isError || !entry.error) return;
659
+ myService.captureException(entry.error, {
660
+ component: entry.component,
661
+ message: entry.message,
662
+ ...entry.data,
663
+ });
664
+ }
665
+ }
666
+ ```
667
+
668
+ ### **Registering a Transport**
669
+
670
+ Use `JSGLogger.addTransport()` — safe to call at any point, including after module-level initialization:
671
+
672
+ ```typescript
673
+ import JSGLogger from '@crimsonsunset/jsg-logger';
674
+
675
+ // Works in Next.js instrumentation.ts, app startup, etc.
676
+ JSGLogger.addTransport(new MyServiceTransport());
677
+ ```
678
+
679
+ > **Why not `getInstanceSync(options)`?** The logger initializes itself at module evaluation time. Passing `transports` via `getInstanceSync()` after that point hits the reinit guard, which silently drops the options to protect already-registered transports. `addTransport()` bypasses this entirely.
680
+
681
+ ### **`LogEntry` Shape**
682
+
683
+ ```typescript
684
+ interface LogEntry {
685
+ level: LogLevel; // 'trace' | 'debug' | 'info' | 'warn' | 'error' | 'fatal'
686
+ levelNum: number; // 10 | 20 | 30 | 40 | 50 | 60
687
+ message: string;
688
+ component: string;
689
+ data?: Record<string, unknown>;
690
+ timestamp: number;
691
+ isError: boolean; // true when levelNum >= 50
692
+ error?: Error; // Extracted from data, data.err, or data.error
693
+ }
694
+ ```
695
+
696
+ The `error` field is auto-extracted: if you call `logger.error('msg', { error: new Error(...) })`, `entry.error` is set automatically.
697
+
698
+ ### **Post-Init Config Updates**
699
+
700
+ To update config (not transports) after initialization, use `configure()`:
701
+
702
+ ```typescript
703
+ logger.configure({ globalLevel: 'debug' });
704
+ // Merges config without touching registered transports
705
+ ```
706
+
645
707
  ## 🚀 Advanced Features
646
708
 
647
709
  ### **Automatic File Detection**
@@ -14,227 +14,44 @@
14
14
 
15
15
  ---
16
16
 
17
- **Date:** October 28, 2025
18
- **Session Goal:** 🎨 **Phase 7.1: Display Controls Panel** - Real-time preview with display toggles
19
- **Status:** ✅ **COMPLETE** - All display controls implemented and working
20
-
21
- ## 🎉 MAJOR ACCOMPLISHMENTS THIS SESSION
22
-
23
- ### ✅ Phase 7.1 Display Controls Complete (October 28, 2025) 🎨→✅
24
- - **📊 Live Preview in Sticky Header** - Real-time log preview that updates instantly
25
- - Shows sample log with all elements (timestamp, emoji, component, level, message, JSON, stack trace)
26
- - Updates immediately as controls are toggled
27
- - Stays visible while scrolling through other controls
28
- - Professional monospace styling matching console output
29
- - **⏱️ Timestamp Mode Control** - Button group with 4 modes
30
- - Absolute: `22:15:30.1` (milliseconds precision)
31
- - Readable: `10:15 PM` (12-hour format)
32
- - Relative: `2s ago` (time since)
33
- - Off: Hidden (no timestamp)
34
- - Active button highlighted with primary appearance
35
- - **🎛️ 6 Display Toggle Switches** - Granular control over log elements
36
- - Emoji: Show/hide level emoji (🌐, 🚨, etc.)
37
- - Component: Show/hide [COMPONENT-NAME] tags
38
- - Level Name: Show/hide level text (INFO, DEBUG, etc.)
39
- - Message: Always on (disabled - can't hide messages)
40
- - JSON Data: Show/hide context data trees
41
- - Stack Trace: Show/hide error stack traces
42
- - **✅ Bulk Operations** - Quick control actions
43
- - All On: Enable all display options
44
- - All Off: Disable all (except message)
45
- - Reset: Restore default settings
46
- - **🏗️ Clean Architecture** - Simplified layout with no sections
47
- - Removed all subheadings and dividers
48
- - Everything in one sticky container
49
- - Only Component Filters and Global Controls scroll
50
- - Single divider at the bottom of scrolling content
51
- - **🔧 API Integration** - Full logger.controls integration
52
- - `getDisplayConfig()` loads initial state
53
- - `getTimestampMode()` loads timestamp setting
54
- - `setDisplayOption()` applies changes to console
55
- - `setTimestampMode()` updates timestamp format
56
- - State managed via parent component callback
57
-
58
- ### **Technical Implementation**
59
- - **DisplayControls.jsx** (~350 lines)
60
- - Exported LogPreview component for header use
61
- - State management with `onStateChange` callback
62
- - Timestamp button group (replaced SegmentedControl)
63
- - 6 toggle switches in 2-column grid
64
- - Bulk control buttons
65
- - **PanelContainer.jsx** (updated)
66
- - LogPreview and DisplayControls in sticky header
67
- - State management for preview rendering
68
- - Single scrolling content area
69
- - Clean layout with one border at bottom
70
- - **ComponentFilters.jsx** (simplified)
71
- - Removed "🎚️ Log Levels" heading
72
- - Reduced spacing for compact layout
73
- - **GlobalControls.jsx** (simplified)
74
- - Removed "🌐 Global Controls" heading
75
- - Cleaner integration with overall layout
76
-
77
- ### **Real-World Impact**
78
- Phase 7.1 completes the foundation for comprehensive DevTools UI:
79
- - **Before**: Only basic component filtering, missing 80% of logger capabilities
80
- - **After**: Display controls expose all visual formatting options with live preview
81
- - **Next**: Phase 7.2 will add component management (emoji/color pickers, bulk operations)
82
-
83
- ## 🎉 PREVIOUS SESSION ACCOMPLISHMENTS
84
-
85
- ### ✅ Critical CLI Tool Fixes Complete (October 25, 2025) 🚨→✅
86
- - **🎨 CLI Context Data Display Fixed** - Replaced pino-colada with custom formatter
87
- - Context data now renders as indented tree in terminal
88
- - Shows all diagnostic information, not just messages
89
- - Example: version, build, command data visible with ├─ and └─ formatting
90
- - **🔧 Environment Detection Fixed** - Enhanced `isCLI()` with multi-signal detection
91
- - Now checks TTY, TERM env vars, and CI context
92
- - CLI tools no longer mis-detected as "server" mode
93
- - Fixes JSON output in terminal applications
94
- - **✨ Force Environment Override** - New `forceEnvironment` config option
95
- - Allows manual override of auto-detection
96
- - Works in inline config and logger-config.json
97
- - Essential for non-TTY contexts (piped output, automation)
98
- - **🎯 Custom Component Names** - Any component name now works
99
- - Auto-creation for undefined components
100
- - Sensible default styling (📦 emoji, gray color)
101
- - No longer restricted to COMPONENT_SCHEME
102
- - **📦 Version Bump** - Published v1.5.0 with all fixes
103
- - **🗑️ Dependency Cleanup** - Removed pino-colada (no longer needed)
104
- - **📚 Comprehensive Documentation** - Updated README, CHANGELOG
105
- - New Quick Start section for v1.5.0
106
- - Detailed forceEnvironment examples
107
- - Custom component usage patterns
108
- - Context data rendering examples
109
-
110
- ### **Real-World Impact**
111
- Fixed production blocker in macOS setup automation tool:
112
- - **Before**: JSON blobs in 30-minute terminal script → unusable
113
- - **After**: Pretty colored output with component organization → perfect UX
114
-
115
- ## 🎉 PREVIOUS SESSION ACCOMPLISHMENTS
116
-
117
- ### ✅ DevTools Integration Blocker RESOLVED (October 24, 2025)
118
- - **🔧 Import Path Fixed** - Installed JSG Logger as local file dependency
119
- - **📦 Dependencies Complete** - All parent dependencies installed (pino, pino-colada)
120
- - **🎯 ThemeProvider Fixed** - Corrected Evergreen UI ThemeProvider syntax
121
- - **🎛️ Panel Renders** - Floating button successfully appears on screen
122
- - **✅ Initialization Success** - DevTools panel loads without crashes
123
-
124
- ## 🎉 PREVIOUS SESSION ACCOMPLISHMENTS
125
-
126
- ### ✅ DevTools Phase 2 Infrastructure Complete
127
- - **🏗️ Dual Architecture** - Separated DevTools test app (`devtools/`) from main logger
128
- - **⚛️ Preact Application** - Complete test harness with comprehensive UI
129
- - **🎨 Evergreen UI Integration** - Professional design system with dark theme
130
- - **🔧 Build Pipeline** - Vite library mode with minification and source maps
131
- - **🎛️ Professional UI** - Beautiful gradient interface with glass-morphism cards
132
-
133
- ### ✅ Theme System & Component Migration
134
- - **🌙 Dark DevTools Theme** - Custom theme matching JSG Logger branding colors
135
- - **🎯 Component Replacement** - FloatingButton migrated to Evergreen Button + Badge
136
- - **📦 Theme Provider** - Proper Evergreen ThemeProvider integration
137
- - **🎨 Design Tokens** - Comprehensive color system and typography scales
138
- - **📱 Component Architecture** - Clean component structure with proper props
139
-
140
- ### ✅ Development Environment
141
- - **📂 Separate Package** - Independent devtools package.json with proper dependencies
142
- - **🔥 Hot Reload** - Vite dev server on port 5556 with live updates
143
- - **🔗 React Compatibility** - Evergreen UI working with Preact via compat aliases
144
- - **🛠️ Build Tools** - Complete development and production build pipeline
17
+ **Date:** March 28, 2026
18
+ **Session Goal:** 🔌 Add `addTransport()` API to fix reinit guard blocking transport registration
19
+ **Status:** ✅ **COMPLETE** - Published as v1.8.4
20
+
21
+ ## 🎉 ACCOMPLISHMENTS THIS SESSION
22
+
23
+ ### ✅ `addTransport()` API v1.8.3 v1.8.4
24
+
25
+ **Problem:** `jsg-logger` calls `getInstanceSync()` at module evaluation time (no options), initializing the singleton. When Next.js `instrumentation.ts` later called `getInstanceSync({ transports: [...] })`, the reinit guard (introduced in v1.8.2) silently dropped the options — including the transports. The PostHog transport was never registered.
26
+
27
+ **Fix:**
28
+ - Added `JSGLogger.addTransport(transport: LogTransport): void` static method
29
+ - Exposed on default export as `enhancedLoggers.addTransport`
30
+ - Updated `index.d.ts` with typings for both `JSGLogger` and `LoggerInstanceType`
31
+ - Updated CHANGELOG and README (`## 🔌 External Transport Integration` section)
32
+
33
+ **Consumer change in `set-times-app/src/instrumentation.ts`:**
34
+ ```typescript
35
+ // Before (broken - reinit guard silently dropped transports):
36
+ JSGLogger.getInstanceSync({ ...loggerConfig, transports: [new PostHogServerTransport(...)] });
37
+
38
+ // After (works at any lifecycle point):
39
+ JSGLogger.addTransport(new PostHogServerTransport(posthogServer, { level: 'warn' }));
40
+ ```
145
41
 
146
42
  ## 🎯 Current Status
147
43
 
148
- ### **DevTools Panel: WORKING with Minor Theme Issues** 🎉
149
- - **Panel Loads**: Successfully initializes and renders floating button
150
- - **Logger Integration**: JSG Logger imports and initializes correctly
151
- - **API Confirmed**: `enableDevPanel()` works, all 13 components loaded
152
- - **Theme Issue**: Text components missing theme.colors (non-blocking)
153
-
154
- ### **What's Working**
155
- - **JSG Logger** - Loads from `@crimsonsunset/jsg-logger` package (file: dependency)
156
- - ✅ **DevTools Panel** - Initializes and renders floating 🎛️ button
157
- - **Vite Dev Server** - Running on port 5556 with hot reload
158
- - ✅ **Test App** - All logger testing features functional
159
- - **Console Logging** - Beautiful formatted output with 13 components
160
-
161
- ### **Minor Issues Remaining** ⚠️
162
- - ⚠️ **Text Theme**: Evergreen Text components throw `undefined.colors` errors
163
- - ⚠️ **Panel Content**: May not be fully visible due to theme data issues
164
-
165
- ## 📋 IMMEDIATE PRIORITIES
166
-
167
- ### **🚀 Ready to Publish v1.5.0:**
168
- - [x] **Environment Detection** - Enhanced CLI detection with multi-signal check
169
- - [x] **Force Environment** - Config option to override auto-detection
170
- - [x] **Custom Components** - Auto-create loggers for any component name
171
- - [x] **Documentation** - README, CHANGELOG updated with v1.5.0 features
172
- - [x] **Version Bump** - Package version updated to 1.5.0
173
- - [ ] **Publish to NPM** - `npm run release:minor` when ready
174
-
175
- ### **🔧 DevTools Theme Fixes (Optional, Low Priority):**
176
- - [ ] **Fix Text Components** - Pass theme data correctly to Evergreen UI Text components
177
- - [ ] **Test Panel Interaction** - Click floating button and verify panel opens
178
- - [ ] **Verify Filtering** - Test component toggles affect console output
179
- - [ ] **Apply Custom Theme** - Implement devtools-theme.js once basic theme works
180
-
181
- ### **✅ COMPLETED THIS SESSION:**
182
- - [x] **CLI Context Data Display** - Custom formatter with tree rendering
183
- - [x] **Environment Detection Fixed** - Multi-signal CLI detection (TTY, TERM, CI check)
184
- - [x] **forceEnvironment Config** - Override auto-detection via config
185
- - [x] **Custom Component Names** - getComponent() auto-creates loggers
186
- - [x] **Config Loading Order** - Load config BEFORE environment detection
187
- - [x] **Dependency Cleanup** - Removed pino-colada from package
188
- - [x] **Documentation Complete** - README, CHANGELOG, version bump
189
-
190
- ## 🔮 Future Possibilities (Phase 10)
191
-
192
- ### **Developer Experience Enhancements** (Optional)
193
- **Current friction points identified:**
194
- - Manual logger-config.json creation
195
- - Component definition setup
196
- - New project onboarding
197
-
198
- **Potential solutions:**
199
- - **CLI Generator**: `npx create-jsg-logger-config`
200
- - **Project Templates**: Pre-built configs for React, Node.js, Chrome extensions
201
- - **Quick Start**: `JSGLogger.quickStart()` with auto-detection
202
- - **Better Errors**: Helpful validation and suggestions
203
-
204
- ### **Success Metrics for Phase 10:**
205
- - New project setup in < 30 seconds
206
- - Zero manual config creation needed
207
- - Out-of-the-box support for common project types
208
-
209
- ## 🎯 Next Session Possibilities
210
-
211
- ### **Option 1: Ship v1.2.0 and Monitor** (Recommended)
212
- - Publish the fully generic logger
213
- - Monitor adoption and gather feedback
214
- - Address any issues that emerge from real-world usage
215
-
216
- ### **Option 2: Phase 10 DX Enhancements** (Nice-to-have)
217
- - Build CLI config generator
218
- - Create project templates
219
- - Add quick-start modes
220
-
221
- ### **Option 3: Maintenance Mode**
222
- - JSG Logger is feature-complete for core logging needs
223
- - Focus on other projects while monitoring for bug reports
224
-
225
- ## 📊 Phase 9 Impact Summary
226
-
227
- ### **Generic Transformation:**
228
- - **Before**: 10+ hardcoded legacy components, CACP-specific references
229
- - **After**: 1 minimal 'core' component, 100% project-agnostic
230
- - **Breaking Changes**: Projects must define components in config
231
- - **Migration**: Simple config file creation for existing users
232
-
233
- ### **Code Quality:**
234
- - **Zero Legacy References**: Exhaustive cleanup completed
235
- - **Clean Architecture**: No hardcoded project assumptions
236
- - **Dynamic Systems**: Auto-generation replaces hardcoded logic
237
- - **Semantic Versioning**: v1.2.0 properly indicates breaking changes
238
-
239
- ### **Deployment Readiness:** ✅ PRODUCTION READY
240
- **The JSG Logger is now a completely generic, professional logging package that can be deployed in any JavaScript project with minimal configuration.**
44
+ - **v1.8.4 published** to npm
45
+ - `set-times-app` updated to `@crimsonsunset/jsg-logger@1.8.4`
46
+ - Server-side PostHog transport verified working
47
+
48
+ ## 📋 Immediate Priorities
49
+
50
+ - [ ] Verify no edge cases with `addTransport()` when called before any `getInstanceSync()`
51
+ - [ ] Consider adding transport removal API (`removeTransport`) if needed
52
+
53
+ ## 🔮 Future Possibilities
54
+
55
+ - **Transport removal**: `JSGLogger.removeTransport(transport)` for hot-unload scenarios
56
+ - **Transport listing**: `JSGLogger.getTransports()` for debugging
57
+ - **Typed transport levels**: Enforce `level` is a valid `LogLevel` at compile time
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@crimsonsunset/jsg-logger",
3
- "version": "1.8.3",
3
+ "version": "1.8.4",
4
4
  "type": "module",
5
5
  "description": "Multi-environment logger with smart detection, file-level overrides, and beautiful console formatting. Test it live: https://logger.joesangiorgio.com/",
6
6
  "main": "index.js",