hazo_logs 1.0.14 → 1.2.1
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 +150 -4
- package/dist/lib/alert-triggers.d.ts +54 -0
- package/dist/lib/alert-triggers.d.ts.map +1 -0
- package/dist/lib/alert-triggers.js +97 -0
- package/dist/lib/alert-triggers.js.map +1 -0
- package/dist/lib/config_loader.d.ts.map +1 -1
- package/dist/lib/config_loader.js +1 -1
- package/dist/lib/config_loader.js.map +1 -1
- package/dist/lib/console-logger.d.ts +1 -0
- package/dist/lib/console-logger.d.ts.map +1 -1
- package/dist/lib/console-logger.js +11 -4
- package/dist/lib/console-logger.js.map +1 -1
- package/dist/lib/context/log-context.d.ts.map +1 -1
- package/dist/lib/context/log-context.js +4 -0
- package/dist/lib/context/log-context.js.map +1 -1
- package/dist/lib/global-error-handlers.d.ts +23 -0
- package/dist/lib/global-error-handlers.d.ts.map +1 -0
- package/dist/lib/global-error-handlers.js +45 -0
- package/dist/lib/global-error-handlers.js.map +1 -0
- package/dist/lib/hazo_logger.d.ts +9 -0
- package/dist/lib/hazo_logger.d.ts.map +1 -1
- package/dist/lib/hazo_logger.js +31 -0
- package/dist/lib/hazo_logger.js.map +1 -1
- package/dist/lib/log-reader.d.ts.map +1 -1
- package/dist/lib/log-reader.js +5 -4
- package/dist/lib/log-reader.js.map +1 -1
- package/dist/lib/log-tail.d.ts +11 -0
- package/dist/lib/log-tail.d.ts.map +1 -0
- package/dist/lib/log-tail.js +161 -0
- package/dist/lib/log-tail.js.map +1 -0
- package/dist/lib/package_logger.d.ts +1 -0
- package/dist/lib/package_logger.d.ts.map +1 -1
- package/dist/lib/package_logger.js +6 -4
- package/dist/lib/package_logger.js.map +1 -1
- package/dist/lib/types.d.ts +34 -24
- package/dist/lib/types.d.ts.map +1 -1
- package/dist/lib/universal-logger.d.ts.map +1 -1
- package/dist/lib/universal-logger.js +3 -0
- package/dist/lib/universal-logger.js.map +1 -1
- package/dist/lib/with-error-handler.d.ts +19 -0
- package/dist/lib/with-error-handler.d.ts.map +1 -0
- package/dist/lib/with-error-handler.js +76 -0
- package/dist/lib/with-error-handler.js.map +1 -0
- package/dist/server.d.ts +8 -0
- package/dist/server.d.ts.map +1 -1
- package/dist/server.js +5 -0
- package/dist/server.js.map +1 -1
- package/dist/ui/api/log-stream-api-handler.d.ts +14 -0
- package/dist/ui/api/log-stream-api-handler.d.ts.map +1 -0
- package/dist/ui/api/log-stream-api-handler.js +53 -0
- package/dist/ui/api/log-stream-api-handler.js.map +1 -0
- package/dist/ui/components/ErrorBoundary.d.ts +44 -0
- package/dist/ui/components/ErrorBoundary.d.ts.map +1 -0
- package/dist/ui/components/ErrorBoundary.js +56 -0
- package/dist/ui/components/ErrorBoundary.js.map +1 -0
- package/dist/ui/components/LogLevelBadge.d.ts.map +1 -1
- package/dist/ui/components/LogLevelBadge.js +1 -0
- package/dist/ui/components/LogLevelBadge.js.map +1 -1
- package/dist/ui/hooks/useErrorReporter.d.ts +16 -0
- package/dist/ui/hooks/useErrorReporter.d.ts.map +1 -0
- package/dist/ui/hooks/useErrorReporter.js +55 -0
- package/dist/ui/hooks/useErrorReporter.js.map +1 -0
- package/dist/ui/index.d.ts +4 -0
- package/dist/ui/index.d.ts.map +1 -1
- package/dist/ui/index.js +3 -0
- package/dist/ui/index.js.map +1 -1
- package/dist/ui/server.d.ts +2 -0
- package/dist/ui/server.d.ts.map +1 -1
- package/dist/ui/server.js +1 -0
- package/dist/ui/server.js.map +1 -1
- package/package.json +5 -1
package/README.md
CHANGED
|
@@ -11,6 +11,9 @@ A Winston-based logging library for Node.js/Next.js applications with a built-in
|
|
|
11
11
|
- **Package Tagging**: Automatically tag logs by package/module name
|
|
12
12
|
- **Daily Rotation**: Automatic log file rotation with configurable retention
|
|
13
13
|
- **Session Tracking**: Track logs across async operations with sessionId and reference
|
|
14
|
+
- **Fatal Level**: `logger.fatal()` for process-critical events, above `error` in severity
|
|
15
|
+
- **Context Fields**: Attach `scope` (dotted operation path) and `userId` to all logs via ALS context
|
|
16
|
+
- **Error Handling Surface**: `withErrorHandler`, `installGlobalErrorHandlers`, `registerAlertTrigger`, `<ErrorBoundary />`, `useErrorReporter` — structured error capture with correlationId tracking
|
|
14
17
|
- **Built-in UI**: React-based log viewer with filtering, sorting, and pagination
|
|
15
18
|
- **Zero Config**: Works out of the box with sensible defaults
|
|
16
19
|
- **Minimal Integration**: Add log viewer to your app with just 2 files (~6 lines of code)
|
|
@@ -249,22 +252,27 @@ import { createLogger, runWithLogContext } from 'hazo_logs/server';
|
|
|
249
252
|
|
|
250
253
|
const logger = createLogger('auth');
|
|
251
254
|
|
|
252
|
-
async function
|
|
255
|
+
async function handle_request(req) {
|
|
253
256
|
await runWithLogContext(
|
|
254
257
|
{
|
|
255
258
|
sessionId: req.sessionId,
|
|
256
259
|
reference: `user-${req.userId}`,
|
|
257
260
|
depth: 0,
|
|
261
|
+
scope: 'auth.login', // Fine-grained operation scope (dotted notation)
|
|
262
|
+
userId: req.userId, // User ID propagated to all log entries
|
|
258
263
|
},
|
|
259
264
|
async () => {
|
|
260
|
-
logger.info('Request started'); // Automatically includes
|
|
261
|
-
await
|
|
265
|
+
logger.info('Request started'); // Automatically includes all context fields
|
|
266
|
+
await process_request(req);
|
|
262
267
|
logger.info('Request completed');
|
|
263
268
|
}
|
|
264
269
|
);
|
|
265
270
|
}
|
|
266
271
|
```
|
|
267
272
|
|
|
273
|
+
Available context fields: `sessionId`, `reference`, `depth`, `scope`, `userId`. All fields present in the ALS context are automatically written to every `LogEntry` produced within the callback.
|
|
274
|
+
```
|
|
275
|
+
|
|
268
276
|
### Embedded Log Viewer
|
|
269
277
|
|
|
270
278
|
Use the log viewer as a sidebar component:
|
|
@@ -450,6 +458,7 @@ logger.info('Hello world');
|
|
|
450
458
|
|
|
451
459
|
```typescript
|
|
452
460
|
interface Logger {
|
|
461
|
+
fatal(message: string, data?: Record<string, unknown>): void;
|
|
453
462
|
error(message: string, data?: Record<string, unknown>): void;
|
|
454
463
|
warn(message: string, data?: Record<string, unknown>): void;
|
|
455
464
|
info(message: string, data?: Record<string, unknown>): void;
|
|
@@ -501,6 +510,52 @@ const logger = createClientLogger({
|
|
|
501
510
|
});
|
|
502
511
|
```
|
|
503
512
|
|
|
513
|
+
#### `ErrorBoundary`
|
|
514
|
+
|
|
515
|
+
React class component that catches render errors, generates a `correlationId`, and logs to the server via the client logger pipeline. The `fallback` render prop receives `{ error, correlationId, retry }`.
|
|
516
|
+
|
|
517
|
+
```tsx
|
|
518
|
+
import { ErrorBoundary } from 'hazo_logs/ui';
|
|
519
|
+
|
|
520
|
+
<ErrorBoundary
|
|
521
|
+
fallback={({ error, correlationId, retry }) => (
|
|
522
|
+
<div>
|
|
523
|
+
<p>Something went wrong. Reference: {correlationId}</p>
|
|
524
|
+
<button onClick={retry}>Retry</button>
|
|
525
|
+
</div>
|
|
526
|
+
)}
|
|
527
|
+
>
|
|
528
|
+
<MyComponent />
|
|
529
|
+
</ErrorBoundary>
|
|
530
|
+
```
|
|
531
|
+
|
|
532
|
+
Props: `fallback` (required), `onError?: (error, correlationId) => void`, `apiBasePath?: string`, `packageName?: string`.
|
|
533
|
+
|
|
534
|
+
**React 19 + Next.js 16 note:** Wrap state changes that may cause throws inside `startTransition()` to prevent the dev overlay from covering the error fallback. React 19 dev mode re-reports caught errors globally; transitions suppress this.
|
|
535
|
+
|
|
536
|
+
#### `useErrorReporter(options?)`
|
|
537
|
+
|
|
538
|
+
React hook for manual error reporting. Each method returns a correlationId string. Auto-attaches `route_path` (window.location.pathname) and `user_agent` to every entry.
|
|
539
|
+
|
|
540
|
+
```tsx
|
|
541
|
+
import { useErrorReporter } from 'hazo_logs/ui';
|
|
542
|
+
|
|
543
|
+
function MyComponent() {
|
|
544
|
+
const { reportError } = useErrorReporter({ userId: session?.user?.id });
|
|
545
|
+
|
|
546
|
+
const handle_action = async () => {
|
|
547
|
+
try {
|
|
548
|
+
await risky_operation();
|
|
549
|
+
} catch (err) {
|
|
550
|
+
const id = reportError(err, { component: 'MyComponent' });
|
|
551
|
+
show_toast(`Something went wrong. Reference: ${id}`);
|
|
552
|
+
}
|
|
553
|
+
};
|
|
554
|
+
}
|
|
555
|
+
```
|
|
556
|
+
|
|
557
|
+
Methods: `reportError(error, context?)`, `reportWarning(message, context?)`, `reportInfo(message, context?)`. Pass `options.userId` to attach `user_id` to all entries — no `hazo_auth` import required.
|
|
558
|
+
|
|
504
559
|
#### `LogViewerPage`
|
|
505
560
|
|
|
506
561
|
Main log viewer component.
|
|
@@ -562,6 +617,95 @@ const authHandler = withLogAuth(handler, async (request) => {
|
|
|
562
617
|
});
|
|
563
618
|
```
|
|
564
619
|
|
|
620
|
+
### Error Handling Surface (`hazo_logs/server`)
|
|
621
|
+
|
|
622
|
+
#### `withErrorHandler(handler)`
|
|
623
|
+
|
|
624
|
+
Wraps a Next.js App Router handler with structured error handling. Generates a `correlationId` (UUID), sets `X-Correlation-Id` on error responses, catches `HandledError` duck-typed throws returning structured JSON with the correct HTTP status, and catches generic `Error` logging at `fatal` and returning 500 (internal message never reaches the client).
|
|
625
|
+
|
|
626
|
+
```typescript
|
|
627
|
+
import { withErrorHandler } from 'hazo_logs/server';
|
|
628
|
+
|
|
629
|
+
export const GET = withErrorHandler(async (req: Request) => {
|
|
630
|
+
// Throw HandledError for structured 4xx/5xx responses:
|
|
631
|
+
throw { code: 'not_found', statusCode: 404, userMessage: 'Resource not found' };
|
|
632
|
+
// Throw Error for 500 — message never reaches client:
|
|
633
|
+
throw new Error('db connection failed');
|
|
634
|
+
});
|
|
635
|
+
```
|
|
636
|
+
|
|
637
|
+
Error response shape:
|
|
638
|
+
```json
|
|
639
|
+
{ "error": "Resource not found", "code": "not_found", "correlationId": "uuid" }
|
|
640
|
+
```
|
|
641
|
+
|
|
642
|
+
Level routing: 5xx throws → `error`, 4xx throws → `warn`, generic `Error` → `fatal`.
|
|
643
|
+
|
|
644
|
+
#### `installGlobalErrorHandlers(options?)`
|
|
645
|
+
|
|
646
|
+
Installs `process.on('unhandledRejection')` and `process.on('uncaughtException')`. Both log at `fatal` with a correlationId, call optional `onFatal`, then wait 500ms and call `process.exit(1)`. Call once at process startup (e.g. `instrumentation.ts`).
|
|
647
|
+
|
|
648
|
+
```typescript
|
|
649
|
+
import { installGlobalErrorHandlers } from 'hazo_logs/server';
|
|
650
|
+
|
|
651
|
+
installGlobalErrorHandlers({
|
|
652
|
+
onFatal: async (err) => {
|
|
653
|
+
await alertOpsTeam(err);
|
|
654
|
+
},
|
|
655
|
+
exitOnUncaught: true, // default
|
|
656
|
+
});
|
|
657
|
+
```
|
|
658
|
+
|
|
659
|
+
Options: `onFatal?: (err: Error) => void | Promise<void>`, `exitOnUncaught?: boolean`.
|
|
660
|
+
|
|
661
|
+
#### `registerAlertTrigger(config)`
|
|
662
|
+
|
|
663
|
+
Sliding-window alert trigger via `hazo_notify` (optional peer dep). Hooks into `HazoLogger.addLogHook` and fires when a match threshold is crossed within a time window. Returns an unregister function.
|
|
664
|
+
|
|
665
|
+
```typescript
|
|
666
|
+
import { registerAlertTrigger } from 'hazo_logs/server';
|
|
667
|
+
|
|
668
|
+
const unregister = registerAlertTrigger({
|
|
669
|
+
id: 'payment_errors',
|
|
670
|
+
match: { level: 'error', scopePrefix: 'payment.' },
|
|
671
|
+
threshold: { count: 3, windowMs: 60_000 },
|
|
672
|
+
notify: {
|
|
673
|
+
kind: 'ops.payment_error',
|
|
674
|
+
scopeId: 'my_app',
|
|
675
|
+
recipientUserIds: ['ops-user-uuid'],
|
|
676
|
+
surfaces: ['email'],
|
|
677
|
+
},
|
|
678
|
+
});
|
|
679
|
+
// Call unregister() to stop listening
|
|
680
|
+
```
|
|
681
|
+
|
|
682
|
+
`match` supports: `level`, `scopePrefix`, `message_contains`. Set `threshold.count` to `0` to fire on every match. `recipientUserIds` can be a static array or `(entry) => string[]`.
|
|
683
|
+
|
|
684
|
+
## Live tail (v1.1+)
|
|
685
|
+
|
|
686
|
+
`tailLogs` watches the active rotating log file and emits new entries as they are written. Filters mirror `readLogs`. Use it directly for in-process consumers:
|
|
687
|
+
|
|
688
|
+
```ts
|
|
689
|
+
import { tailLogs } from "hazo_logs/server";
|
|
690
|
+
|
|
691
|
+
const ctrl = new AbortController();
|
|
692
|
+
for await (const entry of tailLogs({ reference: ["job-123"], signal: ctrl.signal })) {
|
|
693
|
+
console.log(entry.message);
|
|
694
|
+
}
|
|
695
|
+
// later: ctrl.abort();
|
|
696
|
+
```
|
|
697
|
+
|
|
698
|
+
For SSE-over-HTTP (admin UIs, dashboards), use `createLogStreamApiHandler`:
|
|
699
|
+
|
|
700
|
+
```ts
|
|
701
|
+
import { createLogStreamApiHandler } from "hazo_logs/ui/server";
|
|
702
|
+
|
|
703
|
+
// Next.js app router
|
|
704
|
+
export const GET = createLogStreamApiHandler({ reference: ["job-123"] });
|
|
705
|
+
```
|
|
706
|
+
|
|
707
|
+
Clients consume via the standard `EventSource` API. The stream closes when the client disconnects.
|
|
708
|
+
|
|
565
709
|
## Log File Format
|
|
566
710
|
|
|
567
711
|
Logs are stored as newline-delimited JSON:
|
|
@@ -572,7 +716,7 @@ Logs are stored as newline-delimited JSON:
|
|
|
572
716
|
|
|
573
717
|
**Fields:**
|
|
574
718
|
- `timestamp` - ISO 8601 timestamp
|
|
575
|
-
- `level` - Log level (error, warn, info, debug)
|
|
719
|
+
- `level` - Log level (fatal, error, warn, info, debug)
|
|
576
720
|
- `package` - Package name from createLogger
|
|
577
721
|
- `message` - Log message
|
|
578
722
|
- `filename` - Source file name
|
|
@@ -581,6 +725,8 @@ Logs are stored as newline-delimited JSON:
|
|
|
581
725
|
- `sessionId` - Optional session ID from context
|
|
582
726
|
- `reference` - Optional reference from context
|
|
583
727
|
- `depth` - Optional call depth from context
|
|
728
|
+
- `scope` - Optional operation scope from context (dotted notation, e.g. `"payment.checkout.refund"`)
|
|
729
|
+
- `userId` - Optional user ID from ALS context
|
|
584
730
|
- `data` - Optional additional data
|
|
585
731
|
|
|
586
732
|
## UI Screenshots
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* registerAlertTrigger — fires hazo_notify dispatch when log volume crosses a threshold.
|
|
3
|
+
*
|
|
4
|
+
* Requires hazo_notify to be installed (optional peer dep).
|
|
5
|
+
* Sliding window state is in-memory — resets on process restart.
|
|
6
|
+
*/
|
|
7
|
+
import type { LogEntry, LogLevel } from './types.js';
|
|
8
|
+
export interface AlertTriggerMatch {
|
|
9
|
+
/** Only match entries at this level or above */
|
|
10
|
+
level?: LogLevel;
|
|
11
|
+
/** Only match entries whose `scope` starts with this prefix */
|
|
12
|
+
scopePrefix?: string;
|
|
13
|
+
/** Only match entries whose message contains this substring */
|
|
14
|
+
message_contains?: string;
|
|
15
|
+
}
|
|
16
|
+
export interface AlertTriggerNotify {
|
|
17
|
+
/** hazo_notify event_type */
|
|
18
|
+
kind: string;
|
|
19
|
+
/** hazo_notify scope_id */
|
|
20
|
+
scopeId: string;
|
|
21
|
+
/** Static list OR function returning IDs from the triggering log entry */
|
|
22
|
+
recipientUserIds: string[] | ((entry: LogEntry) => string[]);
|
|
23
|
+
/** hazo_notify surfaces (e.g. ['email', 'bell']) */
|
|
24
|
+
surfaces?: string[];
|
|
25
|
+
}
|
|
26
|
+
export interface AlertTriggerConfig {
|
|
27
|
+
id: string;
|
|
28
|
+
match: AlertTriggerMatch;
|
|
29
|
+
threshold: {
|
|
30
|
+
/** Number of matching events required to fire */
|
|
31
|
+
count: number;
|
|
32
|
+
/** Sliding window duration in ms. 0 = fire on every match (no window) */
|
|
33
|
+
windowMs: number;
|
|
34
|
+
};
|
|
35
|
+
notify: AlertTriggerNotify;
|
|
36
|
+
}
|
|
37
|
+
/**
|
|
38
|
+
* Register an alert trigger. Returns an unregister function.
|
|
39
|
+
*
|
|
40
|
+
* @example
|
|
41
|
+
* const unregister = registerAlertTrigger({
|
|
42
|
+
* id: 'payment_errors',
|
|
43
|
+
* match: { level: 'error', scopePrefix: 'payment.' },
|
|
44
|
+
* threshold: { count: 1, windowMs: 0 },
|
|
45
|
+
* notify: {
|
|
46
|
+
* kind: 'ops.payment_error',
|
|
47
|
+
* scopeId: 'my_app',
|
|
48
|
+
* recipientUserIds: ['ops-user-uuid'],
|
|
49
|
+
* surfaces: ['email'],
|
|
50
|
+
* },
|
|
51
|
+
* });
|
|
52
|
+
*/
|
|
53
|
+
export declare function registerAlertTrigger(config: AlertTriggerConfig): () => void;
|
|
54
|
+
//# sourceMappingURL=alert-triggers.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"alert-triggers.d.ts","sourceRoot":"","sources":["../../src/lib/alert-triggers.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAGH,OAAO,KAAK,EAAE,QAAQ,EAAE,QAAQ,EAAE,MAAM,YAAY,CAAC;AAErD,MAAM,WAAW,iBAAiB;IAChC,gDAAgD;IAChD,KAAK,CAAC,EAAE,QAAQ,CAAC;IACjB,+DAA+D;IAC/D,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,+DAA+D;IAC/D,gBAAgB,CAAC,EAAE,MAAM,CAAC;CAC3B;AAED,MAAM,WAAW,kBAAkB;IACjC,6BAA6B;IAC7B,IAAI,EAAE,MAAM,CAAC;IACb,2BAA2B;IAC3B,OAAO,EAAE,MAAM,CAAC;IAChB,0EAA0E;IAC1E,gBAAgB,EAAE,MAAM,EAAE,GAAG,CAAC,CAAC,KAAK,EAAE,QAAQ,KAAK,MAAM,EAAE,CAAC,CAAC;IAC7D,oDAAoD;IACpD,QAAQ,CAAC,EAAE,MAAM,EAAE,CAAC;CACrB;AAED,MAAM,WAAW,kBAAkB;IACjC,EAAE,EAAE,MAAM,CAAC;IACX,KAAK,EAAE,iBAAiB,CAAC;IACzB,SAAS,EAAE;QACT,iDAAiD;QACjD,KAAK,EAAE,MAAM,CAAC;QACd,yEAAyE;QACzE,QAAQ,EAAE,MAAM,CAAC;KAClB,CAAC;IACF,MAAM,EAAE,kBAAkB,CAAC;CAC5B;AA0DD;;;;;;;;;;;;;;;GAeG;AACH,wBAAgB,oBAAoB,CAAC,MAAM,EAAE,kBAAkB,GAAG,MAAM,IAAI,CA2B3E"}
|
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* registerAlertTrigger — fires hazo_notify dispatch when log volume crosses a threshold.
|
|
3
|
+
*
|
|
4
|
+
* Requires hazo_notify to be installed (optional peer dep).
|
|
5
|
+
* Sliding window state is in-memory — resets on process restart.
|
|
6
|
+
*/
|
|
7
|
+
import { HazoLogger } from './hazo_logger.js';
|
|
8
|
+
const HAZO_LOG_LEVEL_PRIORITY = {
|
|
9
|
+
fatal: 0,
|
|
10
|
+
error: 1,
|
|
11
|
+
warn: 2,
|
|
12
|
+
info: 3,
|
|
13
|
+
debug: 4,
|
|
14
|
+
};
|
|
15
|
+
function matchesTrigger(entry, match) {
|
|
16
|
+
if (match.level) {
|
|
17
|
+
// Entry level must be at least as severe as the match level
|
|
18
|
+
if (HAZO_LOG_LEVEL_PRIORITY[entry.level] > HAZO_LOG_LEVEL_PRIORITY[match.level]) {
|
|
19
|
+
return false;
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
if (match.scopePrefix && !entry.scope?.startsWith(match.scopePrefix)) {
|
|
23
|
+
return false;
|
|
24
|
+
}
|
|
25
|
+
if (match.message_contains && !entry.message.includes(match.message_contains)) {
|
|
26
|
+
return false;
|
|
27
|
+
}
|
|
28
|
+
return true;
|
|
29
|
+
}
|
|
30
|
+
async function fireNotification(config, entry) {
|
|
31
|
+
let dispatcher;
|
|
32
|
+
try {
|
|
33
|
+
dispatcher = await import('hazo_notify/dispatcher');
|
|
34
|
+
}
|
|
35
|
+
catch {
|
|
36
|
+
console.error(`[hazo_logs] Alert trigger "${config.id}" fired but hazo_notify is not installed. ` +
|
|
37
|
+
'Add hazo_notify as a dependency to receive alert notifications.');
|
|
38
|
+
return;
|
|
39
|
+
}
|
|
40
|
+
const recipientUserIds = Array.isArray(config.notify.recipientUserIds)
|
|
41
|
+
? config.notify.recipientUserIds
|
|
42
|
+
: config.notify.recipientUserIds(entry);
|
|
43
|
+
await dispatcher.dispatch({
|
|
44
|
+
scope_id: config.notify.scopeId,
|
|
45
|
+
event_type: config.notify.kind,
|
|
46
|
+
subject_id: entry.timestamp,
|
|
47
|
+
recipient_user_ids: recipientUserIds,
|
|
48
|
+
surfaces: config.notify.surfaces,
|
|
49
|
+
payloads: {
|
|
50
|
+
log_level: entry.level,
|
|
51
|
+
log_package: entry.package,
|
|
52
|
+
log_message: entry.message,
|
|
53
|
+
log_scope: entry.scope,
|
|
54
|
+
log_timestamp: entry.timestamp,
|
|
55
|
+
},
|
|
56
|
+
});
|
|
57
|
+
}
|
|
58
|
+
/**
|
|
59
|
+
* Register an alert trigger. Returns an unregister function.
|
|
60
|
+
*
|
|
61
|
+
* @example
|
|
62
|
+
* const unregister = registerAlertTrigger({
|
|
63
|
+
* id: 'payment_errors',
|
|
64
|
+
* match: { level: 'error', scopePrefix: 'payment.' },
|
|
65
|
+
* threshold: { count: 1, windowMs: 0 },
|
|
66
|
+
* notify: {
|
|
67
|
+
* kind: 'ops.payment_error',
|
|
68
|
+
* scopeId: 'my_app',
|
|
69
|
+
* recipientUserIds: ['ops-user-uuid'],
|
|
70
|
+
* surfaces: ['email'],
|
|
71
|
+
* },
|
|
72
|
+
* });
|
|
73
|
+
*/
|
|
74
|
+
export function registerAlertTrigger(config) {
|
|
75
|
+
// Per-trigger sliding window: array of event timestamps
|
|
76
|
+
const eventTimestamps = [];
|
|
77
|
+
const unregister = HazoLogger.addLogHook((entry) => {
|
|
78
|
+
if (!matchesTrigger(entry, config.match))
|
|
79
|
+
return;
|
|
80
|
+
const now = Date.now();
|
|
81
|
+
// Prune events outside the window (skip for windowMs = 0)
|
|
82
|
+
if (config.threshold.windowMs > 0) {
|
|
83
|
+
const cutoff = now - config.threshold.windowMs;
|
|
84
|
+
while (eventTimestamps.length > 0 && eventTimestamps[0] < cutoff) {
|
|
85
|
+
eventTimestamps.shift();
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
eventTimestamps.push(now);
|
|
89
|
+
if (eventTimestamps.length >= config.threshold.count) {
|
|
90
|
+
// Reset window before async fire so re-entrant logs don't double-fire
|
|
91
|
+
eventTimestamps.length = 0;
|
|
92
|
+
void fireNotification(config, entry);
|
|
93
|
+
}
|
|
94
|
+
});
|
|
95
|
+
return unregister;
|
|
96
|
+
}
|
|
97
|
+
//# sourceMappingURL=alert-triggers.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"alert-triggers.js","sourceRoot":"","sources":["../../src/lib/alert-triggers.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAC;AAmC9C,MAAM,uBAAuB,GAA6B;IACxD,KAAK,EAAE,CAAC;IACR,KAAK,EAAE,CAAC;IACR,IAAI,EAAE,CAAC;IACP,IAAI,EAAE,CAAC;IACP,KAAK,EAAE,CAAC;CACT,CAAC;AAEF,SAAS,cAAc,CAAC,KAAe,EAAE,KAAwB;IAC/D,IAAI,KAAK,CAAC,KAAK,EAAE,CAAC;QAChB,4DAA4D;QAC5D,IAAI,uBAAuB,CAAC,KAAK,CAAC,KAAK,CAAC,GAAG,uBAAuB,CAAC,KAAK,CAAC,KAAK,CAAC,EAAE,CAAC;YAChF,OAAO,KAAK,CAAC;QACf,CAAC;IACH,CAAC;IACD,IAAI,KAAK,CAAC,WAAW,IAAI,CAAC,KAAK,CAAC,KAAK,EAAE,UAAU,CAAC,KAAK,CAAC,WAAW,CAAC,EAAE,CAAC;QACrE,OAAO,KAAK,CAAC;IACf,CAAC;IACD,IAAI,KAAK,CAAC,gBAAgB,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,QAAQ,CAAC,KAAK,CAAC,gBAAgB,CAAC,EAAE,CAAC;QAC9E,OAAO,KAAK,CAAC;IACf,CAAC;IACD,OAAO,IAAI,C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AAK,EAAE,MAAM,CAAC,KAAK,CAAC;YAAE,OAAO;QAEjD,MAAM,GAAG,GAAG,IAAI,CAAC,GAAG,EAAE,CAAC;QAEvB,0DAA0D;QAC1D,IAAI,MAAM,CAAC,SAAS,CAAC,QAAQ,GAAG,CAAC,EAAE,CAAC;YAClC,MAAM,MAAM,GAAG,GAAG,GAAG,MAAM,CAAC,SAAS,CAAC,QAAQ,CAAC;YAC/C,OAAO,eAAe,CAAC,MAAM,GAAG,CAAC,IAAI,eAAe,CAAC,CAAC,CAAC,GAAG,MAAM,EAAE,CAAC;gBACjE,eAAe,CAAC,KAAK,EAAE,CAAC;YAC1B,CAAC;QACH,CAAC;QAED,eAAe,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;QAE1B,IAAI,eAAe,CAAC,MAAM,IAAI,MAAM,CAAC,SAAS,CAAC,KAAK,EAAE,CAAC;YACrD,sEAAsE;YACtE,eAAe,CAAC,MAAM,GAAG,CAAC,CAAC;YAC3B,KAAK,gBAAgB,CAAC,MAAM,EAAE,KAAK,CAAC,CAAC;QACvC,CAAC;IACH,CAAC,CAAC,CAAC;IAEH,OAAO,UAAU,CAAC;AACpB,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"config_loader.d.ts","sourceRoot":"","sources":["../../src/lib/config_loader.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAKH,OAAO,KAAK,EAAE,aAAa,
|
|
1
|
+
{"version":3,"file":"config_loader.d.ts","sourceRoot":"","sources":["../../src/lib/config_loader.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAKH,OAAO,KAAK,EAAE,aAAa,EAAkB,MAAM,YAAY,CAAC;AAQhE;;;;GAIG;AACH,wBAAgB,UAAU,CAAC,UAAU,CAAC,EAAE,MAAM,GAAG,aAAa,CAmC7D"}
|
|
@@ -71,7 +71,7 @@ function findConfigFile() {
|
|
|
71
71
|
return null;
|
|
72
72
|
}
|
|
73
73
|
/**
|
|
74
|
-
* Validate and return a valid log level
|
|
74
|
+
* Validate and return a valid config log level (fatal excluded — not a valid min-level)
|
|
75
75
|
*/
|
|
76
76
|
function validateLogLevel(level) {
|
|
77
77
|
const validLevels = ['error', 'warn', 'info', 'debug'];
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"config_loader.js","sourceRoot":"","sources":["../../src/lib/config_loader.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EAAE,MAAM,IAAI,CAAC;AACpB,OAAO,IAAI,MAAM,MAAM,CAAC;AACxB,OAAO,GAAG,MAAM,KAAK,CAAC;AAEtB,OAAO,EAAE,cAAc,EAAE,MAAM,sBAAsB,CAAC;AAEtD,MAAM,eAAe,GAAG,6BAA6B,CAAC;AAEtD,0DAA0D;AAC1D,IAAI,qBAAqB,GAAG,KAAK,CAAC;AAElC;;;;GAIG;AACH,MAAM,UAAU,UAAU,CAAC,UAAmB;IAC5C,MAAM,YAAY,GAAG,UAAU,IAAI,cAAc,EAAE,CAAC;IAEpD,IAAI,CAAC,YAAY,IAAI,CAAC,EAAE,CAAC,UAAU,CAAC,YAAY,CAAC,EAAE,CAAC;QAClD,IAAI,CAAC,qBAAqB,EAAE,CAAC;YAC3B,qBAAqB,GAAG,IAAI,CAAC;YAC7B,OAAO,CAAC,IAAI,CACV,qDAAqD,eAAe,gBAAgB,CACrF,CAAC;QACJ,CAAC;QACD,OAAO,EAAE,GAAG,cAAc,EAAE,CAAC;IAC/B,CAAC;IAED,IAAI,CAAC;QACH,MAAM,OAAO,GAAG,EAAE,CAAC,YAAY,CAAC,YAAY,EAAE,OAAO,CAAC,CAAC;QACvD,MAAM,MAAM,GAAG,GAAG,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC;QAClC,MAAM,WAAW,GAAG,MAAM,CAAC,WAAW,CAAC,IAAI,EAAE,CAAC;QAE9C,OAAO;YACL,aAAa,EAAE,WAAW,CAAC,aAAa,IAAI,cAAc,CAAC,aAAa;YACxE,SAAS,EAAE,gBAAgB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AC,OAAO,CAAC,GAAG,EAAE,EAAE,IAAI,EAAE,IAAI,CAAC;QACpC,IAAI,CAAC,IAAI,CAAC,OAAO,CAAC,GAAG,EAAE,EAAE,IAAI,EAAE,IAAI,EAAE,IAAI,CAAC;KAC3C,CAAC;AACJ,CAAC;AAED;;GAEG;AACH,SAAS,cAAc;IACrB,MAAM,WAAW,GAAG,cAAc,EAAE,CAAC;IAErC,KAAK,MAAM,UAAU,IAAI,WAAW,EAAE,CAAC;QACrC,MAAM,UAAU,GAAG,IAAI,CAAC,IAAI,CAAC,UAAU,EAAE,eAAe,CAAC,CAAC;QAC1D,IAAI,EAAE,CAAC,UAAU,CAAC,UAAU,CAAC,EAAE,CAAC;YAC9B,OAAO,UAAU,CAAC;QACpB,CAAC;IACH,CAAC;IAED,OAAO,IAAI,CAAC;AACd,CAAC;AAED;;GAEG;AACH,SAAS,gBAAgB,CAAC,KAAyB;IACjD,MAAM,WAAW,GAAqB,CAAC,OAAO,EAAE,MAAM,EAAE,MAAM,EAAE,OAAO,CAAC,CAAC;IACzE,OAAO,WAAW,CAAC,QAAQ,CAAC,KAAuB,CAAC,CAAC,CAAC,CAAE,KAAwB,CAAC,CAAC,CAAC,cAAc,CAAC,SAAS,CAAC;AAC9G,CAAC;AAED;;;GAGG;AACH,SAAS,SAAS,CAAC,KAAmC,EAAE,YAAqB;IAC3E,IAAI,KAAK,KAAK,SAAS;QAAE,OAAO,YAAY,CAAC;IAC7C,IAAI,OAAO,KAAK,KAAK,SAAS;QAAE,OAAO,KAAK,CAAC;IAC7C,MAAM,QAAQ,GAAG,MAAM,CAAC,KAAK,CAAC,CAAC,WAAW,EAAE,CAAC;IAC7C,OAAO,QAAQ,KAAK,MAAM,IAAI,QAAQ,KAAK,GAAG,CAAC;AACjD,CAAC"}
|
|
@@ -18,6 +18,7 @@ export declare class ConsoleLogger implements Logger {
|
|
|
18
18
|
constructor(packageName: string, minLevel?: LogLevel, on_log?: (level: string, message: string, data?: Record<string, unknown>) => void);
|
|
19
19
|
private shouldLog;
|
|
20
20
|
private formatMessage;
|
|
21
|
+
fatal(message: string, data?: LogData): void;
|
|
21
22
|
error(message: string, data?: LogData): void;
|
|
22
23
|
warn(message: string, data?: LogData): void;
|
|
23
24
|
info(message: string, data?: LogData): void;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"console-logger.d.ts","sourceRoot":"","sources":["../../src/lib/console-logger.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,OAAO,KAAK,EAAE,MAAM,EAAE,OAAO,EAAE,QAAQ,EAAE,MAAM,YAAY,CAAC;AAE5D,eAAO,MAAM,kBAAkB,EAAE,MAAM,CAAC,QAAQ,EAAE,MAAM,
|
|
1
|
+
{"version":3,"file":"console-logger.d.ts","sourceRoot":"","sources":["../../src/lib/console-logger.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,OAAO,KAAK,EAAE,MAAM,EAAE,OAAO,EAAE,QAAQ,EAAE,MAAM,YAAY,CAAC;AAE5D,eAAO,MAAM,kBAAkB,EAAE,MAAM,CAAC,QAAQ,EAAE,MAAM,CAMvD,CAAC;AAEF;;;GAGG;AACH,qBAAa,aAAc,YAAW,MAAM;IAC1C,OAAO,CAAC,WAAW,CAAS;IAC5B,OAAO,CAAC,QAAQ,CAAW;IAC3B,OAAO,CAAC,MAAM,CAAC,CAA2E;gBAE9E,WAAW,EAAE,MAAM,EAAE,QAAQ,GAAE,QAAkB,EAAE,MAAM,CAAC,EAAE,CAAC,KAAK,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,EAAE,IAAI,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,KAAK,IAAI;IAMhJ,OAAO,CAAC,SAAS;IAIjB,OAAO,CAAC,aAAa;IAKrB,KAAK,CAAC,OAAO,EAAE,MAAM,EAAE,IAAI,CAAC,EAAE,OAAO,GAAG,IAAI;IAO5C,KAAK,CAAC,OAAO,EAAE,MAAM,EAAE,IAAI,CAAC,EAAE,OAAO,GAAG,IAAI;IAO5C,IAAI,CAAC,OAAO,EAAE,MAAM,EAAE,IAAI,CAAC,EAAE,OAAO,GAAG,IAAI;IAO3C,IAAI,CAAC,OAAO,EAAE,MAAM,EAAE,IAAI,CAAC,EAAE,OAAO,GAAG,IAAI;IAO3C,KAAK,CAAC,OAAO,EAAE,MAAM,EAAE,IAAI,CAAC,EAAE,OAAO,GAAG,IAAI;CAM7C"}
|
|
@@ -6,10 +6,11 @@
|
|
|
6
6
|
* so it is safe for both server and client environments.
|
|
7
7
|
*/
|
|
8
8
|
export const LOG_LEVEL_PRIORITY = {
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
9
|
+
fatal: 0,
|
|
10
|
+
error: 1,
|
|
11
|
+
warn: 2,
|
|
12
|
+
info: 3,
|
|
13
|
+
debug: 4,
|
|
13
14
|
};
|
|
14
15
|
/**
|
|
15
16
|
* Console-based logger for client-side use
|
|
@@ -31,6 +32,12 @@ export class ConsoleLogger {
|
|
|
31
32
|
const timestamp = new Date().toISOString();
|
|
32
33
|
return `[${timestamp}] [${level.toUpperCase()}] [${this.packageName}] ${message}`;
|
|
33
34
|
}
|
|
35
|
+
fatal(message, data) {
|
|
36
|
+
if (this.shouldLog('fatal')) {
|
|
37
|
+
console.error(this.formatMessage('fatal', message), data ?? '');
|
|
38
|
+
this.on_log?.('fatal', message, data);
|
|
39
|
+
}
|
|
40
|
+
}
|
|
34
41
|
error(message, data) {
|
|
35
42
|
if (this.shouldLog('error')) {
|
|
36
43
|
console.error(this.formatMessage('error', message), data ?? '');
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"console-logger.js","sourceRoot":"","sources":["../../src/lib/console-logger.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAIH,MAAM,CAAC,MAAM,kBAAkB,GAA6B;IAC1D,KAAK,EAAE,CAAC;IACR,IAAI,EAAE,CAAC;IACP,IAAI,EAAE,CAAC;IACP,KAAK,EAAE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I,UAAU,GAAG,SAAS,CAGtD;AAED;;;;;;;GAOG;AACH,wBAAgB,WAAW,CAAC,CAAC,EAAE,SAAS,EAAE,MAAM,EAAE,EAAE,EAAE,MAAM,CAAC,GAAG,CAAC,CAEhE;AAED;;;;;;;GAOG;AACH,wBAAgB,WAAW,CAAC,CAAC,EAAE,SAAS,EAAE,MAAM,EAAE,SAAS,EAAE,MAAM,EAAE,EAAE,EAAE,MAAM,CAAC,GAAG,CAAC,CAEnF"}
|
|
@@ -113,6 +113,8 @@ export function runWithLogContext(context, fn) {
|
|
|
113
113
|
// Use provided values or inherit from parent
|
|
114
114
|
sessionId: context.sessionId ?? parentContext?.sessionId,
|
|
115
115
|
reference: context.reference ?? parentContext?.reference,
|
|
116
|
+
userId: context.userId ?? parentContext?.userId,
|
|
117
|
+
scope: context.scope ?? parentContext?.scope,
|
|
116
118
|
// Auto-increment depth
|
|
117
119
|
depth: parentDepth + 1,
|
|
118
120
|
};
|
|
@@ -135,6 +137,8 @@ export function runWithLogContextAsync(context, fn) {
|
|
|
135
137
|
const newContext = {
|
|
136
138
|
sessionId: context.sessionId ?? parentContext?.sessionId,
|
|
137
139
|
reference: context.reference ?? parentContext?.reference,
|
|
140
|
+
userId: context.userId ?? parentContext?.userId,
|
|
141
|
+
scope: context.scope ?? parentContext?.scope,
|
|
138
142
|
depth: parentDepth + 1,
|
|
139
143
|
};
|
|
140
144
|
return logContextStorage.run(newContext, fn);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"log-context.js","sourceRoot":"","sources":["../../../src/lib/context/log-context.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAUH,kCAAkC;AAClC,MAAM,iBAAiB,GAAsB;IAC3C,QAAQ,EAAE,GAAG,EAAE,CAAC,SAAS;IACzB,GAAG,EAAE,CAAI,MAAkB,EAAE,EAAW,EAAK,EAAE,CAAC,EAAE,EAAE;CACrD,CAAC;AAEF,oEAAoE;AACpE,IAAI,iBAAiB,GAAsB,iBAA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K,EAAE,WAAW,GAAG,CAAC;KACvB,CAAC;IAEF,OAAO,iBAAiB,CAAC,GAAG,CAAC,UAAU,EAAE,EAAE,CAAC,CAAC;AAC/C,CAAC;AAED;;;GAGG;AACH,MAAM,UAAU,aAAa;IAC3B,iBAAiB,EAAE,CAAC;IACpB,OAAO,iBAAiB,CAAC,QAAQ,EAAE,CAAC;AACtC,CAAC;AAED;;;;;;;GAOG;AACH,MAAM,UAAU,WAAW,CAAI,SAAiB,EAAE,EAAW;IAC3D,OAAO,iBAAiB,CAAC,EAAE,SAAS,EAAE,EAAE,EAAE,CAAC,CAAC;AAC9C,CAAC;AAED;;;;;;;GAOG;AACH,MAAM,UAAU,WAAW,CAAI,SAAiB,EAAE,SAAiB,EAAE,EAAW;IAC9E,OAAO,iBAAiB,CAAC,EAAE,SAAS,EAAE,SAAS,EAAE,EAAE,EAAE,CAAC,CAAC;AACzD,CAAC"}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* installGlobalErrorHandlers — installs process-level error catchers.
|
|
3
|
+
*
|
|
4
|
+
* Behaviour:
|
|
5
|
+
* - Intercepts unhandledRejection + uncaughtException
|
|
6
|
+
* - Logs each at 'fatal' with a synthetic correlationId
|
|
7
|
+
* - Calls onFatal callback (if provided) before exit
|
|
8
|
+
* - Waits FLUSH_DELAY_MS for log writes to complete, then exits with code 1
|
|
9
|
+
* - exitOnUncaught: false skips the exit (useful when a process supervisor manages restart)
|
|
10
|
+
*
|
|
11
|
+
* Call once at process startup, before any other code.
|
|
12
|
+
*/
|
|
13
|
+
export interface GlobalErrorHandlerOptions {
|
|
14
|
+
/** Called with the error just before process.exit — use for escalation (PagerDuty etc.) */
|
|
15
|
+
onFatal?: (err: Error) => void | Promise<void>;
|
|
16
|
+
/**
|
|
17
|
+
* Whether to call process.exit(1) after flushing.
|
|
18
|
+
* Default: true. Set to false if your process supervisor manages restart.
|
|
19
|
+
*/
|
|
20
|
+
exitOnUncaught?: boolean;
|
|
21
|
+
}
|
|
22
|
+
export declare function installGlobalErrorHandlers(options?: GlobalErrorHandlerOptions): void;
|
|
23
|
+
//# sourceMappingURL=global-error-handlers.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"global-error-handlers.d.ts","sourceRoot":"","sources":["../../src/lib/global-error-handlers.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AAQH,MAAM,WAAW,yBAAyB;IACxC,2FAA2F;IAC3F,OAAO,CAAC,EAAE,CAAC,GAAG,EAAE,KAAK,KAAK,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;IAC/C;;;OAGG;IACH,cAAc,CAAC,EAAE,OAAO,CAAC;CAC1B;AA6BD,wBAAgB,0BAA0B,CAAC,OAAO,GAAE,yBAA8B,GAAG,IAAI,CASxF"}
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* installGlobalErrorHandlers — installs process-level error catchers.
|
|
3
|
+
*
|
|
4
|
+
* Behaviour:
|
|
5
|
+
* - Intercepts unhandledRejection + uncaughtException
|
|
6
|
+
* - Logs each at 'fatal' with a synthetic correlationId
|
|
7
|
+
* - Calls onFatal callback (if provided) before exit
|
|
8
|
+
* - Waits FLUSH_DELAY_MS for log writes to complete, then exits with code 1
|
|
9
|
+
* - exitOnUncaught: false skips the exit (useful when a process supervisor manages restart)
|
|
10
|
+
*
|
|
11
|
+
* Call once at process startup, before any other code.
|
|
12
|
+
*/
|
|
13
|
+
import { createLogger } from './package_logger.js';
|
|
14
|
+
const logger = createLogger('hazo_logs.globalHandlers');
|
|
15
|
+
const FLUSH_DELAY_MS = 500;
|
|
16
|
+
async function handleFatal(err, source, options) {
|
|
17
|
+
const correlationId = crypto.randomUUID();
|
|
18
|
+
logger.fatal(`[${source}] ${err.message}`, {
|
|
19
|
+
correlationId,
|
|
20
|
+
source,
|
|
21
|
+
name: err.name,
|
|
22
|
+
stack: err.stack,
|
|
23
|
+
});
|
|
24
|
+
try {
|
|
25
|
+
await options.onFatal?.(err);
|
|
26
|
+
}
|
|
27
|
+
catch {
|
|
28
|
+
// onFatal must never crash the crash handler
|
|
29
|
+
}
|
|
30
|
+
if (options.exitOnUncaught !== false) {
|
|
31
|
+
setTimeout(() => {
|
|
32
|
+
process.exit(1);
|
|
33
|
+
}, FLUSH_DELAY_MS);
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
export function installGlobalErrorHandlers(options = {}) {
|
|
37
|
+
process.on('unhandledRejection', (reason) => {
|
|
38
|
+
const err = reason instanceof Error ? reason : new Error(String(reason));
|
|
39
|
+
void handleFatal(err, 'unhandledRejection', options);
|
|
40
|
+
});
|
|
41
|
+
process.on('uncaughtException', (err) => {
|
|
42
|
+
void handleFatal(err, 'uncaughtException', options);
|
|
43
|
+
});
|
|
44
|
+
}
|
|
45
|
+
//# sourceMappingURL=global-error-handlers.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"global-error-handlers.js","sourceRoot":"","sources":["../../src/lib/global-error-handlers.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AAEH,OAAO,EAAE,YAAY,EAAE,MAAM,qBAAqB,CAAC;AAEnD,MAAM,MAAM,GAAG,YAAY,CAAC,0BAA0B,CAAC,CAAC;AAExD,MAAM,cAAc,GAAG,GAAG,CAAC;AAY3B,KAAK,UAAU,WAAW,CACxB,GAAU,EACV,MAAkD,EAClD,OAAkC;IAElC,MAAM,aAAa,GAAG,MAAM,CAAC,UAAU,EAAE,CAAC;IAE1C,MAAM,CAAC,KAAK,CAAC,IAAI,MAAM,KAAK,GAAG,CAAC,OAAO,EAAE,EAAE;QACzC,aAAa;QACb,MAAM;QACN,IAAI,EAAE,GAAG,CAAC,IAAI;QACd,KAAK,EAAE,GAAG,CAAC,KAAK;KACjB,CAAC,CAAC;IAEH,IAAI,CAAC;QACH,MAAM,OAAO,CAAC,OAAO,EAAE,CAAC,GAAG,CAAC,CAAC;IAC/B,CAAC;IAAC,MAAM,CAAC;QACP,6CAA6C;IAC/C,CAAC;IAED,IAAI,OAAO,CAAC,cAAc,KAAK,KAAK,EAAE,CAAC;QACrC,UAAU,CAAC,GAAG,EAAE;YACd,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;QAClB,CAAC,EAAE,cAAc,CAAC,CAAC;IACrB,CAAC;AACH,CAAC;AAED,MAAM,UAAU,0BAA0B,CAAC,UAAqC,EAAE;IAChF,OAAO,CAAC,EAAE,CAAC,oBAAoB,EAAE,CAAC,MAAM,EAAE,EAAE;QAC1C,MAAM,GAAG,GAAG,MAAM,YAAY,KAAK,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,IAAI,KAAK,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC,CAAC;QACzE,KAAK,WAAW,CAAC,GAAG,EAAE,oBAAoB,EAAE,OAAO,CAAC,CAAC;IACvD,CAAC,CAAC,CAAC;IAEH,OAAO,CAAC,EAAE,CAAC,mBAAmB,EAAE,CAAC,GAAG,EAAE,EAAE;QACtC,KAAK,WAAW,CAAC,GAAG,EAAE,mBAAmB,EAAE,OAAO,CAAC,CAAC;IACtD,CAAC,CAAC,CAAC;AACL,CAAC"}
|
|
@@ -17,6 +17,15 @@ export declare class HazoLogger {
|
|
|
17
17
|
private winstonLogger;
|
|
18
18
|
private config;
|
|
19
19
|
private executionId;
|
|
20
|
+
/** Log hooks — called synchronously after every log() call */
|
|
21
|
+
private static logHooks;
|
|
22
|
+
/**
|
|
23
|
+
* Register a hook that fires after every log entry is written.
|
|
24
|
+
* Returns an unregister function — call it to remove the hook.
|
|
25
|
+
*
|
|
26
|
+
* Used by registerAlertTrigger internally.
|
|
27
|
+
*/
|
|
28
|
+
static addLogHook(fn: (entry: LogEntry) => void): () => void;
|
|
20
29
|
private constructor();
|
|
21
30
|
/**
|
|
22
31
|
* Generate a human-readable execution ID
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"hazo_logger.d.ts","sourceRoot":"","sources":["../../src/lib/hazo_logger.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,OAAO,KAAK,EAAE,aAAa,EAAE,QAAQ,EAAY,MAAM,YAAY,CAAC;AAUpE;;;GAGG;AACH,iBAAe,gBAAgB,IAAI,OAAO,CAAC,IAAI,CAAC,CAyB/C;
|
|
1
|
+
{"version":3,"file":"hazo_logger.d.ts","sourceRoot":"","sources":["../../src/lib/hazo_logger.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,OAAO,KAAK,EAAE,aAAa,EAAE,QAAQ,EAAY,MAAM,YAAY,CAAC;AAUpE;;;GAGG;AACH,iBAAe,gBAAgB,IAAI,OAAO,CAAC,IAAI,CAAC,CAyB/C;AAWD,qBAAa,UAAU;IACrB,OAAO,CAAC,MAAM,CAAC,QAAQ,CAA2B;IAClD,OAAO,CAAC,MAAM,CAAC,eAAe,CAAoC;IAClE,OAAO,CAAC,aAAa,CAA4B;IACjD,OAAO,CAAC,MAAM,CAAiB;IAC/B,OAAO,CAAC,WAAW,CAAS;IAE5B,8DAA8D;IAC9D,OAAO,CAAC,MAAM,CAAC,QAAQ,CAAwC;IAE/D;;;;;OAKG;WACW,UAAU,CAAC,EAAE,EAAE,CAAC,KAAK,EAAE,QAAQ,KAAK,IAAI,GAAG,MAAM,IAAI;IAOnE,OAAO;IASP;;;OAGG;IACH,OAAO,CAAC,mBAAmB;IAQ3B;;;OAGG;WACiB,gBAAgB,CAAC,UAAU,CAAC,EAAE,MAAM,GAAG,OAAO,CAAC,UAAU,CAAC;IAkB9E;;;;OAIG;WACW,WAAW,CAAC,UAAU,CAAC,EAAE,MAAM,GAAG,UAAU;IAgB1D;;OAEG;WACW,KAAK,IAAI,IAAI;IAS3B;;OAEG;IACI,GAAG,CAAC,KAAK,EAAE,QAAQ,GAAG,IAAI;IAUjC;;;OAGG;IACI,SAAS,CAAC,KAAK,EAAE,IAAI,CAAC,QAAQ,EAAE,aAAa,GAAG,UAAU,GA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