Skip to content

Commit

Permalink
Merge pull request #818 from forcedotcom/ew/logger-loop
Browse files Browse the repository at this point in the history
Fix logging loop
  • Loading branch information
mshanemc committed Apr 21, 2023
2 parents c17a69f + a9f9a47 commit 28f564e
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 9 deletions.
6 changes: 4 additions & 2 deletions src/logger.ts
Original file line number Diff line number Diff line change
Expand Up @@ -762,8 +762,10 @@ export class Logger {
*/
public fatal(...args: unknown[]): Logger {
// always show fatal to stderr
// eslint-disable-next-line no-console
console.error(...args);
// IMPORTANT:
// Do not use console.error() here, if fatal() is called from the uncaughtException handler, it
// will be re-thrown and caught again by the uncaughtException handler, causing an infinite loop.
console.log(...args); // eslint-disable-line no-console
this.bunyan.fatal(this.applyFilters(LoggerLevel.FATAL, ...args));
return this;
}
Expand Down
8 changes: 1 addition & 7 deletions test/unit/loggerTest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -280,13 +280,7 @@ describe('Logger', () => {

it('should apply for log level: error', () => runTest(['error', 50]));

it('should apply for log level: fatal', async () => {
// logger.fatal() necessarily writes to stderr so stub it here
$$.SANDBOX.stub(process.stderr, 'write');
await runTest(['fatal', 60]);
// @ts-expect-error: called is a sinon spy property
expect(process.stderr.write['called']).to.be.true;
});
it('should apply for log level: fatal', () => runTest(['fatal', 60]));
});

describe('addField', () => {
Expand Down

0 comments on commit 28f564e

Please sign in to comment.