Last active
August 29, 2015 14:00
-
-
Save zkat/11237340 to your computer and use it in GitHub Desktop.
Log logger locations globally
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
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