Skip to content

Instantly share code, notes, and snippets.

@no-stack-dub-sack
Last active November 19, 2017 18:02
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 no-stack-dub-sack/0bb1baa3d9e80ea99da313250a6dcb7e to your computer and use it in GitHub Desktop.
Save no-stack-dub-sack/0bb1baa3d9e80ea99da313250a6dcb7e to your computer and use it in GitHub Desktop.
capture console.log messages with redux
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