Skip to content

Commit

Permalink
debugMode
Browse files Browse the repository at this point in the history
  • Loading branch information
PleahMaCaka committed Feb 6, 2023
1 parent 328b557 commit 3b90f58
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 6 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@pleahmacaka/logger",
"version": "2.0.0",
"version": "2.0.1",
"dependencies": {},
"description": "Simple TypeScript logger with no dependencies",
"main": "package/logger.js",
Expand Down
14 changes: 9 additions & 5 deletions src/logger.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ function date(): string {

export default class Logger {

public static debugLog: boolean = true

static log(type?: Level | LogType, ...content: any): void {
/**
* @param type Specifies the log type. Be like: Level.INFO
Expand All @@ -46,21 +48,22 @@ export default class Logger {
if (type === "CRITICAL") type = Level.CRITICAL

const date = `[${getDate()}] ::`

switch (type) {
case Level.INFO:
return console.log(color.green, `${date} [INFO] :: ${content}`, color.reset)
return Logger.info(content)

case Level.WARN:
return console.log(color.yellow, `${date} [WARN] :: ${content}`, color.reset)
return Logger.warn(content)

case Level.ERROR:
return console.log(color.red, `${date} [ERROR] :: ${content}`, color.reset)
return Logger.error(content)

case Level.DEBUG:
return console.log(color.blue, `${date} [DEBUG] :: ${content}`, color.reset)
return Logger.debug(content)

case Level.CRITICAL:
return console.log(color.red + color.bold, `${date} [CRITICAL] :: ${content}`, color.reset)
return Logger.critical(content)

default:
throw new TypeError("The logger must be of one of the following types: INFO, WARN, ERROR, DEBUG, CRITICAL")
Expand All @@ -77,6 +80,7 @@ export default class Logger {
return console.log(color.red, `${date()} [ERROR] :: ${content}`, color.reset)
}
public static debug(...content: any) {
if (!this.debugLog) return
return console.log(color.blue, `${date()} [DEBUG] :: ${content}`, color.reset)
}
public static critical(...content: any) {
Expand Down

0 comments on commit 3b90f58

Please sign in to comment.