Skip to content

Commit cd66805

Browse files
WMS-29064 | feat(cli): add timestamps and duration logging for progress steps
1 parent 7fc843e commit cd66805

File tree

1 file changed

+32
-4
lines changed

1 file changed

+32
-4
lines changed

src/custom-logger/task-logger.js

Lines changed: 32 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@ class CustomSpinnerBar {
2424
this.lastProgressValue = -1;
2525
this.renderCount = 0;
2626

27+
this.startTime = null;
28+
2729
// Only render every 10th frame to reduce I/O operations
2830
this.renderThrottle = 10;
2931

@@ -42,6 +44,7 @@ class CustomSpinnerBar {
4244
this.isSpinning = true;
4345
this.frameIndex = 0;
4446
this.renderCount = 0;
47+
this.startTime = Date.now();
4548
this.resetProgressBar();
4649
this.progressBar.start();
4750

@@ -73,12 +76,36 @@ class CustomSpinnerBar {
7376
return this;
7477
}
7578

79+
getElapsedTime() {
80+
if (!this.startTime) return 0;
81+
return this.formatTime(Date.now() - this.startTime);
82+
}
83+
84+
formatTime(milliseconds) {
85+
const seconds = Math.floor(milliseconds / 1000);
86+
const ms = milliseconds % 1000;
87+
88+
if (seconds < 60) {
89+
return `${seconds}.${Math.floor(ms / 100)}s`;
90+
}
91+
92+
const minutes = Math.floor(seconds / 60);
93+
const remainingSeconds = seconds % 60;
94+
return `${minutes}m ${remainingSeconds}s`;
95+
}
96+
97+
getTimestamp() {
98+
const now = new Date();
99+
return now.toTimeString().split(' ')[0];
100+
}
101+
76102
succeed(text) {
77103
if (global?.verbose) return this;
78104
this.stop();
79105

80106
this.progressBar.setProgress(this.progressBar.total);
81-
const output = `${chalk.green("✔")} ${text || this.text} ${this.progressBar.render()}`;
107+
const finalText = text || this.text;
108+
const output = `${chalk.gray(`[${this.getTimestamp()}]`)} ${chalk.green("✔")} ${finalText} ${this.progressBar.render()} ${chalk.gray(`(${this.getElapsedTime()})`)}`;
82109
this.clearLine();
83110
this.writeLine(output);
84111
return this;
@@ -91,24 +118,25 @@ class CustomSpinnerBar {
91118
if(global.logDirectory){
92119
finalText += chalk.gray(" Check logs at: ") + chalk.cyan(global.logDirectory);
93120
}
121+
94122
this.clearLine();
95-
this.writeLine(`${chalk.red('✖')} ${chalk.bold.red(finalText)}`);
123+
this.writeLine(`${chalk.gray(`[${this.getTimestamp()}]`)} ${chalk.red('✖')} ${chalk.bold.red(finalText)} ${chalk.gray(`(${this.getElapsedTime()})`)}`);
96124
process.exit(1);
97125
}
98126

99127
info(text) {
100128
if (global.verbose) return this;
101129
this.stop();
102130
this.clearLine();
103-
this.writeLine(`${chalk.blue("ℹ")} ${text || this.text}`);
131+
this.writeLine(`${chalk.gray(`[${this.getTimestamp()}]`)} ${chalk.blue("ℹ")} ${text || this.text}`);
104132
return this;
105133
}
106134

107135
warn(text) {
108136
if (global.verbose) return this;
109137
this.stop();
110138
this.clearLine();
111-
this.writeLine(`${chalk.yellow("⚠")} ${text || this.text}`);
139+
this.writeLine(`${chalk.gray(`[${this.getTimestamp()}]`)} ${chalk.yellow("⚠")} ${text || this.text}`);
112140
return this;
113141
}
114142

0 commit comments

Comments
 (0)