Last active
November 19, 2017 18:02
-
-
Save no-stack-dub-sack/0bb1baa3d9e80ea99da313250a6dcb7e to your computer and use it in GitHub Desktop.
capture console.log messages with redux
This file contains hidden or 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
import { store } from './index'; | |
export const hijackConsole = () => { | |
const OG_LOG = console.log; | |
console.log = function(...args) { | |
// map over arguments and convert | |
// objects in to readable strings | |
const messages = [...args].map(msg => { | |
return typeof msg !== 'string' | |
? JSON.stringify(msg) | |
: msg; | |
}).join(' '); | |
store.dispatch({ | |
type: CONSOLE_LOG, | |
messages | |
}); | |
// retain original functionality | |
OG_LOG.apply(console, [...args]); | |
}; | |
}; | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment