From 531a3897a1a3bb83dbbdd7f91cb5bc7401837613 Mon Sep 17 00:00:00 2001 From: Luke Hagar Date: Wed, 1 Oct 2025 23:04:06 +0000 Subject: [PATCH] Refactor logger methods for improved timestamp handling and progress updates - Enhanced the getTimestamp method to ensure proper formatting and handling of edge cases. - Updated updateProgress method to accept a current value parameter for better clarity. - Renamed updateProgress to renderProgress to better reflect its functionality in rendering progress output. --- src/logger.ts | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/src/logger.ts b/src/logger.ts index de425f6..17b6ffa 100644 --- a/src/logger.ts +++ b/src/logger.ts @@ -68,7 +68,10 @@ export class Logger { private getTimestamp(): string { if (!this.config.showTimestamps) return ""; const now = new Date(); - return `[${now.toISOString().split("T")[1].split(".")[0]}] `; + const timeString = now.toISOString().split("T")[1]; + if (!timeString) return ""; + const timePart = timeString.split(".")[0]; + return `[${timePart}] `; } private getColorCode(level: keyof LogLevel): string { @@ -157,7 +160,7 @@ export class Logger { label, percentage: 0, }; - this.updateProgress(); + this.updateProgress(0); } public updateProgress(current: number): void { @@ -167,10 +170,10 @@ export class Logger { this.currentProgress.percentage = Math.round( (current / this.currentProgress.total) * 100 ); - this.updateProgress(); + this.renderProgress(); } - public updateProgress(): void { + private renderProgress(): void { if (!this.currentProgress || !this.config.showProgress) return; const { current, total, label, percentage } = this.currentProgress;