Skip to content

Instantly share code, notes, and snippets.

@l-portet
Last active July 6, 2021 20:46
Show Gist options
  • Save l-portet/cac5788e0fedce7878137eb0b03e172c to your computer and use it in GitHub Desktop.
Save l-portet/cac5788e0fedce7878137eb0b03e172c to your computer and use it in GitHub Desktop.
Client-side silent log
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