Skip to content

Commit ef1e958

Browse files
committed
fix: improvements based on feedback
1 parent 243c6b1 commit ef1e958

File tree

3 files changed

+22
-8
lines changed

3 files changed

+22
-8
lines changed

spec/logger.spec.ts

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import { expect } from "chai";
22

33
import * as logger from "../src/logger";
44
import { setGlobalOptions } from "../src/v2";
5+
import { getGlobalOptions } from "../src/v2/options";
56

67
describe("logger", () => {
78
const stdoutWrite = process.stdout.write.bind(process.stdout);
@@ -221,24 +222,37 @@ describe("logger", () => {
221222
});
222223

223224
describe("error logging stacktrace", () => {
224-
it("should include stacktrace in error logs", () => {
225+
const defaultOptions = getGlobalOptions();
226+
227+
beforeEach(() => {
228+
setGlobalOptions(defaultOptions);
229+
});
230+
231+
it("when disableErrorLoggingStacktrace is set to false, should include stacktrace in error logs", () => {
225232
const message = "Test error with stacktrace";
233+
setGlobalOptions({
234+
disableErrorLoggingStacktrace: false,
235+
});
226236
logger.error(message);
227237
const messageOutput = JSON.parse(lastErr.trim()).message;
228238

229239
expect(messageOutput).to.include(`Error: ${message}`);
230240
});
231241

232-
it("when disableErrorLoggingTraceback is set to true, should not log stacktrace", () => {
233-
const message = "Test error with traceback disabled";
242+
it("when disableErrorLoggingStacktrace is set to true, should not include stacktrace in error logs", () => {
243+
const message = "Test error with stacktrace disabled";
234244
setGlobalOptions({
235-
disableErrorLoggingTraceback: true,
245+
disableErrorLoggingStacktrace: true,
236246
});
237247
logger.error(message);
238248
expectStderr({
239249
severity: "ERROR",
240250
message: message,
241251
});
242252
});
253+
254+
afterEach(() => {
255+
setGlobalOptions(defaultOptions);
256+
});
243257
});
244258
});

src/logger/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -161,7 +161,7 @@ function entryFromArgs(severity: LogSeverity, args: any[]): LogEntry {
161161
let message = format(...args);
162162
if (
163163
severity === "ERROR" &&
164-
!getGlobalOptions().disableErrorLoggingTraceback &&
164+
!getGlobalOptions().disableErrorLoggingStacktrace &&
165165
!args.find((arg) => arg instanceof Error)
166166
) {
167167
message = new Error(message).stack || message;

src/v2/options.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -234,13 +234,13 @@ export interface GlobalOptions {
234234
preserveExternalChanges?: boolean;
235235

236236
/**
237-
* Controls whether error logging should include the traceback of the error automatically.
237+
* Controls whether error logging should include the stacktrace of the error automatically.
238238
* Defaults to false.
239239
*
240240
* @remarks
241-
* When true, the error message will include not include the traceback of the error.
241+
* When true, the error message will not include the stacktrace of the error.
242242
*/
243-
disableErrorLoggingTraceback?: boolean;
243+
disableErrorLoggingStacktrace?: boolean;
244244
}
245245

246246
let globalOptions: GlobalOptions | undefined;

0 commit comments

Comments
 (0)