diff --git a/packages/polyfills/console.js b/packages/polyfills/console.js index 338e1590cb3..aac13350ccb 100644 --- a/packages/polyfills/console.js +++ b/packages/polyfills/console.js @@ -554,6 +554,7 @@ if (global.nativeLoggingHook) { } global.console = { + ...(originalConsole ?? {}), error: getNativeLogFunction(LOG_LEVELS.error), info: getNativeLogFunction(LOG_LEVELS.info), log: getNativeLogFunction(LOG_LEVELS.info), @@ -578,7 +579,10 @@ if (global.nativeLoggingHook) { if (__DEV__ && originalConsole) { Object.keys(console).forEach(methodName => { const reactNativeMethod = console[methodName]; - if (originalConsole[methodName]) { + if ( + originalConsole[methodName] && + reactNativeMethod !== originalConsole[methodName] + ) { console[methodName] = function () { originalConsole[methodName](...arguments); reactNativeMethod.apply(console, arguments); diff --git a/packages/react-native/ReactCommon/jsinspector-modern/tests/prelude.js.h b/packages/react-native/ReactCommon/jsinspector-modern/tests/prelude.js.h index 31d00ca9df1..994222a3d5b 100644 --- a/packages/react-native/ReactCommon/jsinspector-modern/tests/prelude.js.h +++ b/packages/react-native/ReactCommon/jsinspector-modern/tests/prelude.js.h @@ -553,6 +553,7 @@ if (global.nativeLoggingHook) { } global.console = { + ...(originalConsole ?? {}), error: getNativeLogFunction(LOG_LEVELS.error), info: getNativeLogFunction(LOG_LEVELS.info), log: getNativeLogFunction(LOG_LEVELS.info), @@ -577,7 +578,10 @@ if (global.nativeLoggingHook) { if (__DEV__ && originalConsole) { Object.keys(console).forEach(methodName => { const reactNativeMethod = console[methodName]; - if (originalConsole[methodName]) { + if ( + originalConsole[methodName] && + reactNativeMethod !== originalConsole[methodName] + ) { console[methodName] = function () { originalConsole[methodName](...arguments); reactNativeMethod.apply(console, arguments);