Skip to content

Instantly share code, notes, and snippets.

@zkat
Last active August 29, 2015 14:00
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save zkat/11237340 to your computer and use it in GitHub Desktop.
Save zkat/11237340 to your computer and use it in GitHub Desktop.
Log logger locations globally
var old = {};
module.exports = {
install: install,
uninstall: uninstall,
methods: ["log", "info", "warn", "error"]
};
install();
function install() {
module.exports.methods.forEach(function(m) {
old[m] = console[m];
console[m] = function() {
var loc;
try {
throw new Error();
} catch (e) {
var stack = e.stack.split("\n");
loc = (stack[2]||stack[1]).trim();
}
old[m].apply(this, [].slice.call(arguments).concat("("+loc+")"));
};
});
}
function uninstall() {
for (var m in old) {
if (old.hasOwnProperty(m)) {
console[m] = old[m];
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment