SquadJS/core/logger.js

37 lines
841 B
JavaScript
Raw Normal View History

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 = {};
this.includeTimestamps = false;
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(
`${this.includeTimestamps ? '[' + new Date().toISOString() + ']' : ''}[${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;
}
setTimeStamps(option) {
this.includeTimestamps = option;
}
2020-10-25 09:24:48 -05:00
}
2020-10-25 09:28:36 -05:00
export default new Logger();