diff --git a/packages/system/src/api.ts b/packages/system/src/api.ts index bfab15ba57..53385620b8 100644 --- a/packages/system/src/api.ts +++ b/packages/system/src/api.ts @@ -1,4 +1,4 @@ -import type { Fn, Keys } from "@thi.ng/api"; +import { Fn, ILogger, Keys, NULL_LOGGER } from "@thi.ng/api"; export interface ILifecycle { /** @@ -48,3 +48,13 @@ export type SystemSpecs> = Record< deps?: Keys[]; } >; + +/** @internal */ +export let LOGGER = NULL_LOGGER; + +/** + * Sets package logger to given instance. + * + * @param logger + */ +export const setLogger = (logger: ILogger) => (LOGGER = logger); diff --git a/packages/system/src/system.ts b/packages/system/src/system.ts index 811861e034..d24983f0d2 100644 --- a/packages/system/src/system.ts +++ b/packages/system/src/system.ts @@ -1,6 +1,6 @@ import type { Keys } from "@thi.ng/api"; import { DGraph } from "@thi.ng/dgraph"; -import type { ILifecycle, SystemMap, SystemSpecs } from "./api"; +import { ILifecycle, LOGGER, SystemMap, SystemSpecs } from "./api"; export const defSystem = >(map: SystemSpecs) => new System(map); @@ -37,7 +37,7 @@ export class System> implements ILifecycle { for (let id of this.topology) { const comp = this.components[id]; if (comp.start && !(await comp.start())) { - console.warn(`error starting component: ${id}`); + LOGGER.warn(`error starting component: ${id}`); return false; } } @@ -59,7 +59,7 @@ export class System> implements ILifecycle { const id = topo[i]; const comp = this.components[id]; if (comp.stop && !(await comp.stop())) { - console.warn(`error stopping component: ${id}`); + LOGGER.warn(`error stopping component: ${id}`); } } return true;