2020-12-08 10:40:56 -06:00
|
|
|
import chalk from 'chalk';
|
|
|
|
|
2020-10-25 09:24:48 -05:00
|
|
|
class Logger {
|
|
|
|
constructor() {
|
|
|
|
this.verboseness = {};
|
2020-12-08 10:40:56 -06:00
|
|
|
this.colors = {};
|
2020-10-25 09:24:48 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
verbose(module, verboseness, message, ...extras) {
|
2020-12-08 10:40:56 -06:00
|
|
|
let colorFunc = chalk[this.colors[module] || 'white'];
|
|
|
|
if (typeof colorFunc !== 'function') colorFunc = chalk.white;
|
|
|
|
|
2020-12-08 11:16:32 -06:00
|
|
|
if ((this.verboseness[module] || 1) >= verboseness)
|
|
|
|
console.log(`[${colorFunc(module)}][${verboseness}] ${message}`, ...extras);
|
2020-10-25 09:24:48 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
setVerboseness(module, verboseness) {
|
|
|
|
this.verboseness[module] = verboseness;
|
|
|
|
}
|
2020-12-08 10:40:56 -06:00
|
|
|
|
|
|
|
setColor(module, color) {
|
|
|
|
this.colors[module] = color;
|
|
|
|
}
|
2020-10-25 09:24:48 -05:00
|
|
|
}
|
|
|
|
|
2020-10-25 09:28:36 -05:00
|
|
|
export default new Logger();
|