hazo_logs 1.0.6 → 1.0.7
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 +82 -4
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -78,7 +78,8 @@ import { createLogApiHandler } from 'hazo_logs/ui/server';
|
|
|
78
78
|
|
|
79
79
|
const handler = createLogApiHandler();
|
|
80
80
|
|
|
81
|
-
|
|
81
|
+
// GET for log viewer, POST for client-side logging
|
|
82
|
+
export const { GET, POST } = handler;
|
|
82
83
|
```
|
|
83
84
|
|
|
84
85
|
**2. Create UI page** (`app/logs/page.tsx`):
|
|
@@ -116,21 +117,45 @@ Visit `/logs` in your app to view logs!
|
|
|
116
117
|
|
|
117
118
|
### Client-Side Logging (Browser)
|
|
118
119
|
|
|
119
|
-
For logging from client components (browser), use the client logger
|
|
120
|
+
For logging from client components (browser), use the client logger.
|
|
121
|
+
|
|
122
|
+
**1. Configure global defaults (recommended):**
|
|
123
|
+
|
|
124
|
+
Set up global configuration once at app initialization. This ensures all client loggers (including those from dependency packages) use the correct API endpoint:
|
|
125
|
+
|
|
126
|
+
```typescript
|
|
127
|
+
// app/providers.tsx or lib/hazo-init.ts
|
|
128
|
+
'use client';
|
|
129
|
+
import { configureClientLogger } from 'hazo_logs/ui';
|
|
130
|
+
|
|
131
|
+
// Configure once at app startup
|
|
132
|
+
configureClientLogger({
|
|
133
|
+
apiBasePath: '/api/logs', // Required: your log API endpoint
|
|
134
|
+
minLevel: 'info', // Optional: minimum log level
|
|
135
|
+
});
|
|
136
|
+
```
|
|
137
|
+
|
|
138
|
+
**2. Create loggers in your components:**
|
|
120
139
|
|
|
121
140
|
```typescript
|
|
122
141
|
'use client';
|
|
123
142
|
import { createClientLogger } from 'hazo_logs/ui';
|
|
124
143
|
|
|
144
|
+
// No need to specify apiBasePath - inherits from global config
|
|
125
145
|
const logger = createClientLogger({
|
|
126
146
|
packageName: 'my-app-client',
|
|
127
|
-
apiBasePath: '/api/logs',
|
|
128
147
|
});
|
|
129
148
|
|
|
130
149
|
logger.info('User clicked button', { buttonId: 'submit' });
|
|
131
150
|
logger.error('Failed to load data', { error: err.message });
|
|
132
151
|
```
|
|
133
152
|
|
|
153
|
+
**Why use global configuration?**
|
|
154
|
+
|
|
155
|
+
- Dependency packages (like `hazo_collab_forms`) automatically use your configured endpoint
|
|
156
|
+
- Avoids 404 errors from loggers using the wrong default path
|
|
157
|
+
- Single place to configure all client logging settings
|
|
158
|
+
|
|
134
159
|
## Important Notes
|
|
135
160
|
|
|
136
161
|
### Server-Only Core Logger
|
|
@@ -344,6 +369,40 @@ Read logs from files with filtering and pagination (server-side only).
|
|
|
344
369
|
|
|
345
370
|
### UI Exports (`hazo_logs/ui`)
|
|
346
371
|
|
|
372
|
+
#### `configureClientLogger(config: ClientLoggerGlobalConfig): void`
|
|
373
|
+
|
|
374
|
+
Configure global defaults for all client loggers. Call once at app initialization.
|
|
375
|
+
|
|
376
|
+
```typescript
|
|
377
|
+
configureClientLogger({
|
|
378
|
+
apiBasePath: '/api/logs', // Required
|
|
379
|
+
minLevel: 'info', // Optional
|
|
380
|
+
consoleOutput: true, // Optional
|
|
381
|
+
batchMode: false, // Optional
|
|
382
|
+
batchInterval: 5000, // Optional (ms)
|
|
383
|
+
});
|
|
384
|
+
```
|
|
385
|
+
|
|
386
|
+
#### `getClientLoggerConfig(): ClientLoggerGlobalConfig | undefined`
|
|
387
|
+
|
|
388
|
+
Get current global configuration (returns undefined if not configured).
|
|
389
|
+
|
|
390
|
+
#### `isClientLoggerConfigured(): boolean`
|
|
391
|
+
|
|
392
|
+
Check if global configuration has been set.
|
|
393
|
+
|
|
394
|
+
#### `createClientLogger(config?: ClientLoggerConfig): ClientLogger`
|
|
395
|
+
|
|
396
|
+
Create a client-side logger. Inherits from global config if set.
|
|
397
|
+
|
|
398
|
+
```typescript
|
|
399
|
+
const logger = createClientLogger({
|
|
400
|
+
packageName: 'my-component', // Tag for this logger
|
|
401
|
+
sessionId: 'sess_123', // Optional session tracking
|
|
402
|
+
reference: 'user_456', // Optional reference tracking
|
|
403
|
+
});
|
|
404
|
+
```
|
|
405
|
+
|
|
347
406
|
#### `LogViewerPage`
|
|
348
407
|
|
|
349
408
|
Main log viewer component.
|
|
@@ -374,7 +433,8 @@ Create Next.js API route handler.
|
|
|
374
433
|
**Returns:**
|
|
375
434
|
```typescript
|
|
376
435
|
{
|
|
377
|
-
GET: (request: Request) => Promise<Response
|
|
436
|
+
GET: (request: Request) => Promise<Response>, // Log viewer queries
|
|
437
|
+
POST: (request: Request) => Promise<Response>, // Client-side log ingestion
|
|
378
438
|
}
|
|
379
439
|
```
|
|
380
440
|
|
|
@@ -462,6 +522,24 @@ The log viewer UI requires `hazo_ui` package. Install it:
|
|
|
462
522
|
npm install hazo_ui
|
|
463
523
|
```
|
|
464
524
|
|
|
525
|
+
### POST /api/logs 404 errors
|
|
526
|
+
|
|
527
|
+
If you see repeated `POST /api/logs 404` errors, client loggers are using the default endpoint which doesn't match your API route location.
|
|
528
|
+
|
|
529
|
+
**Solution**: Configure the global client logger at app startup:
|
|
530
|
+
|
|
531
|
+
```typescript
|
|
532
|
+
// app/providers.tsx or lib/hazo-init.ts
|
|
533
|
+
'use client';
|
|
534
|
+
import { configureClientLogger } from 'hazo_logs/ui';
|
|
535
|
+
|
|
536
|
+
configureClientLogger({
|
|
537
|
+
apiBasePath: '/api/hazo_logs/logs', // Match your actual route
|
|
538
|
+
});
|
|
539
|
+
```
|
|
540
|
+
|
|
541
|
+
This ensures all client loggers (including those from dependency packages) use the correct endpoint.
|
|
542
|
+
|
|
465
543
|
## Contributing
|
|
466
544
|
|
|
467
545
|
Contributions are welcome! Please:
|