Skip to content

Commit

Permalink
feat(system): add package LOGGER
Browse files Browse the repository at this point in the history
  • Loading branch information
postspectacular committed Mar 30, 2021
1 parent 01273d1 commit f67364c
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 4 deletions.
12 changes: 11 additions & 1 deletion 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 {
/**
Expand Down Expand Up @@ -48,3 +48,13 @@ export type SystemSpecs<T extends SystemMap<T>> = Record<
deps?: Keys<T>[];
}
>;

/** @internal */
export let LOGGER = NULL_LOGGER;

/**
* Sets package logger to given instance.
*
* @param logger
*/
export const setLogger = (logger: ILogger) => (LOGGER = logger);
6 changes: 3 additions & 3 deletions 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 = <T extends SystemMap<T>>(map: SystemSpecs<T>) =>
new System<T>(map);
Expand Down Expand Up @@ -37,7 +37,7 @@ export class System<T extends SystemMap<T>> 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;
}
}
Expand All @@ -59,7 +59,7 @@ export class System<T extends SystemMap<T>> 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;
Expand Down

0 comments on commit f67364c

Please sign in to comment.