mirror of
https://github.com/SchildiChat/element-web.git
synced 2024-10-01 01:26:12 -04:00
Add a monkeyPatch function rather than monkey-patching in the constructor
This commit is contained in:
parent
53a16158c7
commit
ea860807c4
@ -36,7 +36,9 @@ const FLUSH_RATE_MS = 30 * 1000;
|
|||||||
class ConsoleLogger {
|
class ConsoleLogger {
|
||||||
constructor() {
|
constructor() {
|
||||||
this.logs = "";
|
this.logs = "";
|
||||||
|
}
|
||||||
|
|
||||||
|
monkeyPatch(consoleObj) {
|
||||||
// Monkey-patch console logging
|
// Monkey-patch console logging
|
||||||
const consoleFunctionsToLevels = {
|
const consoleFunctionsToLevels = {
|
||||||
log: "I",
|
log: "I",
|
||||||
@ -46,8 +48,8 @@ class ConsoleLogger {
|
|||||||
};
|
};
|
||||||
Object.keys(consoleFunctionsToLevels).forEach((fnName) => {
|
Object.keys(consoleFunctionsToLevels).forEach((fnName) => {
|
||||||
const level = consoleFunctionsToLevels[fnName];
|
const level = consoleFunctionsToLevels[fnName];
|
||||||
let originalFn = window.console[fnName].bind(window.console);
|
let originalFn = consoleObj[fnName].bind(consoleObj);
|
||||||
window.console[fnName] = (...args) => {
|
consoleObj[fnName] = (...args) => {
|
||||||
this.log(level, ...args);
|
this.log(level, ...args);
|
||||||
originalFn(...args);
|
originalFn(...args);
|
||||||
}
|
}
|
||||||
@ -310,6 +312,7 @@ module.exports = {
|
|||||||
return initPromise;
|
return initPromise;
|
||||||
}
|
}
|
||||||
logger = new ConsoleLogger();
|
logger = new ConsoleLogger();
|
||||||
|
logger.monkeyPatch(window.console);
|
||||||
if (window.indexedDB) {
|
if (window.indexedDB) {
|
||||||
store = new IndexedDBLogStore(window.indexedDB, logger);
|
store = new IndexedDBLogStore(window.indexedDB, logger);
|
||||||
initPromise = store.connect();
|
initPromise = store.connect();
|
||||||
|
Loading…
Reference in New Issue
Block a user