Skip to content

Commit

Permalink
Refactor logger class for improved readability
Browse files Browse the repository at this point in the history
The dependency on the 'util' module's format function has been removed from logger.ts. This change simplifies the main functions such as info(), warning(), error(), and debug(). Previously, these functions were using the format function to construct the console.log string. Now, the string is constructed natively using template literals, thus improving code readability and maintainability. This modification should not affect the application's functionality, it's purely an improvement in the code structure.
  • Loading branch information
Ancocodet committed Nov 23, 2023
1 parent 5c148a7 commit 060d824
Showing 1 changed file with 4 additions and 10 deletions.
14 changes: 4 additions & 10 deletions src/lib/logger.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
import {format} from "util";

export class Logger {

private readonly debugState: boolean;
Expand All @@ -8,29 +6,25 @@ export class Logger {
this.debugState = debug
}

private logFormat() : string {
return "[%s|%s] %s"
}

private date() : string {
return new Date().toISOString()
}

public info(log: string) {
console.log(format(this.logFormat(), this.date(), "INFO", log))
console.log(`[${this.date()}|INFO] ${log}`)
}

public warning(log: string) {
console.log(format(this.logFormat(), this.date(), "WARNING", log))
console.log(`[${this.date()}|WARNING] ${log}`)
}

public error(log: string) {
console.log(format(this.logFormat(), this.date(), "ERROR", log))
console.log(`[${this.date()}|ERROR] ${log}`)
}

public debug(log: string) {
if(this.debugState)
console.log(format(this.logFormat(), this.date(), "DEBUG", log))
console.log(`[${this.date()}|DEBUG] ${log}`)
}

}

0 comments on commit 060d824

Please sign in to comment.