UNPKG

minsky-kit

Version:
48 lines (39 loc) 1.08 kB
/* eslint no-console: "off" */ import Config from '../Config'; // 'Private' properties let key = null; let type = 'log'; const colors = { log: 'black', info: 'blue', warn: 'olive', error: 'red', }; // class definition export default class Logger { static setKey (value = null) { key = value; } static setType (value = 'log') { type = value; } static set (key = null, type = 'log') { this.setKey(key); this.setType(type); } static log (...values) { // block logger if mode is production if (Config.globals.mode !== 'production' || type === 'error') { // add prefix to log if one is given if (key) { console[type](`%c[ ${key} ]`, `color: ${colors[type] || colors.log}; font-weight: bold; font-size: 11px; font-family: "Menlo-Regular", Consolas, Monospace`, '-', ...values); } else { console[type](...values); } } } static reset () { this.settings(); } }