Skip to content
This repository was archived by the owner on Sep 11, 2024. It is now read-only.

Commit 985bde7

Browse files
authored
Mark debug logging with distinct letter (#11118)
* Mark debug logging with distinct letter * Simplify types * Prettier
1 parent b84a230 commit 985bde7

File tree

1 file changed

+17
-18
lines changed

1 file changed

+17
-18
lines changed

src/rageshake/rageshake.ts

+17-18
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,14 @@ const FLUSH_RATE_MS = 30 * 1000;
4949
const MAX_LOG_SIZE = 1024 * 1024 * 5; // 5 MB
5050

5151
type LogFunction = (...args: (Error | DOMException | object | string)[]) => void;
52-
type LogFunctionName = "log" | "info" | "warn" | "error";
52+
const consoleFunctionsToLevels = {
53+
log: "I",
54+
info: "I",
55+
warn: "W",
56+
error: "E",
57+
debug: "D",
58+
} as const;
59+
type LogFunctionName = keyof typeof consoleFunctionsToLevels;
5360

5461
// A class which monkey-patches the global console and stores log lines.
5562
export class ConsoleLogger {
@@ -58,23 +65,15 @@ export class ConsoleLogger {
5865

5966
public monkeyPatch(consoleObj: Console): void {
6067
// Monkey-patch console logging
61-
const consoleFunctionsToLevels = {
62-
log: "I",
63-
info: "I",
64-
warn: "W",
65-
error: "E",
66-
} as const;
67-
(Object.keys(consoleFunctionsToLevels) as [keyof typeof consoleFunctionsToLevels]).forEach(
68-
(fnName: keyof typeof consoleFunctionsToLevels) => {
69-
const level = consoleFunctionsToLevels[fnName];
70-
const originalFn = consoleObj[fnName].bind(consoleObj);
71-
this.originalFunctions[fnName] = originalFn;
72-
consoleObj[fnName] = (...args) => {
73-
this.log(level, ...args);
74-
originalFn(...args);
75-
};
76-
},
77-
);
68+
(Object.keys(consoleFunctionsToLevels) as LogFunctionName[]).forEach((fnName: LogFunctionName) => {
69+
const level = consoleFunctionsToLevels[fnName];
70+
const originalFn = consoleObj[fnName].bind(consoleObj);
71+
this.originalFunctions[fnName] = originalFn;
72+
consoleObj[fnName] = (...args) => {
73+
this.log(level, ...args);
74+
originalFn(...args);
75+
};
76+
});
7877
}
7978

8079
public bypassRageshake(fnName: LogFunctionName, ...args: (Error | DOMException | object | string)[]): void {

0 commit comments

Comments
 (0)