Skip to content

Commit

Permalink
fix: include time and scope in log file (#1951)
Browse files Browse the repository at this point in the history
  • Loading branch information
xiyaowong committed May 12, 2024
1 parent 1fc6752 commit cccdf99
Showing 1 changed file with 4 additions and 5 deletions.
9 changes: 4 additions & 5 deletions src/logger.ts
Original file line number Diff line number Diff line change
Expand Up @@ -87,11 +87,10 @@ export class Logger implements Disposable {
return p + (i > 0 ? " " : "") + c;
}, "");

if (this.fd) {
fs.appendFileSync(this.fd, msg + "\n");
}
if (this.logToConsole) {
console[level == LogLevel.error ? "error" : "log"](`${getTimestamp()} ${scope}: ${msg}`);
if (this.fd || this.logToConsole) {
const logMsg = `${getTimestamp()} ${scope}: ${msg}`;
this.fd && fs.appendFileSync(this.fd, logMsg + "\n");
this.logToConsole && console[level == LogLevel.error ? "error" : "log"](logMsg);
}

// Half-baked attempt to avoid infinite loop.
Expand Down

0 comments on commit cccdf99

Please sign in to comment.