Skip to content

Commit f7c468d

Browse files
authored
chore: Log only to stderr (#624)
1 parent 7f98448 commit f7c468d

File tree

2 files changed

+13
-12
lines changed

2 files changed

+13
-12
lines changed

packages/bundler-plugin-core/src/sentry/logger.ts

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,30 +11,31 @@ export type Logger = {
1111
debug(message: string, ...params: unknown[]): void;
1212
};
1313

14+
// Logging everything to stderr not to interfere with stdout
1415
export function createLogger(options: LoggerOptions): Logger {
1516
return {
1617
info(message: string, ...params: unknown[]) {
1718
if (!options.silent) {
1819
// eslint-disable-next-line no-console
19-
console.log(`${options.prefix} Info: ${message}`, ...params);
20+
console.error(`${options.prefix} Info: ${message}`, ...params);
2021
}
2122
},
2223
warn(message: string, ...params: unknown[]) {
2324
if (!options.silent) {
2425
// eslint-disable-next-line no-console
25-
console.log(`${options.prefix} Warning: ${message}`, ...params);
26+
console.error(`${options.prefix} Warning: ${message}`, ...params);
2627
}
2728
},
2829
error(message: string, ...params: unknown[]) {
2930
if (!options.silent) {
3031
// eslint-disable-next-line no-console
31-
console.log(`${options.prefix} Error: ${message}`, ...params);
32+
console.error(`${options.prefix} Error: ${message}`, ...params);
3233
}
3334
},
3435
debug(message: string, ...params: unknown[]) {
3536
if (!options.silent && options.debug) {
3637
// eslint-disable-next-line no-console
37-
console.log(`${options.prefix} Debug: ${message}`, ...params);
38+
console.error(`${options.prefix} Debug: ${message}`, ...params);
3839
}
3940
},
4041
};

packages/bundler-plugin-core/test/sentry/logger.test.ts

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
import { createLogger } from "../../src/sentry/logger";
22

33
describe("Logger", () => {
4-
const consoleLogSpy = jest.spyOn(console, "log").mockImplementation(() => undefined);
4+
const consoleErrorSpy = jest.spyOn(console, "error").mockImplementation(() => undefined);
55

66
afterEach(() => {
7-
consoleLogSpy.mockReset();
7+
consoleErrorSpy.mockReset();
88
});
99

1010
it.each([
@@ -17,7 +17,7 @@ describe("Logger", () => {
1717

1818
logger[loggerMethod]("Hey!");
1919

20-
expect(consoleLogSpy).toHaveBeenCalledWith(`[some-prefix] ${logLevel}: Hey!`);
20+
expect(consoleErrorSpy).toHaveBeenCalledWith(`[some-prefix] ${logLevel}: Hey!`);
2121
});
2222

2323
it.each([
@@ -30,7 +30,7 @@ describe("Logger", () => {
3030

3131
logger[loggerMethod]("Hey!", "this", "is", "a test with", 5, "params");
3232

33-
expect(consoleLogSpy).toHaveBeenCalledWith(
33+
expect(consoleErrorSpy).toHaveBeenCalledWith(
3434
`[some-prefix] ${logLevel}: Hey!`,
3535
"this",
3636
"is",
@@ -46,7 +46,7 @@ describe("Logger", () => {
4646

4747
logger.debug("Hey!");
4848

49-
expect(consoleLogSpy).toHaveBeenCalledWith(`[some-prefix] Debug: Hey!`);
49+
expect(consoleErrorSpy).toHaveBeenCalledWith(`[some-prefix] Debug: Hey!`);
5050
});
5151

5252
it(".debug() should log multiple params correctly", () => {
@@ -55,7 +55,7 @@ describe("Logger", () => {
5555

5656
logger.debug("Hey!", "this", "is", "a test with", 5, "params");
5757

58-
expect(consoleLogSpy).toHaveBeenCalledWith(
58+
expect(consoleErrorSpy).toHaveBeenCalledWith(
5959
`[some-prefix] Debug: Hey!`,
6060
"this",
6161
"is",
@@ -72,7 +72,7 @@ describe("Logger", () => {
7272

7373
logger[loggerMethod]("Hey!");
7474

75-
expect(consoleLogSpy).not.toHaveBeenCalled();
75+
expect(consoleErrorSpy).not.toHaveBeenCalled();
7676
});
7777
});
7878

@@ -82,6 +82,6 @@ describe("Logger", () => {
8282

8383
logger.debug("Hey!");
8484

85-
expect(consoleLogSpy).not.toHaveBeenCalled();
85+
expect(consoleErrorSpy).not.toHaveBeenCalled();
8686
});
8787
});

0 commit comments

Comments
 (0)