JaBa/helpers/logger.js

53 lines
1.2 KiB
JavaScript
Raw Normal View History

2024-12-05 20:15:07 +05:00
import { bgBlue, black, green } from "chalk";
2022-01-04 02:18:28 +05:00
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
2024-12-05 20:15:07 +05:00
export default {
log(content) {
2024-11-18 19:19:24 +05:00
return console.log(`[${format(new Date(Date.now()))}]: ${bgBlue("LOG")} ${content}`);
2024-12-05 20:15:07 +05:00
},
2024-12-05 20:15:07 +05:00
warn(content) {
2024-11-18 19:19:24 +05:00
return console.log(`[${format(new Date(Date.now()))}]: ${black.bgYellow("WARN")} ${content}`);
2024-12-05 20:15:07 +05:00
},
2024-12-05 20:15:07 +05:00
error(content) {
2024-11-18 19:19:24 +05:00
return console.log(`[${format(new Date(Date.now()))}]: ${black.bgRed("ERROR")} ${content}`);
2024-12-05 20:15:07 +05:00
},
2024-12-05 20:15:07 +05:00
debug(content) {
2024-11-18 19:19:24 +05:00
return console.log(`[${format(new Date(Date.now()))}]: ${green("DEBUG")} ${content}`);
2024-12-05 20:15:07 +05:00
},
2024-12-05 20:15:07 +05:00
cmd(content) {
2024-11-18 19:19:24 +05:00
return console.log(`[${format(new Date(Date.now()))}]: ${black.bgWhite("CMD")} ${content}`);
2024-12-05 20:15:07 +05:00
},
2024-12-05 20:15:07 +05:00
ready(content) {
2024-11-18 19:19:24 +05:00
return console.log(`[${format(new Date(Date.now()))}]: ${black.bgGreen("READY")} ${content}`);
2024-12-05 20:15:07 +05:00
},
2023-07-05 00:58:06 +05:00
};