@hkdigital/lib-core 0.4.29 → 0.4.30
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
|
@@ -187,10 +187,16 @@ The library includes a comprehensive logging system that provides:
|
|
|
187
187
|
- **Client-side**: Enhanced console logging with structured data display in browser inspector
|
|
188
188
|
- **Consistent API**: Same logging interface for both server and client environments
|
|
189
189
|
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
- **
|
|
190
|
+
## Documentation
|
|
191
|
+
|
|
192
|
+
For detailed setup guides and configuration:
|
|
193
|
+
- **Project setup**: [docs/setup/new-project.md](./docs/setup/new-project.md) - SvelteKit project setup
|
|
194
|
+
- **Library setup**: [docs/setup/new-lib.md](./docs/setup/new-lib.md) - SvelteKit library setup
|
|
195
|
+
- **Services & logging**: [docs/setup/services-logging.md](./docs/setup/services-logging.md) - Service management architecture
|
|
196
|
+
- **Configuration files**: [docs/config/root-config-files.md](./docs/config/root-config-files.md) - Config file reference
|
|
197
|
+
- **Design system**: [src/lib/design/README.md](./src/lib/design/README.md) - Design tokens and theming
|
|
198
|
+
- **Vite configuration**: [src/lib/config/README.md](./src/lib/config/README.md) - Build configuration
|
|
199
|
+
- **Logging system**: [src/lib/logging/README.md](./src/lib/logging/README.md) - Server and client logging
|
|
194
200
|
|
|
195
201
|
### Update
|
|
196
202
|
|
package/dist/services/README.md
CHANGED
|
@@ -237,6 +237,37 @@ const systemHealth = await manager.checkHealth();
|
|
|
237
237
|
|
|
238
238
|
### Error Handling and Recovery
|
|
239
239
|
|
|
240
|
+
### Logging Configuration
|
|
241
|
+
|
|
242
|
+
ServiceManager provides centralized logging control for all services:
|
|
243
|
+
|
|
244
|
+
```javascript
|
|
245
|
+
const manager = new ServiceManager({
|
|
246
|
+
debug: true, // Sets defaultLogLevel to DEBUG
|
|
247
|
+
defaultLogLevel: 'INFO', // Default level for all services
|
|
248
|
+
managerLogLevel: 'DEBUG', // Level for ServiceManager itself
|
|
249
|
+
serviceLogLevels: { // Per-service levels
|
|
250
|
+
database: 'ERROR',
|
|
251
|
+
auth: 'DEBUG'
|
|
252
|
+
}
|
|
253
|
+
});
|
|
254
|
+
|
|
255
|
+
// Change manager log level at runtime
|
|
256
|
+
manager.setManagerLogLevel('ERROR');
|
|
257
|
+
|
|
258
|
+
// Change service log levels at runtime
|
|
259
|
+
manager.setServiceLogLevel('database', 'INFO');
|
|
260
|
+
|
|
261
|
+
// Set multiple service levels at once
|
|
262
|
+
manager.setServiceLogLevel({
|
|
263
|
+
database: 'INFO',
|
|
264
|
+
auth: 'DEBUG'
|
|
265
|
+
});
|
|
266
|
+
|
|
267
|
+
// Parse string format
|
|
268
|
+
manager.setServiceLogLevel('database:info,auth:debug');
|
|
269
|
+
```
|
|
270
|
+
|
|
240
271
|
### ServiceManager events
|
|
241
272
|
|
|
242
273
|
ServiceManager emits these events (constants from `$lib/services/service-manager/constants.js`):
|
|
@@ -264,14 +295,14 @@ await manager.recoverService('database');
|
|
|
264
295
|
Forward all service log events to a centralised logger:
|
|
265
296
|
|
|
266
297
|
```javascript
|
|
267
|
-
import { ServiceManager
|
|
298
|
+
import { ServiceManager } from '$lib/services/index.js';
|
|
268
299
|
import { createServerLogger } from '$lib/logging/index.js';
|
|
269
300
|
|
|
270
301
|
const manager = new ServiceManager();
|
|
271
302
|
const logger = createServerLogger('SystemLogger');
|
|
272
303
|
|
|
273
304
|
// Listen to all log events and forward them to the logger
|
|
274
|
-
manager.
|
|
305
|
+
const unsubscribe = manager.onServiceLogEvent((logEvent) => {
|
|
275
306
|
logger.logFromEvent('manager:service:log', logEvent);
|
|
276
307
|
});
|
|
277
308
|
|
|
@@ -280,6 +311,9 @@ manager.register('database', DatabaseService, { ... });
|
|
|
280
311
|
manager.register('auth', AuthService, { ... });
|
|
281
312
|
|
|
282
313
|
await manager.startAll();
|
|
314
|
+
|
|
315
|
+
// Cleanup when done
|
|
316
|
+
unsubscribe();
|
|
283
317
|
```
|
|
284
318
|
|
|
285
319
|
## Plugins
|
|
@@ -106,7 +106,8 @@ export class ServiceManager extends EventEmitter {
|
|
|
106
106
|
/** @type {Map<string, ServiceEntry>} */
|
|
107
107
|
this.services = new Map();
|
|
108
108
|
|
|
109
|
-
const defaultLogLevel =
|
|
109
|
+
const defaultLogLevel =
|
|
110
|
+
config.defaultLogLevel || (config.debug ? DEBUG : INFO);
|
|
110
111
|
const managerLogLevel = config.managerLogLevel || defaultLogLevel;
|
|
111
112
|
const serviceLogLevels = config.serviceLogLevels;
|
|
112
113
|
|
|
@@ -118,16 +119,16 @@ export class ServiceManager extends EventEmitter {
|
|
|
118
119
|
debug: config.debug ?? false,
|
|
119
120
|
autoStart: config.autoStart ?? false,
|
|
120
121
|
stopTimeout: config.stopTimeout || 10000,
|
|
121
|
-
defaultLogLevel
|
|
122
|
-
managerLogLevel
|
|
122
|
+
defaultLogLevel
|
|
123
|
+
// managerLogLevel will be set bysetManagerLogLevel()
|
|
123
124
|
// serviceLogLevels will be set by setServiceLogLevel()
|
|
124
125
|
};
|
|
125
126
|
|
|
127
|
+
this.setManagerLogLevel(managerLogLevel);
|
|
128
|
+
|
|
126
129
|
if (serviceLogLevels) {
|
|
127
130
|
this.setServiceLogLevel(serviceLogLevels);
|
|
128
131
|
}
|
|
129
|
-
|
|
130
|
-
this.#setupLogging();
|
|
131
132
|
}
|
|
132
133
|
|
|
133
134
|
/**
|
|
@@ -528,7 +529,9 @@ export class ServiceManager extends EventEmitter {
|
|
|
528
529
|
} else {
|
|
529
530
|
// Single service name
|
|
530
531
|
if (!level) {
|
|
531
|
-
throw new Error(
|
|
532
|
+
throw new Error(
|
|
533
|
+
`Level parameter required for service '${nameOrConfig}'`
|
|
534
|
+
);
|
|
532
535
|
}
|
|
533
536
|
serviceLevels[nameOrConfig] = level;
|
|
534
537
|
}
|
|
@@ -633,23 +636,6 @@ export class ServiceManager extends EventEmitter {
|
|
|
633
636
|
}
|
|
634
637
|
}
|
|
635
638
|
|
|
636
|
-
/**
|
|
637
|
-
* Setup logging configuration based on config.debug
|
|
638
|
-
*/
|
|
639
|
-
#setupLogging() {
|
|
640
|
-
// Set default level for services based on debug flag if not explicitly set
|
|
641
|
-
if (!this.config.defaultLogLevel) {
|
|
642
|
-
this.config.defaultLogLevel = this.config.debug ? DEBUG : INFO;
|
|
643
|
-
}
|
|
644
|
-
|
|
645
|
-
// Set manager log level (use defaultLogLevel as fallback)
|
|
646
|
-
const managerLevel = this.config.managerLogLevel ||
|
|
647
|
-
this.config.defaultLogLevel;
|
|
648
|
-
if (managerLevel) {
|
|
649
|
-
this.logger.setLevel(managerLevel);
|
|
650
|
-
}
|
|
651
|
-
}
|
|
652
|
-
|
|
653
639
|
/**
|
|
654
640
|
* Get the appropriate log level for a service
|
|
655
641
|
*
|
|
@@ -6,10 +6,10 @@
|
|
|
6
6
|
* Event emitted when entering a state
|
|
7
7
|
* @type {string}
|
|
8
8
|
*/
|
|
9
|
-
export const ENTER = '
|
|
9
|
+
export const ENTER = '_enter';
|
|
10
10
|
|
|
11
11
|
/**
|
|
12
12
|
* Event emitted when exiting a state
|
|
13
13
|
* @type {string}
|
|
14
14
|
*/
|
|
15
|
-
export const EXIT = '
|
|
15
|
+
export const EXIT = '_exit';
|