Skip to content

Instantly share code, notes, and snippets.

@ray-peters
Created January 10, 2017 00:17
Show Gist options
  • Save ray-peters/da4f643edad5803da29ed35ebae785b1 to your computer and use it in GitHub Desktop.
Save ray-peters/da4f643edad5803da29ed35ebae785b1 to your computer and use it in GitHub Desktop.
var consoleLogSpy = function() {
return {
start: _start,
stop: _stop
};
function _start( callback ) {
console.log = function( originalConsoleLog ) {
console._originalLog = originalConsoleLog;
return function(){
callback.apply( callback, arguments );
return originalConsoleLog.apply( console, originalConsoleLog );
};
}( console.log );
}
function _stop() {
if ( console._originalLog ) {
console.log = console._originalLog;
}
}
}();
console.log( 'test' );
consoleLogSpy.start( function() {
debugger;
} );
console.log( 'hello world' );
consoleLogSpy.stop();
console.log( 'done' );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment