Also call the original `console` methods if they exist

Summary: Ex. When `console.log` or similar is called, this will call
the original method, which can be quite useful.

For example, under iOS, this will log to the Safari console debugger,
which has an expandable UI for inspecting objects, etc., and is also
just useful if you are using that as a REPL.

I don't believe this incurs a meaningful performance penalty unless
the console is open, but it would be easy to stick behind a flag
if that is a problem.
Closes https://github.com/facebook/react-native/pull/2486

Reviewed By: @​svcscm

Differential Revision: D2472470

Pulled By: @vjeux
This commit is contained in:
Charlie Cheever 2015-09-23 17:19:47 -07:00 committed by facebook-github-bot-7
parent cea98fdef1
commit c7ec04b253
1 changed files with 13 additions and 0 deletions

View File

@ -367,6 +367,9 @@
}; };
function setupConsole(global) { function setupConsole(global) {
var originalConsole = global.console;
if (!global.nativeLoggingHook) { if (!global.nativeLoggingHook) {
return; return;
} }
@ -462,6 +465,16 @@
table: consoleTablePolyfill table: consoleTablePolyfill
}; };
// If available, also call the original `console` method since that is
// sometimes useful. Ex: on OS X, this will let you see rich output in
// the Safari Web Inspector console.
Object.keys(global.console).forEach(methodName => {
var reactNativeMethod = global.console[methodName];
global.console[methodName] = function() {
originalConsole[methodName](...arguments);
reactNativeMethod.apply(global.console, arguments);
};
});
} }
if (typeof module !== 'undefined') { if (typeof module !== 'undefined') {