dont show all 20 send messages
support muting a logger and chaining calls
This commit is contained in:
parent
dcf96e1461
commit
244d5b0851
2 changed files with 29 additions and 5 deletions
|
@ -35,25 +35,46 @@ class Logger {
|
|||
constructor(username) {
|
||||
this.indent = 0;
|
||||
this.username = username;
|
||||
this.muted = false;
|
||||
}
|
||||
|
||||
startGroup(description) {
|
||||
const indent = " ".repeat(this.indent * 2);
|
||||
console.log(`${indent} * ${this.username} ${description}:`);
|
||||
if (!this.muted) {
|
||||
const indent = " ".repeat(this.indent * 2);
|
||||
console.log(`${indent} * ${this.username} ${description}:`);
|
||||
}
|
||||
this.indent += 1;
|
||||
return this;
|
||||
}
|
||||
|
||||
endGroup() {
|
||||
this.indent -= 1;
|
||||
return this;
|
||||
}
|
||||
|
||||
step(description) {
|
||||
const indent = " ".repeat(this.indent * 2);
|
||||
process.stdout.write(`${indent} * ${this.username} ${description} ... `);
|
||||
if (!this.muted) {
|
||||
const indent = " ".repeat(this.indent * 2);
|
||||
process.stdout.write(`${indent} * ${this.username} ${description} ... `);
|
||||
}
|
||||
return this;
|
||||
}
|
||||
|
||||
done(status = "done") {
|
||||
process.stdout.write(status + "\n");
|
||||
if (!this.muted) {
|
||||
process.stdout.write(status + "\n");
|
||||
}
|
||||
return this;
|
||||
}
|
||||
|
||||
mute() {
|
||||
this.muted = true;
|
||||
return this;
|
||||
}
|
||||
|
||||
unmute() {
|
||||
this.muted = false;
|
||||
return this;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue