SquadJS/core/logger.js
ect0s fd7483a323 Add Timestamps to logger
Change logger string constructor;

By default, no logging enabled.

if timestamps exists in logger config, timestamps enabled
2023-01-20 20:59:07 -05:00

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();