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.
This commit is contained in:
Luke Hagar
2025-10-01 23:04:06 +00:00
parent c4a250359f
commit 531a3897a1

View File

@@ -68,7 +68,10 @@ export class Logger {
private getTimestamp(): string { private getTimestamp(): string {
if (!this.config.showTimestamps) return ""; if (!this.config.showTimestamps) return "";
const now = new Date(); 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 { private getColorCode(level: keyof LogLevel): string {
@@ -157,7 +160,7 @@ export class Logger {
label, label,
percentage: 0, percentage: 0,
}; };
this.updateProgress(); this.updateProgress(0);
} }
public updateProgress(current: number): void { public updateProgress(current: number): void {
@@ -167,10 +170,10 @@ export class Logger {
this.currentProgress.percentage = Math.round( this.currentProgress.percentage = Math.round(
(current / this.currentProgress.total) * 100 (current / this.currentProgress.total) * 100
); );
this.updateProgress(); this.renderProgress();
} }
public updateProgress(): void { private renderProgress(): void {
if (!this.currentProgress || !this.config.showProgress) return; if (!this.currentProgress || !this.config.showProgress) return;
const { current, total, label, percentage } = this.currentProgress; const { current, total, label, percentage } = this.currentProgress;