JaBa/helpers/logger.js

65 lines
1.5 KiB
JavaScript
Raw Permalink Normal View History

2022-01-04 02:18:28 +05:00
const { bgBlue, black, green } = require("chalk");
function dateTimePad(value, digits) {
let number = value;
while (number.toString().length < digits) number = "0" + number;
return number;
2022-01-13 00:26:23 +05:00
}
2022-01-04 02:18:28 +05:00
function format(tDate) {
2023-07-05 00:58:06 +05:00
return (
dateTimePad(tDate.getDate(), 2) +
"-" +
dateTimePad(tDate.getMonth() + 1, 2) +
"-" +
dateTimePad(tDate.getFullYear(), 2) +
" " +
dateTimePad(tDate.getHours(), 2) +
":" +
dateTimePad(tDate.getMinutes(), 2) +
":" +
dateTimePad(tDate.getSeconds(), 2) +
"." +
dateTimePad(tDate.getMilliseconds(), 3)
);
2022-01-13 00:26:23 +05:00
}
2022-01-04 02:18:28 +05:00
module.exports = class Logger {
static log(content) {
2022-01-04 02:18:28 +05:00
const date = `[${format(new Date(Date.now()))}]:`;
return console.log(`${date} ${bgBlue("LOG")} ${content}`);
}
static warn(content) {
const date = `[${format(new Date(Date.now()))}]:`;
return console.log(`${date} ${black.bgYellow("WARN")} ${content}`);
}
static error(content) {
const date = `[${format(new Date(Date.now()))}]:`;
return console.log(`${date} ${black.bgRed("ERROR")} ${content}`);
}
static debug(content) {
const date = `[${format(new Date(Date.now()))}]:`;
return console.log(`${date} ${green("DEBUG")} ${content}`);
}
static cmd(content) {
const date = `[${format(new Date(Date.now()))}]:`;
return console.log(`${date} ${black.bgWhite("CMD")} ${content}`);
}
static ready(content) {
const date = `[${format(new Date(Date.now()))}]:`;
return console.log(`${date} ${black.bgGreen("READY")} ${content}`);
2022-01-04 02:18:28 +05:00
}
2023-07-05 00:58:06 +05:00
};