Binato/consoleHelper.js

63 lines
1.3 KiB
JavaScript
Raw Normal View History

2020-08-27 13:09:35 +01:00
const chalk = require("chalk");
2022-05-10 12:35:36 +01:00
const LogType = {
INFO: 0,
WARN: 1,
ERROR: 2
}
const LogTags = {
BANCHO: chalk.bgMagenta(chalk.black(" BANCHO ")),
WEBREQ: chalk.bgGreen(chalk.black(" WEBREQ ")),
CHAT: chalk.bgCyan(chalk.black(" CHATTO ")),
WARN: chalk.bgYellow(chalk.black(" WARNIN ")),
ERROR: chalk.bgRed(" ERROR! "),
REDIS: chalk.bgRed(chalk.white(" bREDIS "))
}
function correctValue(i) {
if (i <= 9) return "0"+i;
else return i;
}
function getTime() {
const time = new Date();
return chalk.green(`[${correctValue(time.getHours())}:${correctValue(time.getMinutes())}:${correctValue(time.getSeconds())}]`);
}
function log(tag = "", log = "", logType = LogType.INFO) {
switch (logType) {
case LogType.INFO:
return console.log(`${getTime()} ${tag} ${log}`);
case LogType.WARN:
return console.warn(`${getTime()} ${tag} ${log}`);
case LogType.ERROR:
return console.error(`${getTime()} ${tag} ${log}`);
}
}
2020-08-27 13:09:35 +01:00
module.exports = {
printWebReq:function(s) {
2022-05-10 12:35:36 +01:00
log(LogTags.WEBREQ, s);
},
printBancho:function(s) {
2022-05-10 12:35:36 +01:00
log(LogTags.BANCHO, s);
},
printRedis:function(s) {
log(LogTags.REDIS, s);
},
2020-08-27 13:09:35 +01:00
printChat:function(s) {
2022-05-10 12:35:36 +01:00
log(LogTags.CHAT, s);
},
2020-08-27 13:09:35 +01:00
printWarn:function(s) {
2022-05-10 12:35:36 +01:00
log(LogTags.WARN, chalk.yellow(s), LogType.WARN);
},
printError:function(s) {
2022-05-10 12:35:36 +01:00
log(LogTags.ERROR, chalk.red(s), LogType.ERROR);
}
2020-08-27 13:09:35 +01:00
}