mirror of
https://github.com/AsgardEternal/SquadJS.git
synced 2024-09-28 11:54:23 -05:00
fd7483a323
Change logger string constructor; By default, no logging enabled. if timestamps exists in logger config, timestamps enabled
37 lines
841 B
JavaScript
37 lines
841 B
JavaScript
import chalk from 'chalk';
|
|
|
|
class Logger {
|
|
constructor() {
|
|
this.verboseness = {};
|
|
this.colors = {};
|
|
this.includeTimestamps = false;
|
|
}
|
|
|
|
verbose(module, verboseness, message, ...extras) {
|
|
let colorFunc = chalk[this.colors[module] || 'white'];
|
|
if (typeof colorFunc !== 'function') colorFunc = chalk.white;
|
|
|
|
if ((this.verboseness[module] || 1) >= verboseness)
|
|
console.log(
|
|
`${this.includeTimestamps ? '[' + new Date().toISOString() + ']' : ''}[${colorFunc(
|
|
module
|
|
)}][${verboseness}] ${message}`,
|
|
...extras
|
|
);
|
|
}
|
|
|
|
setVerboseness(module, verboseness) {
|
|
this.verboseness[module] = verboseness;
|
|
}
|
|
|
|
setColor(module, color) {
|
|
this.colors[module] = color;
|
|
}
|
|
|
|
setTimeStamps(option) {
|
|
this.includeTimestamps = option;
|
|
}
|
|
}
|
|
|
|
export default new Logger();
|