From 3429b83f5e9afa218d343f16454937e306340aa0 Mon Sep 17 00:00:00 2001 From: Michael Telatynski <7t3chguy@gmail.com> Date: Tue, 20 Jun 2023 12:24:49 +0100 Subject: [PATCH 1/3] Mark debug logging with distinct letter --- src/rageshake/rageshake.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/src/rageshake/rageshake.ts b/src/rageshake/rageshake.ts index d7ff981f77e..d00b17bbdad 100644 --- a/src/rageshake/rageshake.ts +++ b/src/rageshake/rageshake.ts @@ -63,6 +63,7 @@ export class ConsoleLogger { info: "I", warn: "W", error: "E", + debug: "D", } as const; (Object.keys(consoleFunctionsToLevels) as [keyof typeof consoleFunctionsToLevels]).forEach( (fnName: keyof typeof consoleFunctionsToLevels) => { From d2bf0608c333b1f2847d78246f4bb85f031e2ba1 Mon Sep 17 00:00:00 2001 From: Michael Telatynski <7t3chguy@gmail.com> Date: Tue, 20 Jun 2023 12:35:51 +0100 Subject: [PATCH 2/3] Simplify types --- src/rageshake/rageshake.ts | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/src/rageshake/rageshake.ts b/src/rageshake/rageshake.ts index d00b17bbdad..64fbea1140a 100644 --- a/src/rageshake/rageshake.ts +++ b/src/rageshake/rageshake.ts @@ -49,7 +49,14 @@ const FLUSH_RATE_MS = 30 * 1000; const MAX_LOG_SIZE = 1024 * 1024 * 5; // 5 MB type LogFunction = (...args: (Error | DOMException | object | string)[]) => void; -type LogFunctionName = "log" | "info" | "warn" | "error"; +const consoleFunctionsToLevels = { + log: "I", + info: "I", + warn: "W", + error: "E", + debug: "D", +} as const; +type LogFunctionName = keyof typeof consoleFunctionsToLevels; // A class which monkey-patches the global console and stores log lines. export class ConsoleLogger { @@ -58,15 +65,8 @@ export class ConsoleLogger { public monkeyPatch(consoleObj: Console): void { // Monkey-patch console logging - const consoleFunctionsToLevels = { - log: "I", - info: "I", - warn: "W", - error: "E", - debug: "D", - } as const; - (Object.keys(consoleFunctionsToLevels) as [keyof typeof consoleFunctionsToLevels]).forEach( - (fnName: keyof typeof consoleFunctionsToLevels) => { + (Object.keys(consoleFunctionsToLevels) as LogFunctionName[]).forEach( + (fnName: LogFunctionName) => { const level = consoleFunctionsToLevels[fnName]; const originalFn = consoleObj[fnName].bind(consoleObj); this.originalFunctions[fnName] = originalFn; From bfdefa381fd8746f3dc35171bc81b582b3d50f77 Mon Sep 17 00:00:00 2001 From: Michael Telatynski <7t3chguy@gmail.com> Date: Tue, 20 Jun 2023 12:39:25 +0100 Subject: [PATCH 3/3] Prettier --- src/rageshake/rageshake.ts | 20 +++++++++----------- 1 file changed, 9 insertions(+), 11 deletions(-) diff --git a/src/rageshake/rageshake.ts b/src/rageshake/rageshake.ts index 64fbea1140a..885ece6b935 100644 --- a/src/rageshake/rageshake.ts +++ b/src/rageshake/rageshake.ts @@ -65,17 +65,15 @@ export class ConsoleLogger { public monkeyPatch(consoleObj: Console): void { // Monkey-patch console logging - (Object.keys(consoleFunctionsToLevels) as LogFunctionName[]).forEach( - (fnName: LogFunctionName) => { - const level = consoleFunctionsToLevels[fnName]; - const originalFn = consoleObj[fnName].bind(consoleObj); - this.originalFunctions[fnName] = originalFn; - consoleObj[fnName] = (...args) => { - this.log(level, ...args); - originalFn(...args); - }; - }, - ); + (Object.keys(consoleFunctionsToLevels) as LogFunctionName[]).forEach((fnName: LogFunctionName) => { + const level = consoleFunctionsToLevels[fnName]; + const originalFn = consoleObj[fnName].bind(consoleObj); + this.originalFunctions[fnName] = originalFn; + consoleObj[fnName] = (...args) => { + this.log(level, ...args); + originalFn(...args); + }; + }); } public bypassRageshake(fnName: LogFunctionName, ...args: (Error | DOMException | object | string)[]): void {