JaBa/helpers/logger.js
2024-12-08 18:00:26 +03:00

47 lines
1.1 KiB
JavaScript

import chalk from "chalk";
function format(tDate) {
return new Intl.DateTimeFormat("ru-RU", {
year: "numeric",
month: "2-digit",
day: "2-digit",
hour: "2-digit",
minute: "2-digit",
second: "2-digit",
}).format(tDate);
}
const logLevels = {
LOG: chalk.bgBlue("LOG"),
WARN: chalk.black.bgYellow("WARN"),
ERROR: chalk.black.bgRed("ERROR"),
DEBUG: chalk.green("DEBUG"),
CMD: chalk.black.bgWhite("CMD"),
READY: chalk.black.bgGreen("READY"),
};
export default {
log(content) {
return console.log(`[${format(Date.now())}]: ${logLevels.LOG} ${content}`);
},
warn(content) {
return console.log(`[${format(Date.now())}]: ${logLevels.WARN} ${content}`);
},
error(content) {
return console.log(`[${format(Date.now())}]: ${logLevels.ERROR} ${content}`);
},
debug(content) {
return console.log(`[${format(Date.now())}]: ${logLevels.DEBUG} ${content}`);
},
cmd(content) {
return console.log(`[${format(Date.now())}]: ${logLevels.CMD} ${content}`);
},
ready(content) {
return console.log(`[${format(Date.now())}]: ${logLevels.READY} ${content}`);
},
};