diff --git a/src/common/log.ts b/src/common/log.ts index 4d63a6c..0118d83 100644 --- a/src/common/log.ts +++ b/src/common/log.ts @@ -14,20 +14,21 @@ const formatTime = (date: Date): string => date.toTimeString().split(" ")[0]; export class Log { static level = level; + static colorPatterns: [string, (m: string) => string][] = [ + ["_", colors.cyan], + ["\\*", colors.magenta], + ["!", colors.red], + ]; static colorize(pattern: string) { - for (const item of [ - ["_", colors.cyan], - ["\\*", colors.magenta], - ["!", colors.red], - ]) { + for (const item of this.colorPatterns) { const r = new RegExp(item[0] + "(.*?)" + item[0], "g"); pattern = pattern.replace(r, item[1]("$1")); } return pattern; } - static write(level: number, tag: string, pattern: string, ...args: any) { + static write(level: number, tag: string, pattern: string, args: any[]) { if (level >= this.level) { const message = `[${colors.gray(formatTime(new Date()))}] ${colors.green(tag)} ${this.colorize(pattern)}`; console.log(message, ...args); @@ -40,23 +41,23 @@ export class Log { this.tag = tag; } - v(...args: any) { - Log.write(-1, this.tag, ...args); + v(message: string, ...args: any) { + Log.write(-1, this.tag, message, args); } - d(...args: any) { - Log.write(0, this.tag, ...args); + d(message: string, ...args: any) { + Log.write(0, this.tag, message, args); } - i(...args: any) { - Log.write(1, this.tag, ...args); + i(message: string, ...args: any) { + Log.write(1, this.tag, message, args); } - w(...args: any) { - Log.write(2, this.tag, ...args); + w(message: string, ...args: any) { + Log.write(2, this.tag, message, args); } - e(...args: any) { - Log.write(3, this.tag, ...args); + e(message: string, ...args: any) { + Log.write(3, this.tag, message, args); } }