Last active
July 6, 2021 20:46
-
-
Save l-portet/cac5788e0fedce7878137eb0b03e172c to your computer and use it in GitHub Desktop.
Client-side silent log
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
window.slog = function (...args) { | |
if (!window.logsStack) { | |
window.logsStack = []; | |
window.printLogsStack = function () { | |
for (const logItem of window.logsStack) { | |
const [msg, lineDetails] = logItem; | |
console.log(msg); | |
console.log(lineDetails); | |
} | |
}; | |
} | |
let lineDetails; | |
try { | |
lineDetails = new Error().stack.split('at ')[3].trim(); | |
} catch (err) { | |
lineDetails = 'untracable'; | |
} | |
for (let msg of args) { | |
if (window.DISABLE_SILENT_LOG) { | |
console.log(msg); | |
console.log(lineDetails); | |
} else { | |
window.logsStack.push([msg, lineDetails]); | |
} | |
} | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment