Created
August 7, 2016 15:34
-
-
Save madox2/680c24790d522d69d1a27812c19c6615 to your computer and use it in GitHub Desktop.
intercept console.log method
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
/** | |
* This function extends console.log functionality with given logger. | |
* @param {function} logger - Custom logger | |
*/ | |
function extendLog(logger) { | |
var original = console.log; | |
console.log = function() { | |
logger(Array.prototype.slice.call(arguments)); | |
return original.apply(this, arguments); | |
} | |
} | |
/** | |
* Custom logger used to extend console.log | |
* @param {Object[]} args - array of arguments passed to original console.log | |
*/ | |
var myLogger = function(args) { | |
var log = document.createElement("div"); | |
log.innerHTML = args; | |
document.body.appendChild(log); | |
} | |
extendLog(myLogger); | |
console.log("Hello world!"); | |
console.log("How", "are", "you?"); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment