2020-10-20 05:47:05 +00:00
|
|
|
/**
|
|
|
|
* Colorful logger class from the Chariot.js Client framework featuring various log levels.
|
|
|
|
* Link: https://github.com/riyacchi/chariot.js/master/helpers/Logger.js
|
2020-10-25 02:10:11 +00:00
|
|
|
* This file is licensed under the AGPLv3 license (same as the Woomy project)
|
2020-10-20 05:47:05 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
const chalk = require('chalk');
|
|
|
|
|
|
|
|
class Logger {
|
|
|
|
/**
|
|
|
|
* Pads a single number for unified looks in the console
|
|
|
|
* @param {number} number The number that should be force-padded
|
|
|
|
* @returns {number} The padded number
|
|
|
|
*/
|
|
|
|
static _forcePadding (number) {
|
|
|
|
return (number < 10 ? '0' : '') + number;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Gets the full current system time and date for logging purposes
|
|
|
|
* @returns {string} The formatted current time
|
|
|
|
*/
|
|
|
|
static _getCurrentTime () {
|
|
|
|
const now = new Date();
|
|
|
|
const day = this._forcePadding(now.getDate());
|
|
|
|
const month = this._forcePadding(now.getMonth() + 1);
|
|
|
|
const year = this._forcePadding(now.getFullYear());
|
|
|
|
const hour = this._forcePadding(now.getHours());
|
|
|
|
const minute = this._forcePadding(now.getMinutes());
|
|
|
|
const second = this._forcePadding(now.getSeconds());
|
|
|
|
|
|
|
|
return `${day}.${month}.${year} ${hour}:${minute}:${second}`;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Log something related to being successful
|
2022-12-12 01:25:34 +00:00
|
|
|
* @param {string} title The title of the log entry
|
2020-10-20 05:47:05 +00:00
|
|
|
* @param {string} body The body of the log entry
|
|
|
|
* @returns {void}
|
|
|
|
*/
|
|
|
|
static success (title, body) {
|
|
|
|
console.log(chalk.bold.green(`[ ${this._getCurrentTime()} ] [ ${title} ] `) + body);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Log something related to a warning
|
2022-12-12 01:25:34 +00:00
|
|
|
* @param {string} title The title of the log entry
|
2020-10-20 05:47:05 +00:00
|
|
|
* @param {string} body The body of the log entry
|
|
|
|
* @returns {void}
|
|
|
|
*/
|
|
|
|
static warning (title, body) {
|
|
|
|
console.log(chalk.bold.yellow(`[ ${this._getCurrentTime()} ] [ ${title} ] `) + body);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Log something related to an error
|
2022-12-12 01:25:34 +00:00
|
|
|
* @param {string} title The title of the log entry
|
2020-10-20 05:47:05 +00:00
|
|
|
* @param {string} body The body of the log entry
|
|
|
|
* @returns {void}
|
|
|
|
*/
|
|
|
|
static error (title, body) {
|
|
|
|
console.log(chalk.bold.red(`[ ${this._getCurrentTime()} ] [ ${title} ] `) + body);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Log something related to debugging
|
2022-12-12 01:25:34 +00:00
|
|
|
* @param {string} title The title of the log entry
|
2020-10-20 05:47:05 +00:00
|
|
|
* @param {string} body The body of the log entry
|
|
|
|
* @returns {void}
|
|
|
|
*/
|
|
|
|
static debug (title, body) {
|
|
|
|
console.log(chalk.bold.magenta(`[ ${this._getCurrentTime()} ] [ ${title} ] `) + body);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Log something related to an event
|
|
|
|
* @param {string} body The body of the log entry
|
|
|
|
* @returns {void}
|
|
|
|
*/
|
|
|
|
static event (body) {
|
2020-10-20 08:30:46 +00:00
|
|
|
console.log(chalk.bold.blue(`[ ${this._getCurrentTime()} ] [ EVENT ] `) + body);
|
2020-10-20 05:47:05 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Log something related to command usage
|
|
|
|
* @param {string} body The body of the log entry
|
|
|
|
* @returns {void}
|
|
|
|
*/
|
|
|
|
static command (body) {
|
2020-10-21 07:07:03 +00:00
|
|
|
console.log(chalk.bold.white(`[ ${this._getCurrentTime()} ] [ COMMAND ] `) + body);
|
2020-10-20 05:47:05 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
module.exports = Logger;
|