This repository has been archived by the owner on Dec 9, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 31
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
✨ Introduce new logger system (#471)
* ✨ Introduce new logger system * 🔖 Tag!
- Loading branch information
Jasper Mayone
authored
Aug 28, 2022
1 parent
b83f40b
commit ef5484d
Showing
13 changed files
with
140 additions
and
92 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
import chalk from "chalk"; | ||
import moment from "moment"; | ||
|
||
export const log = ( | ||
content: string, | ||
type: | ||
| "log" | ||
| "info" | ||
| "warn" | ||
| "error" | ||
| "debug" | ||
| "load" | ||
| "ready" | ||
| "mongo" | ||
| "heptagram" = "log" | ||
) => { | ||
const timestamp = `${chalk.white(`[${moment().format("DD-MM-YY H:m:s")}]`)}`; | ||
|
||
switch (type) { | ||
case "log": | ||
return console.log(`${chalk.grey("[LOG]")} ${timestamp} ${content}`); | ||
case "info": | ||
return console.log( | ||
`${chalk.blueBright("[INFO]")} ${timestamp} ${chalk.blueBright( | ||
content | ||
)}` | ||
); | ||
case "warn": | ||
return console.log( | ||
`${chalk.yellow("[WARN]")} ${timestamp} ${chalk.yellow(content)} ` | ||
); | ||
case "error": | ||
return console.log( | ||
`${chalk.red("[ERROR]")} ${timestamp} ${chalk.red(content)} ` | ||
); | ||
case "debug": | ||
return console.log( | ||
`${chalk.blueBright("[DEBUG]")} ${timestamp} ${chalk.magenta( | ||
content | ||
)} ` | ||
); | ||
case "load": { | ||
return console.log( | ||
`${timestamp} ${chalk.magenta(type.toUpperCase())} ${content} ` | ||
); | ||
} | ||
case "ready": | ||
return console.log( | ||
`${chalk.green("[READY]")} ${timestamp} ${chalk.green(content)}` | ||
); | ||
case "mongo": | ||
return console.log( | ||
`${chalk.hex("#f1421a")("[MONGO]")} ${timestamp} ${chalk.hex("#f1421a")( | ||
content | ||
)}` | ||
); | ||
case "heptagram": | ||
return console.log( | ||
`${chalk.hex("#FFF800")("[HEPTAGRAM]")} ${timestamp} ${chalk.hex( | ||
"#FFF800" | ||
)(`${content}`)}` | ||
); | ||
default: | ||
throw new TypeError("Logger type not correct."); | ||
} | ||
}; | ||
|
||
export const info = (content: string) => log(content, "info"); | ||
export const warn = (content: string) => log(content, "warn"); | ||
export const error = (content: string) => log(content, "error"); | ||
export const debug = (content: string) => log(content, "debug"); | ||
export const load = (content: string) => log(content, "load"); | ||
export const ready = (content: string) => log(content, "ready"); | ||
export const mongo = (content: string) => log(content, "mongo"); | ||
export const heptagram = (content: string) => log(content, "heptagram"); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
/** | ||
* gets a random number between min and max | ||
* | ||
* @param {number} min | ||
* @param {number} max | ||
* @returns {number} A human-readable format of the number of seconds. | ||
*/ | ||
export const randomNumber = (min: number, max: number): number => { | ||
return Math.floor(Math.random() * (max - min)) + min; | ||
}; |
Oops, something went wrong.