From c7ec04b253eda43b7174e13542d1c1db43c60fc6 Mon Sep 17 00:00:00 2001 From: Charlie Cheever Date: Wed, 23 Sep 2015 17:19:47 -0700 Subject: [PATCH] Also call the original `console` methods if they exist MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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 --- .../src/DependencyResolver/polyfills/console.js | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/react-packager/src/DependencyResolver/polyfills/console.js b/react-packager/src/DependencyResolver/polyfills/console.js index e0459740..e841aebb 100644 --- a/react-packager/src/DependencyResolver/polyfills/console.js +++ b/react-packager/src/DependencyResolver/polyfills/console.js @@ -367,6 +367,9 @@ }; function setupConsole(global) { + + var originalConsole = global.console; + if (!global.nativeLoggingHook) { return; } @@ -462,6 +465,16 @@ 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') {