Skip to content

Commit

Permalink
refactor: intercept logs
Browse files Browse the repository at this point in the history
  • Loading branch information
venki91 committed Aug 12, 2024
1 parent e0df57d commit d52a711
Showing 1 changed file with 9 additions and 5 deletions.
14 changes: 9 additions & 5 deletions lib/main/logs/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,21 +45,25 @@ const logCollector = {
}
});
}
process.stdout.write = this.originalStdoutWrite;
process.stderr.write = this.originalStderrWrite;

if (this.enableConsoleOutput) {
process.stdout.write = this.originalStdoutWrite;
process.stderr.write = this.originalStderrWrite;
} else {
process.stdout.write = (chunk, encoding, done) => done();
process.stderr.write = (chunk, encoding, done) => done();
}
if (this.collectLogs.includes(LogLevel.INFO)) {
this.interceptLogs(LogLevel.INFO);
console.log(`Errsole is capturing ${LogLevel.INFO.toUpperCase()} logs.`);
} else {
console.log(`Errsole is NOT capturing ${LogLevel.INFO.toUpperCase()} logs.`);
if (!this.enableConsoleOutput) process.stdout.write = (chunk, encoding, done) => done();
}
if (this.collectLogs.includes(LogLevel.ERROR)) {
this.interceptLogs(LogLevel.ERROR);
console.log(`Errsole is capturing ${LogLevel.ERROR.toUpperCase()} logs.`);
} else {
console.log(`Errsole is NOT capturing ${LogLevel.ERROR.toUpperCase()} logs.`);
if (!this.enableConsoleOutput) process.stderr.write = (chunk, encoding, done) => done();
}
},

Expand Down Expand Up @@ -155,7 +159,7 @@ const logCollector = {
logCollector.setInitializationTimeout();
logCollector.createLogStream();
logCollector.logStream.cork();
logCollector.interceptLogs(LogLevel.ERROR);
logCollector.interceptLogs(LogLevel.INFO);
logCollector.interceptLogs(LogLevel.ERROR);

module.exports = logCollector;

0 comments on commit d52a711

Please sign in to comment.