Skip to content

Commit

Permalink
[New] Created logger function for better console output
Browse files Browse the repository at this point in the history
  • Loading branch information
naseif committed Sep 30, 2021
1 parent a3d0d32 commit b6031a4
Showing 1 changed file with 32 additions and 0 deletions.
32 changes: 32 additions & 0 deletions modules/logger.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
const moment = require("moment");
const chalk = require("chalk");

/**
*
* @param {string} message
* @param {string} type
* @returns
*/

module.exports.logger = (message, type = "log") => {
const date = `${moment().format("DD-MM-YYYY hh:mm:ss")}`;

switch (type) {
case "log":
return console.log(
`[${chalk.gray(date)}]: [${chalk.black.bgBlue(
type.toUpperCase()
)}] ${message}`
);
case "error":
return console.log(
`[${chalk.gray(date)}]: [${chalk.black.bgRed(
type.toUpperCase()
)}] ${message}`
);
default:
throw new TypeError(
"Logger type must be either warn, debug, log, ready, cmd or error."
);
}
};

0 comments on commit b6031a4

Please sign in to comment.