@hkdigital/lib-core 0.4.32 → 0.4.33
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/dist/logging/internal/adapters/console.js +5 -5
- package/dist/logging/internal/adapters/pino.js +2 -1
- package/dist/logging/internal/factories/client.js +2 -2
- package/dist/logging/internal/factories/server.js +2 -2
- package/dist/services/service-manager/ServiceManager.d.ts +16 -0
- package/dist/services/service-manager/ServiceManager.js +48 -9
- package/dist/services/service-manager/constants.d.ts +6 -2
- package/dist/services/service-manager/constants.js +10 -3
- package/dist/util/sveltekit/env/README.md +1 -2
- package/package.json +1 -1
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { dev } from '$app/environment';
|
|
2
|
-
import { LEVELS } from '../../levels.js';
|
|
2
|
+
import { LEVELS, DEBUG, INFO, WARN, ERROR } from '../../levels.js';
|
|
3
3
|
import {
|
|
4
4
|
findRelevantFrameIndex,
|
|
5
5
|
detectErrorMeta,
|
|
@@ -164,13 +164,13 @@ export class ConsoleAdapter {
|
|
|
164
164
|
*/
|
|
165
165
|
#getConsoleMethod(level) {
|
|
166
166
|
switch (level) {
|
|
167
|
-
case
|
|
167
|
+
case DEBUG:
|
|
168
168
|
return 'debug';
|
|
169
|
-
case
|
|
169
|
+
case INFO:
|
|
170
170
|
return 'info';
|
|
171
|
-
case
|
|
171
|
+
case WARN:
|
|
172
172
|
return 'warn';
|
|
173
|
-
case
|
|
173
|
+
case ERROR:
|
|
174
174
|
case 'fatal':
|
|
175
175
|
return 'error';
|
|
176
176
|
default:
|
|
@@ -5,6 +5,7 @@ import pino from 'pino';
|
|
|
5
5
|
import { dev } from '$app/environment';
|
|
6
6
|
|
|
7
7
|
import { HkPromise } from '../../../generic/promises.js';
|
|
8
|
+
import { ERROR } from '../../levels.js';
|
|
8
9
|
|
|
9
10
|
import {
|
|
10
11
|
detectErrorMeta,
|
|
@@ -240,7 +241,7 @@ export class PinoAdapter {
|
|
|
240
241
|
|
|
241
242
|
while (this.#messageQueue.length > 0) {
|
|
242
243
|
const queuedLog = this.#messageQueue.shift();
|
|
243
|
-
console[queuedLog.level ===
|
|
244
|
+
console[queuedLog.level === ERROR ? 'error' : 'log'](
|
|
244
245
|
`[${queuedLog.level.toUpperCase()}] ${queuedLog.message}`,
|
|
245
246
|
queuedLog.data
|
|
246
247
|
);
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { Logger } from '../logger/index.js';
|
|
2
2
|
import { ConsoleAdapter } from '../adapters/console.js';
|
|
3
|
-
import { INFO } from '../../levels.js';
|
|
3
|
+
import { INFO, LOG } from '../../levels.js';
|
|
4
4
|
|
|
5
5
|
/**
|
|
6
6
|
* Create a client-side logger with console adapter
|
|
@@ -15,7 +15,7 @@ export function createClientLogger(name, level = INFO, consoleOptions = {}) {
|
|
|
15
15
|
const adapter = new ConsoleAdapter({ ...consoleOptions, level });
|
|
16
16
|
|
|
17
17
|
// Connect adapter to logger events
|
|
18
|
-
logger.on(
|
|
18
|
+
logger.on(LOG, (logEvent) => adapter.handleLog(logEvent));
|
|
19
19
|
|
|
20
20
|
return logger;
|
|
21
21
|
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { Logger } from '../logger/index.js';
|
|
2
2
|
import { PinoAdapter } from '../adapters/pino.js';
|
|
3
|
-
import { INFO } from '../../levels.js';
|
|
3
|
+
import { INFO, LOG } from '../../levels.js';
|
|
4
4
|
// import { expectNoSSRContext } from '../../../util/ssr/index.js';
|
|
5
5
|
|
|
6
6
|
/**
|
|
@@ -26,7 +26,7 @@ export function createServerLogger(name, level = INFO, pinoOptions = {}) {
|
|
|
26
26
|
// determination to fail
|
|
27
27
|
// -> Stop and start the dev server
|
|
28
28
|
//
|
|
29
|
-
logger.on(
|
|
29
|
+
logger.on(LOG, (logEvent) => adapter.handleLog(logEvent));
|
|
30
30
|
|
|
31
31
|
return logger;
|
|
32
32
|
}
|
|
@@ -140,6 +140,22 @@ export class ServiceManager extends EventEmitter {
|
|
|
140
140
|
* @returns {Function} Unsubscribe function
|
|
141
141
|
*/
|
|
142
142
|
onServiceLogEvent(listener: (logEvent: LogEvent) => void): Function;
|
|
143
|
+
/**
|
|
144
|
+
* Listen to log messages emitted by the ServiceManager itself
|
|
145
|
+
*
|
|
146
|
+
* @param {(logEvent: LogEvent) => void} listener - Log event handler
|
|
147
|
+
*
|
|
148
|
+
* @returns {Function} Unsubscribe function
|
|
149
|
+
*/
|
|
150
|
+
onManagerLogEvent(listener: (logEvent: LogEvent) => void): Function;
|
|
151
|
+
/**
|
|
152
|
+
* Listen to all log messages (both manager and services)
|
|
153
|
+
*
|
|
154
|
+
* @param {(logEvent: LogEvent) => void} listener - Log event handler
|
|
155
|
+
*
|
|
156
|
+
* @returns {Function} Unsubscribe function
|
|
157
|
+
*/
|
|
158
|
+
onLogEvent(listener: (logEvent: LogEvent) => void): Function;
|
|
143
159
|
/**
|
|
144
160
|
* Set log level for the ServiceManager itself
|
|
145
161
|
*
|
|
@@ -66,7 +66,16 @@
|
|
|
66
66
|
import { EventEmitter } from '../../generic/events.js';
|
|
67
67
|
import { Logger, DEBUG, INFO } from '../../logging/index.js';
|
|
68
68
|
|
|
69
|
-
import {
|
|
69
|
+
import {
|
|
70
|
+
SERVICE_LOG,
|
|
71
|
+
STATE_CHANGED,
|
|
72
|
+
HEALTH_CHANGED,
|
|
73
|
+
ERROR,
|
|
74
|
+
LOG,
|
|
75
|
+
SERVICE_STATE_CHANGED,
|
|
76
|
+
SERVICE_HEALTH_CHANGED,
|
|
77
|
+
SERVICE_ERROR
|
|
78
|
+
} from './constants.js';
|
|
70
79
|
import { parseServiceLogLevels } from './util.js';
|
|
71
80
|
|
|
72
81
|
import {
|
|
@@ -503,6 +512,36 @@ export class ServiceManager extends EventEmitter {
|
|
|
503
512
|
return this.on(SERVICE_LOG, listener);
|
|
504
513
|
}
|
|
505
514
|
|
|
515
|
+
/**
|
|
516
|
+
* Listen to log messages emitted by the ServiceManager itself
|
|
517
|
+
*
|
|
518
|
+
* @param {(logEvent: LogEvent) => void} listener - Log event handler
|
|
519
|
+
*
|
|
520
|
+
* @returns {Function} Unsubscribe function
|
|
521
|
+
*/
|
|
522
|
+
onManagerLogEvent(listener) {
|
|
523
|
+
return this.logger.on(LOG, listener);
|
|
524
|
+
}
|
|
525
|
+
|
|
526
|
+
/**
|
|
527
|
+
* Listen to all log messages (both manager and services)
|
|
528
|
+
*
|
|
529
|
+
* @param {(logEvent: LogEvent) => void} listener - Log event handler
|
|
530
|
+
*
|
|
531
|
+
* @returns {Function} Unsubscribe function
|
|
532
|
+
*/
|
|
533
|
+
onLogEvent(listener) {
|
|
534
|
+
// Listen to both service and manager logs
|
|
535
|
+
const unsubscribeService = this.onServiceLogEvent(listener);
|
|
536
|
+
const unsubscribeManager = this.onManagerLogEvent(listener);
|
|
537
|
+
|
|
538
|
+
// Return combined unsubscribe function
|
|
539
|
+
return () => {
|
|
540
|
+
unsubscribeService();
|
|
541
|
+
unsubscribeManager();
|
|
542
|
+
};
|
|
543
|
+
}
|
|
544
|
+
|
|
506
545
|
/**
|
|
507
546
|
* Set log level for the ServiceManager itself
|
|
508
547
|
*
|
|
@@ -587,21 +626,21 @@ export class ServiceManager extends EventEmitter {
|
|
|
587
626
|
*/
|
|
588
627
|
_attachServiceEvents(name, instance) {
|
|
589
628
|
// Forward service events
|
|
590
|
-
instance.on(
|
|
591
|
-
this.emit(
|
|
629
|
+
instance.on(STATE_CHANGED, (/** @type {StateChangeEvent} */ data) => {
|
|
630
|
+
this.emit(SERVICE_STATE_CHANGED, { service: name, data });
|
|
592
631
|
});
|
|
593
632
|
|
|
594
|
-
instance.on(
|
|
595
|
-
this.emit(
|
|
633
|
+
instance.on(HEALTH_CHANGED, (/** @type {HealthChangeEvent} */ data) => {
|
|
634
|
+
this.emit(SERVICE_HEALTH_CHANGED, { service: name, data });
|
|
596
635
|
});
|
|
597
636
|
|
|
598
|
-
instance.on(
|
|
599
|
-
this.emit(
|
|
637
|
+
instance.on(ERROR, (/** @type {ServiceErrorEvent} */ data) => {
|
|
638
|
+
this.emit(SERVICE_ERROR, { service: name, data });
|
|
600
639
|
});
|
|
601
640
|
|
|
602
641
|
// Forward log events
|
|
603
|
-
instance.logger.on(
|
|
604
|
-
this.emit(
|
|
642
|
+
instance.logger.on(LOG, (/** @type {LogEvent} */ logEvent) => {
|
|
643
|
+
this.emit(SERVICE_LOG, logEvent);
|
|
605
644
|
});
|
|
606
645
|
}
|
|
607
646
|
|
|
@@ -1,5 +1,9 @@
|
|
|
1
|
-
export const
|
|
2
|
-
export const
|
|
1
|
+
export const STATE_CHANGED: "stateChanged";
|
|
2
|
+
export const HEALTH_CHANGED: "healthChanged";
|
|
3
|
+
export const ERROR: "error";
|
|
4
|
+
export const LOG: "log";
|
|
5
|
+
export const SERVICE_STATE_CHANGED: "service:stateChanged";
|
|
6
|
+
export const SERVICE_HEALTH_CHANGED: "service:healthChanged";
|
|
3
7
|
export const SERVICE_ERROR: "service:error";
|
|
4
8
|
export const SERVICE_LOG: "service:log";
|
|
5
9
|
export const ANY_LOG_LEVEL: "*";
|
|
@@ -1,8 +1,15 @@
|
|
|
1
|
-
//
|
|
2
|
-
export const
|
|
3
|
-
export const
|
|
1
|
+
// Service event names (what services emit)
|
|
2
|
+
export const STATE_CHANGED = 'stateChanged';
|
|
3
|
+
export const HEALTH_CHANGED = 'healthChanged';
|
|
4
|
+
export const ERROR = 'error';
|
|
5
|
+
export const LOG = 'log';
|
|
6
|
+
|
|
7
|
+
// Manager event names (what ServiceManager emits)
|
|
8
|
+
export const SERVICE_STATE_CHANGED = 'service:stateChanged';
|
|
9
|
+
export const SERVICE_HEALTH_CHANGED = 'service:healthChanged';
|
|
4
10
|
export const SERVICE_ERROR = 'service:error';
|
|
5
11
|
export const SERVICE_LOG = 'service:log';
|
|
6
12
|
|
|
13
|
+
|
|
7
14
|
export const ANY_LOG_LEVEL = '*';
|
|
8
15
|
export const ANY_SERVICE_NAME = '*';
|
|
@@ -339,7 +339,6 @@ console.log(features);
|
|
|
339
339
|
- `getAllEnv(options)` - Get combined environment variables (server only)
|
|
340
340
|
- `getPublicEnvByPrefix(prefix, options)` - Get public variables by prefix
|
|
341
341
|
- `getPrivateEnvByPrefix(prefix, options)` - Get private variables by prefix
|
|
342
|
-
- `getAllEnvByPrefix(prefix, options)` - Get combined variables by prefix
|
|
343
342
|
|
|
344
343
|
### Raw Access
|
|
345
344
|
|
|
@@ -421,4 +420,4 @@ interface DatabaseConfig {
|
|
|
421
420
|
}
|
|
422
421
|
|
|
423
422
|
const { database }: { database: DatabaseConfig } = getPrivateEnv();
|
|
424
|
-
```
|
|
423
|
+
```
|