From bd66e7aa701e3fb5e48852b09881e37114626b8b Mon Sep 17 00:00:00 2001 From: neru Date: Sat, 10 Jan 2026 09:08:24 -0300 Subject: [PATCH] style: run format:apply --- src/utils/log.ts | 125 +++++++++++++++++++++++------------------------ 1 file changed, 62 insertions(+), 63 deletions(-) diff --git a/src/utils/log.ts b/src/utils/log.ts index b1c6f1f..b56d0ae 100644 --- a/src/utils/log.ts +++ b/src/utils/log.ts @@ -7,93 +7,92 @@ import 'colorts/lib/string'; helper fns */ function getCallerFrame(shift: number = 0): NodeJS.CallSite | undefined { - const prepareStackTrace = Error.prepareStackTrace; - let loggedStack: NodeJS.CallSite[] | undefined; + const prepareStackTrace = Error.prepareStackTrace; + let loggedStack: NodeJS.CallSite[] | undefined; - Error.prepareStackTrace = (_, stackTraces: NodeJS.CallSite[]) => { - loggedStack = stackTraces; - stackTraces.shift(); // discard curr frame - return stackTraces; - }; + Error.prepareStackTrace = (_, stackTraces: NodeJS.CallSite[]) => { + loggedStack = stackTraces; + stackTraces.shift(); // discard curr frame + return stackTraces; + }; - // eslint-disable-next-line @typescript-eslint/no-unused-expressions - new Error().stack; + // eslint-disable-next-line @typescript-eslint/no-unused-expressions + new Error().stack; - Error.prepareStackTrace = prepareStackTrace; + Error.prepareStackTrace = prepareStackTrace; - if (!loggedStack) return undefined; + if (!loggedStack) return undefined; - if (shift > 0) - for (let i = 0; i < shift; i++) - loggedStack.shift(); + if (shift > 0) for (let i = 0; i < shift; i++) loggedStack.shift(); - return loggedStack[1]; + return loggedStack[1]; } /* logger */ const LOG_TYPES = { - Info: "[Info]".green, - Verbose: "[Verbose]".blue, - Warning: "[Warning]".yellow, - Error: "[Error]".red, + Info: '[Info]'.green, + Verbose: '[Verbose]'.blue, + Warning: '[Warning]'.yellow, + Error: '[Error]'.red } as const; export class Logger { - private readonly name: string; + private readonly name: string; - constructor(name: string) { - this.name = name; - } + constructor(name: string) { + this.name = name; + } - public info(fmt: string, ...args: unknown[]): void { - this.log(LOG_TYPES.Info, fmt, args); - } + public info(fmt: string, ...args: unknown[]): void { + this.log(LOG_TYPES.Info, fmt, args); + } - public verbose(fmt: string, ...args: unknown[]): void { - this.log(LOG_TYPES.Verbose, fmt, args); - } + public verbose(fmt: string, ...args: unknown[]): void { + this.log(LOG_TYPES.Verbose, fmt, args); + } - public warning(fmt: string, ...args: unknown[]): void { - this.log(LOG_TYPES.Warning, fmt, args); - } + public warning(fmt: string, ...args: unknown[]): void { + this.log(LOG_TYPES.Warning, fmt, args); + } - public error(fmt: string, ...args: unknown[]): void { - this.log(LOG_TYPES.Error, fmt, args); - } + public error(fmt: string, ...args: unknown[]): void { + this.log(LOG_TYPES.Error, fmt, args); + } - private log(type: string, message: string, args: unknown[]): void { - const caller = getCallerFrame(1); - if (!caller) { - console.error('Failed to determine caller information'); - return; - } + private log(type: string, message: string, args: unknown[]): void { + const caller = getCallerFrame(1); + if (!caller) { + console.error('Failed to determine caller information'); + return; + } - const timestamp = this.getFormattedTime(); - const callerInfo = this.getCallerInfo(caller); - const formattedMessage = util.format(message, ...args); + const timestamp = this.getFormattedTime(); + const callerInfo = this.getCallerInfo(caller); + const formattedMessage = util.format(message, ...args); - console.log( - `${timestamp} - ${callerInfo} [${this.name.magenta}] ${type} ${formattedMessage}` - ); - } + console.log( + `${timestamp} - ${callerInfo} [${this.name.magenta}] ${type} ${formattedMessage}` + ); + } - private getFormattedTime(): string { - const now = new Date(); - return now.toLocaleTimeString('en-US', { - hour: '2-digit', - minute: '2-digit', - second: '2-digit', - hour12: false - }); - } + private getFormattedTime(): string { + const now = new Date(); + return now.toLocaleTimeString('en-US', { + hour: '2-digit', + minute: '2-digit', + second: '2-digit', + hour12: false + }); + } - private getCallerInfo(caller: NodeJS.CallSite): string { - const functionName = caller.getFunctionName()?.replace(/\[.*\]/, '') || ''; - const fileName = caller.getFileName() || 'unknown'; - const relativePath = path.relative(process.cwd(), fileName); + private getCallerInfo(caller: NodeJS.CallSite): string { + const functionName = + caller.getFunctionName()?.replace(/\[.*\]/, '') || ''; + const fileName = caller.getFileName() || 'unknown'; + const relativePath = path.relative(process.cwd(), fileName); - return `${functionName.cyan} @ ${relativePath.dim}`; - } + return `${functionName.cyan} @ ${relativePath.dim}`; + } }