@hkdigital/lib-core 0.4.42 → 0.4.43
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.
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
/** @typedef {import('../../logging/typedef.js').LogLevel} LogLevel */
|
|
1
2
|
/**
|
|
2
3
|
* @typedef {import('./typedef.js').ServiceConstructor} ServiceConstructor
|
|
3
4
|
* @typedef {import('./typedef.js').ServiceRegistrationOptions} ServiceRegistrationOptions
|
|
@@ -174,11 +175,11 @@ export class ServiceManager extends EventEmitter {
|
|
|
174
175
|
* - String with service name: 'auth' (requires level parameter)
|
|
175
176
|
* - String with config: 'auth:debug,database:info'
|
|
176
177
|
* - Object: { auth: 'debug', database: 'info' }
|
|
177
|
-
* @param {
|
|
178
|
+
* @param {LogLevel} [level] - Log level (required when nameOrConfig is service name)
|
|
178
179
|
*/
|
|
179
180
|
setServiceLogLevel(nameOrConfig: string | {
|
|
180
181
|
[x: string]: string;
|
|
181
|
-
}, level?:
|
|
182
|
+
}, level?: LogLevel): void;
|
|
182
183
|
/**
|
|
183
184
|
* Get all services with a specific tag
|
|
184
185
|
*
|
|
@@ -198,6 +199,7 @@ export class ServiceManager extends EventEmitter {
|
|
|
198
199
|
#private;
|
|
199
200
|
}
|
|
200
201
|
export default ServiceManager;
|
|
202
|
+
export type LogLevel = import("../../logging/typedef.js").LogLevel;
|
|
201
203
|
export type ServiceConstructor = import("./typedef.js").ServiceConstructor;
|
|
202
204
|
export type ServiceRegistrationOptions = import("./typedef.js").ServiceRegistrationOptions;
|
|
203
205
|
export type ServiceManagerConfig = import("./typedef.js").ServiceManagerConfig;
|
|
@@ -86,6 +86,8 @@ import {
|
|
|
86
86
|
STATE_DESTROYED
|
|
87
87
|
} from '../service-base/constants.js';
|
|
88
88
|
|
|
89
|
+
/** @typedef {import('../../logging/typedef.js').LogLevel} LogLevel */
|
|
90
|
+
|
|
89
91
|
/**
|
|
90
92
|
* @typedef {import('./typedef.js').ServiceConstructor} ServiceConstructor
|
|
91
93
|
* @typedef {import('./typedef.js').ServiceRegistrationOptions} ServiceRegistrationOptions
|
|
@@ -141,7 +143,26 @@ export class ServiceManager extends EventEmitter {
|
|
|
141
143
|
this.setManagerLogLevel(managerLogLevel);
|
|
142
144
|
|
|
143
145
|
if (serviceLogLevels) {
|
|
144
|
-
|
|
146
|
+
// Parse and store service log levels, but don't apply them yet
|
|
147
|
+
// They will be applied when services are created in get()
|
|
148
|
+
/** @type {{[name:string]: LogLevel}} */
|
|
149
|
+
let parsedServiceLevels = {};
|
|
150
|
+
|
|
151
|
+
if (typeof serviceLogLevels === 'string') {
|
|
152
|
+
if (serviceLogLevels.includes(':')) {
|
|
153
|
+
// Parse string config: 'auth:debug,database:info'
|
|
154
|
+
parsedServiceLevels = parseServiceLogLevels(serviceLogLevels);
|
|
155
|
+
} else {
|
|
156
|
+
throw new Error(
|
|
157
|
+
'Service log levels string must include service:level pairs'
|
|
158
|
+
);
|
|
159
|
+
}
|
|
160
|
+
} else {
|
|
161
|
+
// Object config: { auth: 'debug', database: 'info' }
|
|
162
|
+
parsedServiceLevels = serviceLogLevels;
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
this.config.serviceLogLevels = parsedServiceLevels;
|
|
145
166
|
}
|
|
146
167
|
}
|
|
147
168
|
|
|
@@ -585,10 +606,10 @@ export class ServiceManager extends EventEmitter {
|
|
|
585
606
|
* - String with service name: 'auth' (requires level parameter)
|
|
586
607
|
* - String with config: 'auth:debug,database:info'
|
|
587
608
|
* - Object: { auth: 'debug', database: 'info' }
|
|
588
|
-
* @param {
|
|
609
|
+
* @param {LogLevel} [level] - Log level (required when nameOrConfig is service name)
|
|
589
610
|
*/
|
|
590
611
|
setServiceLogLevel(nameOrConfig, level) {
|
|
591
|
-
/** @type {{[name:string]:
|
|
612
|
+
/** @type {{[name:string]: LogLevel}} */
|
|
592
613
|
let serviceLevels = {};
|
|
593
614
|
|
|
594
615
|
if (typeof nameOrConfig === 'string') {
|
|
@@ -617,10 +638,10 @@ export class ServiceManager extends EventEmitter {
|
|
|
617
638
|
for (const [name, logLevel] of Object.entries(serviceLevels)) {
|
|
618
639
|
this.config.serviceLogLevels[name] = logLevel;
|
|
619
640
|
|
|
620
|
-
// Apply to existing instance
|
|
621
|
-
const
|
|
622
|
-
if (instance) {
|
|
623
|
-
instance.setLogLevel(logLevel);
|
|
641
|
+
// Apply to existing instance if it exists and is registered
|
|
642
|
+
const entry = this.services.get(name);
|
|
643
|
+
if (entry?.instance) {
|
|
644
|
+
entry.instance.setLogLevel(logLevel);
|
|
624
645
|
}
|
|
625
646
|
}
|
|
626
647
|
}
|
|
@@ -1,18 +1,17 @@
|
|
|
1
|
+
/** @typedef {import('../../logging/typedef.js').LogLevel} LogLevel */
|
|
1
2
|
/**
|
|
2
3
|
* Parse comma-separated service:level configuration string
|
|
3
4
|
*
|
|
4
5
|
* @param {string} configString
|
|
5
6
|
* Comma-separated string like "auth:debug,database:info,cache:warn"
|
|
6
7
|
*
|
|
7
|
-
* @returns {
|
|
8
|
+
* @returns {Record<string, LogLevel>} Service name to log level mapping
|
|
8
9
|
*
|
|
9
10
|
* @example
|
|
10
11
|
* const config = parseServiceLogLevels("auth:debug,database:info");
|
|
11
12
|
* // Returns: { auth: "debug", database: "info" }
|
|
12
13
|
*/
|
|
13
|
-
export function parseServiceLogLevels(configString: string):
|
|
14
|
-
[x: string]: string;
|
|
15
|
-
};
|
|
14
|
+
export function parseServiceLogLevels(configString: string): Record<string, LogLevel>;
|
|
16
15
|
/**
|
|
17
16
|
* Expand log levels to include higher severity levels
|
|
18
17
|
*
|
|
@@ -33,3 +32,4 @@ export function expandLogLevels(serviceLevels: {
|
|
|
33
32
|
}): {
|
|
34
33
|
[x: string]: string[];
|
|
35
34
|
};
|
|
35
|
+
export type LogLevel = import("../../logging/typedef.js").LogLevel;
|
|
@@ -7,13 +7,15 @@
|
|
|
7
7
|
|
|
8
8
|
import { DEBUG, INFO, WARN, ERROR } from '../../logging/index.js';
|
|
9
9
|
|
|
10
|
+
/** @typedef {import('../../logging/typedef.js').LogLevel} LogLevel */
|
|
11
|
+
|
|
10
12
|
/**
|
|
11
13
|
* Parse comma-separated service:level configuration string
|
|
12
14
|
*
|
|
13
15
|
* @param {string} configString
|
|
14
16
|
* Comma-separated string like "auth:debug,database:info,cache:warn"
|
|
15
17
|
*
|
|
16
|
-
* @returns {
|
|
18
|
+
* @returns {Record<string, LogLevel>} Service name to log level mapping
|
|
17
19
|
*
|
|
18
20
|
* @example
|
|
19
21
|
* const config = parseServiceLogLevels("auth:debug,database:info");
|