JaBa/helpers/logger.js

53 lines
1.3 KiB
JavaScript
Raw 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) {
2024-11-18 19:19:24 +05:00
return console.log(`[${format(new Date(Date.now()))}]: ${bgBlue("LOG")} ${content}`);
}
static warn(content) {
2024-11-18 19:19:24 +05:00
return console.log(`[${format(new Date(Date.now()))}]: ${black.bgYellow("WARN")} ${content}`);
}
static error(content) {
2024-11-18 19:19:24 +05:00
return console.log(`[${format(new Date(Date.now()))}]: ${black.bgRed("ERROR")} ${content}`);
}
static debug(content) {
2024-11-18 19:19:24 +05:00
return console.log(`[${format(new Date(Date.now()))}]: ${green("DEBUG")} ${content}`);
}
static cmd(content) {
2024-11-18 19:19:24 +05:00
return console.log(`[${format(new Date(Date.now()))}]: ${black.bgWhite("CMD")} ${content}`);
}
static ready(content) {
2024-11-18 19:19:24 +05:00
return console.log(`[${format(new Date(Date.now()))}]: ${black.bgGreen("READY")} ${content}`);
2022-01-04 02:18:28 +05:00
}
2023-07-05 00:58:06 +05:00
};