UNPKG

tycho-solver

Version:

Evolutionary computation and optimization library

26 lines 919 B
export class Logger { levelOrder = { debug: 10, info: 20, warn: 30, error: 40, silent: 100 }; level; sink; constructor(level = 'info', sink) { this.level = level; this.sink = sink || ((l, m, ...a) => console.log(`[${l.toUpperCase()}] ${m}`, ...a)); } setLevel(l) { this.level = l; } shouldLog(l) { return this.levelOrder[l] >= this.levelOrder[this.level]; } debug(msg, ...args) { if (this.shouldLog('debug')) this.sink('debug', msg, ...args); } info(msg, ...args) { if (this.shouldLog('info')) this.sink('info', msg, ...args); } warn(msg, ...args) { if (this.shouldLog('warn')) this.sink('warn', msg, ...args); } error(msg, ...args) { if (this.shouldLog('error')) this.sink('error', msg, ...args); } } // default shared logger export const logger = new Logger('info'); //# sourceMappingURL=logger.js.map