From 985bde70c5b442c5fbafaf70d107159398699d4c Mon Sep 17 00:00:00 2001 From: Michael Telatynski <7t3chguy@gmail.com> Date: Tue, 20 Jun 2023 16:27:59 +0100 Subject: [PATCH] Mark debug logging with distinct letter (#11118) * Mark debug logging with distinct letter * Simplify types * Prettier --- src/rageshake/rageshake.ts | 35 +++++++++++++++++------------------ 1 file changed, 17 insertions(+), 18 deletions(-) diff --git a/src/rageshake/rageshake.ts b/src/rageshake/rageshake.ts index d7ff981f77e..885ece6b935 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,23 +65,15 @@ export class ConsoleLogger { public monkeyPatch(consoleObj: Console): void { // Monkey-patch console logging - const consoleFunctionsToLevels = { - log: "I", - info: "I", - warn: "W", - error: "E", - } as const; - (Object.keys(consoleFunctionsToLevels) as [keyof typeof consoleFunctionsToLevels]).forEach( - (fnName: keyof typeof consoleFunctionsToLevels) => { - 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 {