From b289600a7aaae51b1fcef9bd0c51d3c00dc06729 Mon Sep 17 00:00:00 2001 From: Pieter De Baets Date: Fri, 20 Nov 2015 03:33:07 -0800 Subject: [PATCH] Port CatalystLoggingTestCase to iOS Reviewed By: nicklockwood Differential Revision: D2658485 fb-gh-sync-id: e6803aefee69ee058651fc4c8c202619543f0cd2 --- .../src/Resolver/polyfills/console.js | 20 ++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-) diff --git a/react-packager/src/Resolver/polyfills/console.js b/react-packager/src/Resolver/polyfills/console.js index e08e8ef7..5461602b 100644 --- a/react-packager/src/Resolver/polyfills/console.js +++ b/react-packager/src/Resolver/polyfills/console.js @@ -366,7 +366,6 @@ }; function setupConsole(global) { - var originalConsole = global.console; if (!global.nativeLoggingHook) { @@ -375,16 +374,23 @@ function getNativeLogFunction(level) { return function() { - var str = Array.prototype.map.call(arguments, function(arg) { - return inspect(arg, {depth: 10}); - }).join(', '); - if (str.slice(0, 10) === "'Warning: " && level >= LOG_LEVELS.error) { + var str; + if (arguments.length === 1 && typeof arguments[0] === 'string') { + str = arguments[0]; + } else { + str = Array.prototype.map.call(arguments, function(arg) { + return inspect(arg, {depth: 10}); + }).join(', '); + } + + var logLevel = level; + if (str.slice(0, 9) === 'Warning: ' && logLevel >= LOG_LEVELS.error) { // React warnings use console.error so that a stack trace is shown, // but we don't (currently) want these to show a redbox // (Note: Logic duplicated in ExceptionsManager.js.) - level = LOG_LEVELS.warn; + logLevel = LOG_LEVELS.warn; } - global.nativeLoggingHook(str, level); + global.nativeLoggingHook(str, logLevel); }; }