Mark debug logging with distinct letter (#11118)
* Mark debug logging with distinct letter * Simplify types * Prettier
This commit is contained in:
parent
b84a230d58
commit
985bde70c5
1 changed files with 17 additions and 18 deletions
|
@ -49,7 +49,14 @@ const FLUSH_RATE_MS = 30 * 1000;
|
||||||
const MAX_LOG_SIZE = 1024 * 1024 * 5; // 5 MB
|
const MAX_LOG_SIZE = 1024 * 1024 * 5; // 5 MB
|
||||||
|
|
||||||
type LogFunction = (...args: (Error | DOMException | object | string)[]) => void;
|
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.
|
// A class which monkey-patches the global console and stores log lines.
|
||||||
export class ConsoleLogger {
|
export class ConsoleLogger {
|
||||||
|
@ -58,23 +65,15 @@ export class ConsoleLogger {
|
||||||
|
|
||||||
public monkeyPatch(consoleObj: Console): void {
|
public monkeyPatch(consoleObj: Console): void {
|
||||||
// Monkey-patch console logging
|
// Monkey-patch console logging
|
||||||
const consoleFunctionsToLevels = {
|
(Object.keys(consoleFunctionsToLevels) as LogFunctionName[]).forEach((fnName: LogFunctionName) => {
|
||||||
log: "I",
|
const level = consoleFunctionsToLevels[fnName];
|
||||||
info: "I",
|
const originalFn = consoleObj[fnName].bind(consoleObj);
|
||||||
warn: "W",
|
this.originalFunctions[fnName] = originalFn;
|
||||||
error: "E",
|
consoleObj[fnName] = (...args) => {
|
||||||
} as const;
|
this.log(level, ...args);
|
||||||
(Object.keys(consoleFunctionsToLevels) as [keyof typeof consoleFunctionsToLevels]).forEach(
|
originalFn(...args);
|
||||||
(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);
|
|
||||||
};
|
|
||||||
},
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public bypassRageshake(fnName: LogFunctionName, ...args: (Error | DOMException | object | string)[]): void {
|
public bypassRageshake(fnName: LogFunctionName, ...args: (Error | DOMException | object | string)[]): void {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue