UNPKG

@open-audio-stack/core

Version:
47 lines (46 loc) 1.38 kB
import chalk from 'chalk'; import { logEnable, logDisable } from '../helpers/utils.js'; export class Logger { static debug = false; static log(...args) { if (this.debug) console.log(...args); } static logEnable() { logEnable(); return (this.debug = true); } static logDisable() { logDisable(); return (this.debug = false); } static logErrors(errors) { errors.forEach(error => { // @ts-expect-error need to filter by code. if (error.received) { this.log(chalk.red( // @ts-expect-error need to filter by code. `- ${error.path} (${error.message}) received '${error.received}' expected '${error.expected}'`)); } else { this.log(chalk.red(`- ${error.path} (${error.message})`)); } }); } static logRecommendations(recs) { recs.forEach(rec => { this.log(chalk.yellow(`- ${rec.field} ${rec.rec}`)); }); } static logReport(info, errors, recs) { if (errors && errors.length > 0) { this.log(chalk.red(`X ${info}`)); this.logErrors(errors); } else { this.log(chalk.green(`✓ ${info}`)); } if (recs) this.logRecommendations(recs); } }