From 57d5e6466e456c5398adbc1ac2204918831626b5 Mon Sep 17 00:00:00 2001 From: npmrun <1549469775@qq.com> Date: Sun, 19 Apr 2026 12:04:08 +0800 Subject: [PATCH] feat: add Logger core module --- src/core/Logger.ts | 41 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 41 insertions(+) create mode 100644 src/core/Logger.ts diff --git a/src/core/Logger.ts b/src/core/Logger.ts new file mode 100644 index 0000000..820246e --- /dev/null +++ b/src/core/Logger.ts @@ -0,0 +1,41 @@ +type LogLevel = "debug" | "info" | "warn" | "error" | "none"; + +class Logger { + private level: LogLevel = "debug"; + + setLevel(level: LogLevel): void { + this.level = level; + } + + debug(...args: any[]): void { + if (this.shouldLog("debug")) { + console.debug(...args); + } + } + + info(...args: any[]): void { + if (this.shouldLog("info")) { + console.info(...args); + } + } + + warn(...args: any[]): void { + if (this.shouldLog("warn")) { + console.warn(...args); + } + } + + error(...args: any[]): void { + if (this.shouldLog("error")) { + console.error(...args); + } + } + + private shouldLog(level: LogLevel): boolean { + const levels: LogLevel[] = ["debug", "info", "warn", "error", "none"]; + return levels.indexOf(level) >= levels.indexOf(this.level); + } +} + +export const logger = new Logger(); +export default logger;