-
Notifications
You must be signed in to change notification settings - Fork 25
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
improv: abtract the log to logger package
- Loading branch information
Showing
7 changed files
with
35 additions
and
20 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
export * from "./types.js"; | ||
export * from "./log.js"; |
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,28 @@ | ||
import loglevel from "loglevel"; | ||
import prefix from "loglevel-plugin-prefix"; | ||
|
||
export interface LoggerOptions { | ||
level?: loglevel.LogLevelDesc; | ||
} | ||
|
||
export class Logger { | ||
private log: loglevel.Logger; | ||
// biome-ignore lint/suspicious/noExplicitAny: Do this to allow any method to be called on the logger | ||
[key: string]: any; | ||
|
||
constructor(context: string, level: loglevel.LogLevelDesc = "info") { | ||
this.log = loglevel.getLogger(context); | ||
this.log.setLevel(level); | ||
prefix.reg(loglevel); | ||
prefix.apply(this.log, { | ||
template: "%n", | ||
}); | ||
|
||
for (const method of Object.keys(this.log)) { | ||
const logMethod = this.log[method as keyof loglevel.Logger]; | ||
if (typeof logMethod === "function") { | ||
this[method as string] = logMethod.bind(this.log); | ||
} | ||
} | ||
} | ||
} |
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 |
---|---|---|
|
@@ -3,5 +3,5 @@ | |
"compilerOptions": { | ||
"outDir": "dist" | ||
}, | ||
"include": ["src/**/*.ts"] | ||
"include": ["src/**/*.ts", "src/**/*.js"] | ||
} |
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