function consoleLogBlacklist(blacklist = [], functionsToPreserve = ["error"]) {
function noop() {}
const savedFunctions = {
log: console.log
};
Object.keys(console).reduce((memo, key) => {
if (
typeof console[key] == "function" &&
functionsToPreserve.indexOf(key) != -1
) {
memo[key] = console[key];
console[key] = noop;
}
return memo;
}, savedFunctions);
console.log = function customLog() {
const callingFile = new Error().stack.split("\n")[2];
if (blacklist.some((entry) => callingFile.includes(entry))) {
return;
} else {
savedFunctions.log.apply(console, arguments);
}
};
}