From 97bc0845ecd588b587c7b7dad07c1475bcebf80b Mon Sep 17 00:00:00 2001 From: Ramanpreet Nara Date: Wed, 29 Apr 2020 09:13:45 -0700 Subject: [PATCH] Guard all debug logs behind an MC Reviewed By: PeteTheHeat Differential Revision: D21292280 fbshipit-source-id: 1701a945f126f35a53417b57e3162372d39e75f1 --- .../facebook/react/ReactInstanceManager.java | 36 +++++++++++-------- .../react/bridge/CatalystInstanceImpl.java | 16 +++++---- .../react/config/ReactFeatureFlags.java | 3 ++ .../turbomodule/core/TurboModuleManager.java | 14 +++++--- 4 files changed, 42 insertions(+), 27 deletions(-) diff --git a/ReactAndroid/src/main/java/com/facebook/react/ReactInstanceManager.java b/ReactAndroid/src/main/java/com/facebook/react/ReactInstanceManager.java index 07f26501f6e283..12f0c9e3f47f8f 100644 --- a/ReactAndroid/src/main/java/com/facebook/react/ReactInstanceManager.java +++ b/ReactAndroid/src/main/java/com/facebook/react/ReactInstanceManager.java @@ -1252,32 +1252,38 @@ private ReactApplicationContext createReactContext( reactContext.initializeWithInstance(catalystInstance); - // TODO(T46487253): Remove after task is closed - FLog.e( - ReactConstants.TAG, - "ReactInstanceManager.createReactContext: mJSIModulePackage " - + (mJSIModulePackage != null ? "not null" : "null")); + if (ReactFeatureFlags.enableTurboModuleDebugLogs) { + // TODO(T46487253): Remove after task is closed + FLog.e( + ReactConstants.TAG, + "ReactInstanceManager.createReactContext: mJSIModulePackage " + + (mJSIModulePackage != null ? "not null" : "null")); + } if (mJSIModulePackage != null) { catalystInstance.addJSIModules( mJSIModulePackage.getJSIModules( reactContext, catalystInstance.getJavaScriptContextHolder())); - // TODO(T46487253): Remove after task is closed - FLog.e( - ReactConstants.TAG, - "ReactInstanceManager.createReactContext: ReactFeatureFlags.useTurboModules == " - + (ReactFeatureFlags.useTurboModules == false ? "false" : "true")); + if (ReactFeatureFlags.enableTurboModuleDebugLogs) { + // TODO(T46487253): Remove after task is closed + FLog.e( + ReactConstants.TAG, + "ReactInstanceManager.createReactContext: ReactFeatureFlags.useTurboModules == " + + (ReactFeatureFlags.useTurboModules == false ? "false" : "true")); + } if (ReactFeatureFlags.useTurboModules) { JSIModule turboModuleManager = catalystInstance.getJSIModule(JSIModuleType.TurboModuleManager); - // TODO(T46487253): Remove after task is closed - FLog.e( - ReactConstants.TAG, - "ReactInstanceManager.createReactContext: TurboModuleManager " - + (turboModuleManager == null ? "not created" : "created")); + if (ReactFeatureFlags.enableTurboModuleDebugLogs) { + // TODO(T46487253): Remove after task is closed + FLog.e( + ReactConstants.TAG, + "ReactInstanceManager.createReactContext: TurboModuleManager " + + (turboModuleManager == null ? "not created" : "created")); + } catalystInstance.setTurboModuleManager(turboModuleManager); diff --git a/ReactAndroid/src/main/java/com/facebook/react/bridge/CatalystInstanceImpl.java b/ReactAndroid/src/main/java/com/facebook/react/bridge/CatalystInstanceImpl.java index 6e481bbd2cd12b..864c85c73601e6 100644 --- a/ReactAndroid/src/main/java/com/facebook/react/bridge/CatalystInstanceImpl.java +++ b/ReactAndroid/src/main/java/com/facebook/react/bridge/CatalystInstanceImpl.java @@ -583,13 +583,15 @@ public NativeModule getNativeModule(String moduleName) { if (getTurboModuleRegistry() != null) { TurboModule turboModule = getTurboModuleRegistry().getModule(moduleName); - // TODO(T46487253): Remove after task is closed - FLog.e( - ReactConstants.TAG, - "CatalystInstanceImpl.getNativeModule: TurboModule " - + moduleName - + (turboModule == null ? " not" : "") - + " found"); + if (ReactFeatureFlags.enableTurboModuleDebugLogs) { + // TODO(T46487253): Remove after task is closed + FLog.e( + ReactConstants.TAG, + "CatalystInstanceImpl.getNativeModule: TurboModule " + + moduleName + + (turboModule == null ? " not" : "") + + " found"); + } if (turboModule != null) { return (NativeModule) turboModule; } diff --git a/ReactAndroid/src/main/java/com/facebook/react/config/ReactFeatureFlags.java b/ReactAndroid/src/main/java/com/facebook/react/config/ReactFeatureFlags.java index c5b9de82a4453f..c04a883d5fb5cc 100644 --- a/ReactAndroid/src/main/java/com/facebook/react/config/ReactFeatureFlags.java +++ b/ReactAndroid/src/main/java/com/facebook/react/config/ReactFeatureFlags.java @@ -23,6 +23,9 @@ public class ReactFeatureFlags { */ public static volatile boolean useTurboModules = false; + /** Should we output debug logs to debug the TurboModule infra? */ + public static volatile boolean enableTurboModuleDebugLogs = false; + /* * This feature flag enables logs for Fabric */ diff --git a/ReactAndroid/src/main/java/com/facebook/react/turbomodule/core/TurboModuleManager.java b/ReactAndroid/src/main/java/com/facebook/react/turbomodule/core/TurboModuleManager.java index d2afb785c8b36f..6b01a2008308ad 100644 --- a/ReactAndroid/src/main/java/com/facebook/react/turbomodule/core/TurboModuleManager.java +++ b/ReactAndroid/src/main/java/com/facebook/react/turbomodule/core/TurboModuleManager.java @@ -19,6 +19,7 @@ import com.facebook.react.bridge.JavaScriptContextHolder; import com.facebook.react.bridge.NativeModule; import com.facebook.react.common.ReactConstants; +import com.facebook.react.config.ReactFeatureFlags; import com.facebook.react.turbomodule.core.interfaces.CallInvokerHolder; import com.facebook.react.turbomodule.core.interfaces.TurboModule; import com.facebook.react.turbomodule.core.interfaces.TurboModuleRegistry; @@ -142,11 +143,14 @@ public TurboModule getModule(String moduleName) { * Always return null after cleanup has started, so that getModule(moduleName) returns null. */ - FLog.e( - ReactConstants.TAG, - "TurboModuleManager.getOrMaybeCreateTurboModuleHolder: Tried to require TurboModule " - + moduleName - + " after cleanup initiated"); + if (ReactFeatureFlags.enableTurboModuleDebugLogs) { + // TODO(T46487253): Remove after task is closed + FLog.e( + ReactConstants.TAG, + "TurboModuleManager.getOrMaybeCreateTurboModuleHolder: Tried to require TurboModule " + + moduleName + + " after cleanup initiated"); + } return null; }