mirror of
https://github.com/JonnyBro/JaBa.git
synced 2024-11-29 00:24:58 +05:00
52 lines
No EOL
1.4 KiB
JavaScript
52 lines
No EOL
1.4 KiB
JavaScript
const { bgBlue, black, green } = require("chalk");
|
|
|
|
function dateTimePad(value, digits) {
|
|
let number = value;
|
|
while (number.toString().length < digits) number = "0" + number;
|
|
|
|
return number;
|
|
}
|
|
|
|
function format(tDate) {
|
|
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));
|
|
}
|
|
|
|
module.exports = class Logger {
|
|
static log(content, type = "log") {
|
|
const date = `[${format(new Date(Date.now()))}]:`;
|
|
switch (type) {
|
|
case "log": {
|
|
return console.log(`${date} ${bgBlue(type.toUpperCase())} ${content} `);
|
|
}
|
|
|
|
case "warn": {
|
|
return console.log(`${date} ${black.bgYellow(type.toUpperCase())} ${content} `);
|
|
}
|
|
|
|
case "error": {
|
|
return console.log(`${date} ${black.bgRed(type.toUpperCase())} ${content} `);
|
|
}
|
|
|
|
case "debug": {
|
|
return console.log(`${date} ${green(type.toUpperCase())} ${content} `);
|
|
}
|
|
|
|
case "cmd": {
|
|
return console.log(`${date} ${black.bgWhite(type.toUpperCase())} ${content}`);
|
|
}
|
|
|
|
case "ready": {
|
|
return console.log(`${date} ${black.bgGreen(type.toUpperCase())} ${content}`);
|
|
}
|
|
|
|
default:
|
|
throw new TypeError("Logger type must be either warn, debug, log, ready, cmd or error.");
|
|
}
|
|
}
|
|
}; |