Refactor Log to Flog in Fabric

Reviewed By: shergin

Differential Revision: D8363593

fbshipit-source-id: fb4104b66ef3d50d4101c39a1bf4515e6d0ecd19
This commit is contained in:
David Vacca 2018-06-14 18:36:32 -07:00 committed by Facebook Github Bot
parent 1ffb2b63be
commit e773b36990
7 changed files with 51 additions and 26 deletions

View File

@ -27,6 +27,16 @@ public class ReactDebugOverlayTags {
"UI Manager", "UI Manager",
"UI Manager View Operations (requires restart\nwarning: this is spammy)", "UI Manager View Operations (requires restart\nwarning: this is spammy)",
Color.CYAN); Color.CYAN);
public static final DebugOverlayTag FABRIC_UI_MANAGER =
new DebugOverlayTag(
"FabricUIManager",
"Fabric UI Manager View Operations",
Color.CYAN);
public static final DebugOverlayTag FABRIC_RECONCILER =
new DebugOverlayTag(
"FabricReconciler",
"Reconciler for Fabric",
Color.CYAN);
public static final DebugOverlayTag RELAY = public static final DebugOverlayTag RELAY =
new DebugOverlayTag("Relay", "including prefetching", Color.rgb(0xFF, 0x99, 0x00)); new DebugOverlayTag("Relay", "including prefetching", Color.rgb(0xFF, 0x99, 0x00));
} }

View File

@ -9,5 +9,5 @@ package com.facebook.react.bridge;
import java.util.Map; import java.util.Map;
public interface PerformanceCounter { public interface PerformanceCounter {
public Map<String, Long> getPerformanceCounters(); Map<String, Long> getPerformanceCounters();
} }

View File

@ -15,9 +15,12 @@ rn_android_library(
], ],
deps = [ deps = [
YOGA_TARGET, YOGA_TARGET,
react_native_dep("libraries/fbcore/src/main/java/com/facebook/common/logging:logging"),
react_native_dep("third-party/java/infer-annotations:infer-annotations"), react_native_dep("third-party/java/infer-annotations:infer-annotations"),
react_native_dep("third-party/java/jsr-305:jsr-305"), react_native_dep("third-party/java/jsr-305:jsr-305"),
react_native_target("java/com/facebook/react:react"), react_native_target("java/com/facebook/react:react"),
react_native_target("java/com/facebook/debug/tags:tags"),
react_native_target("java/com/facebook/debug/holder:holder"),
react_native_target("java/com/facebook/react/bridge:bridge"), react_native_target("java/com/facebook/react/bridge:bridge"),
react_native_target("java/com/facebook/react/uimanager:uimanager"), react_native_target("java/com/facebook/react/uimanager:uimanager"),
react_native_target("java/com/facebook/react/uimanager/annotations:annotations"), react_native_target("java/com/facebook/react/uimanager/annotations:annotations"),

View File

@ -7,8 +7,11 @@
package com.facebook.react.fabric; package com.facebook.react.fabric;
import android.util.Log; import com.facebook.common.logging.FLog;
import com.facebook.debug.holder.PrinterHolder;
import com.facebook.debug.tags.ReactDebugOverlayTags;
import com.facebook.react.common.ArrayUtils; import com.facebook.react.common.ArrayUtils;
import com.facebook.react.common.build.ReactBuildConfig;
import com.facebook.react.uimanager.ReactShadowNode; import com.facebook.react.uimanager.ReactShadowNode;
import com.facebook.react.uimanager.UIViewOperationQueue; import com.facebook.react.uimanager.UIViewOperationQueue;
import com.facebook.react.uimanager.ViewAtIndex; import com.facebook.react.uimanager.ViewAtIndex;
@ -23,7 +26,8 @@ import javax.annotation.Nullable;
public class FabricReconciler { public class FabricReconciler {
private static final String TAG = FabricReconciler.class.getSimpleName(); private static final String TAG = FabricReconciler.class.getSimpleName();
private static final boolean DEBUG = true; private static final boolean DEBUG = ReactBuildConfig.DEBUG || PrinterHolder
.getPrinter().shouldDisplayLogMessage(ReactDebugOverlayTags.FABRIC_RECONCILER);
private UIViewOperationQueue uiViewOperationQueue; private UIViewOperationQueue uiViewOperationQueue;
@ -104,7 +108,7 @@ public class FabricReconciler {
ViewAtIndex[] viewsToAddArray = viewsToAdd.toArray(new ViewAtIndex[viewsToAdd.size()]); ViewAtIndex[] viewsToAddArray = viewsToAdd.toArray(new ViewAtIndex[viewsToAdd.size()]);
int[] tagsToDeleteArray = ArrayUtils.copyListToArray(tagsToDelete); int[] tagsToDeleteArray = ArrayUtils.copyListToArray(tagsToDelete);
if (DEBUG) { if (DEBUG) {
Log.d( FLog.d(
TAG, TAG,
"manageChildren.enqueueManageChildren parent: " + parent.getReactTag() + "manageChildren.enqueueManageChildren parent: " + parent.getReactTag() +
"\n\tIndices2Remove: " + Arrays.toString(indicesToRemoveArray) + "\n\tIndices2Remove: " + Arrays.toString(indicesToRemoveArray) +
@ -119,7 +123,7 @@ public class FabricReconciler {
private void enqueueUpdateProperties(ReactShadowNode node) { private void enqueueUpdateProperties(ReactShadowNode node) {
int reactTag = node.getReactTag(); int reactTag = node.getReactTag();
if (DEBUG) { if (DEBUG) {
Log.d( FLog.d(
TAG, TAG,
"manageChildren.enqueueUpdateProperties " + "manageChildren.enqueueUpdateProperties " +
"\n\ttag: " + reactTag + "\n\ttag: " + reactTag +

View File

@ -12,8 +12,10 @@ import static android.view.View.MeasureSpec.EXACTLY;
import static android.view.View.MeasureSpec.UNSPECIFIED; import static android.view.View.MeasureSpec.UNSPECIFIED;
import static com.facebook.react.uimanager.common.UIManagerType.FABRIC; import static com.facebook.react.uimanager.common.UIManagerType.FABRIC;
import android.util.Log;
import android.view.View; import android.view.View;
import com.facebook.common.logging.FLog;
import com.facebook.debug.holder.PrinterHolder;
import com.facebook.debug.tags.ReactDebugOverlayTags;
import com.facebook.infer.annotation.Assertions; import com.facebook.infer.annotation.Assertions;
import com.facebook.proguard.annotations.DoNotStrip; import com.facebook.proguard.annotations.DoNotStrip;
import com.facebook.react.bridge.JavaScriptContextHolder; import com.facebook.react.bridge.JavaScriptContextHolder;
@ -26,6 +28,7 @@ import com.facebook.react.bridge.WritableMap;
import com.facebook.react.bridge.WritableNativeMap; import com.facebook.react.bridge.WritableNativeMap;
import com.facebook.react.common.ReactConstants; import com.facebook.react.common.ReactConstants;
import com.facebook.react.common.annotations.VisibleForTesting; import com.facebook.react.common.annotations.VisibleForTesting;
import com.facebook.react.common.build.ReactBuildConfig;
import com.facebook.react.fabric.events.FabricEventEmitter; import com.facebook.react.fabric.events.FabricEventEmitter;
import com.facebook.react.modules.i18nmanager.I18nUtil; import com.facebook.react.modules.i18nmanager.I18nUtil;
import com.facebook.react.uimanager.DisplayMetricsHolder; import com.facebook.react.uimanager.DisplayMetricsHolder;
@ -56,7 +59,7 @@ import javax.annotation.Nullable;
public class FabricUIManager implements UIManager, JSHandler { public class FabricUIManager implements UIManager, JSHandler {
private static final String TAG = FabricUIManager.class.getSimpleName(); private static final String TAG = FabricUIManager.class.getSimpleName();
private static final boolean DEBUG = true; private static final boolean DEBUG = ReactBuildConfig.DEBUG || PrinterHolder.getPrinter().shouldDisplayLogMessage(ReactDebugOverlayTags.FABRIC_UI_MANAGER);
private final RootShadowNodeRegistry mRootShadowNodeRegistry = new RootShadowNodeRegistry(); private final RootShadowNodeRegistry mRootShadowNodeRegistry = new RootShadowNodeRegistry();
private final ReactApplicationContext mReactApplicationContext; private final ReactApplicationContext mReactApplicationContext;
@ -100,7 +103,7 @@ public class FabricUIManager implements UIManager, JSHandler {
public ReactShadowNode createNode( public ReactShadowNode createNode(
int reactTag, String viewName, int rootTag, ReadableNativeMap props, long instanceHandle) { int reactTag, String viewName, int rootTag, ReadableNativeMap props, long instanceHandle) {
if (DEBUG) { if (DEBUG) {
Log.d(TAG, "createNode \n\ttag: " + reactTag + FLog.d(TAG, "createNode \n\ttag: " + reactTag +
"\n\tviewName: " + viewName + "\n\tviewName: " + viewName +
"\n\trootTag: " + rootTag + "\n\trootTag: " + rootTag +
"\n\tprops: " + props); "\n\tprops: " + props);
@ -151,7 +154,7 @@ public class FabricUIManager implements UIManager, JSHandler {
@DoNotStrip @DoNotStrip
public ReactShadowNode cloneNode(ReactShadowNode node, long instanceHandle) { public ReactShadowNode cloneNode(ReactShadowNode node, long instanceHandle) {
if (DEBUG) { if (DEBUG) {
Log.d(TAG, "cloneNode \n\tnode: " + node); FLog.d(TAG, "cloneNode \n\tnode: " + node);
} }
try { try {
ReactShadowNode clone = node.mutableCopy(instanceHandle); ReactShadowNode clone = node.mutableCopy(instanceHandle);
@ -172,7 +175,7 @@ public class FabricUIManager implements UIManager, JSHandler {
@DoNotStrip @DoNotStrip
public ReactShadowNode cloneNodeWithNewChildren(ReactShadowNode node, long instanceHandle) { public ReactShadowNode cloneNodeWithNewChildren(ReactShadowNode node, long instanceHandle) {
if (DEBUG) { if (DEBUG) {
Log.d(TAG, "cloneNodeWithNewChildren \n\tnode: " + node); FLog.d(TAG, "cloneNodeWithNewChildren \n\tnode: " + node);
} }
try { try {
ReactShadowNode clone = node.mutableCopyWithNewChildren(instanceHandle); ReactShadowNode clone = node.mutableCopyWithNewChildren(instanceHandle);
@ -194,7 +197,7 @@ public class FabricUIManager implements UIManager, JSHandler {
public ReactShadowNode cloneNodeWithNewProps( public ReactShadowNode cloneNodeWithNewProps(
ReactShadowNode node, @Nullable ReadableNativeMap newProps, long instanceHandle) { ReactShadowNode node, @Nullable ReadableNativeMap newProps, long instanceHandle) {
if (DEBUG) { if (DEBUG) {
Log.d(TAG, "cloneNodeWithNewProps \n\tnode: " + node + "\n\tprops: " + newProps); FLog.d(TAG, "cloneNodeWithNewProps \n\tnode: " + node + "\n\tprops: " + newProps);
} }
try { try {
ReactShadowNode clone = node.mutableCopyWithNewProps(instanceHandle, ReactShadowNode clone = node.mutableCopyWithNewProps(instanceHandle,
@ -218,7 +221,7 @@ public class FabricUIManager implements UIManager, JSHandler {
public ReactShadowNode cloneNodeWithNewChildrenAndProps( public ReactShadowNode cloneNodeWithNewChildrenAndProps(
ReactShadowNode node, ReadableNativeMap newProps, long instanceHandle) { ReactShadowNode node, ReadableNativeMap newProps, long instanceHandle) {
if (DEBUG) { if (DEBUG) {
Log.d(TAG, "cloneNodeWithNewChildrenAndProps \n\tnode: " + node + "\n\tnewProps: " + newProps); FLog.d(TAG, "cloneNodeWithNewChildrenAndProps \n\tnode: " + node + "\n\tnewProps: " + newProps);
} }
try { try {
ReactShadowNode clone = ReactShadowNode clone =
@ -252,7 +255,7 @@ public class FabricUIManager implements UIManager, JSHandler {
@DoNotStrip @DoNotStrip
public void appendChild(ReactShadowNode parent, ReactShadowNode child) { public void appendChild(ReactShadowNode parent, ReactShadowNode child) {
if (DEBUG) { if (DEBUG) {
Log.d(TAG, "appendChild \n\tparent: " + parent + "\n\tchild: " + child); FLog.d(TAG, "appendChild \n\tparent: " + parent + "\n\tchild: " + child);
} }
try { try {
// If the child to append is shared with another tree (child.getParent() != null), // If the child to append is shared with another tree (child.getParent() != null),
@ -274,7 +277,7 @@ public class FabricUIManager implements UIManager, JSHandler {
@DoNotStrip @DoNotStrip
public List<ReactShadowNode> createChildSet(int rootTag) { public List<ReactShadowNode> createChildSet(int rootTag) {
if (DEBUG) { if (DEBUG) {
Log.d(TAG, "createChildSet rootTag: " + rootTag); FLog.d(TAG, "createChildSet rootTag: " + rootTag);
} }
return new ArrayList<>(1); return new ArrayList<>(1);
} }
@ -292,7 +295,7 @@ public class FabricUIManager implements UIManager, JSHandler {
try { try {
childList = childList == null ? new LinkedList<ReactShadowNode>() : childList; childList = childList == null ? new LinkedList<ReactShadowNode>() : childList;
if (DEBUG) { if (DEBUG) {
Log.d(TAG, "completeRoot rootTag: " + rootTag + ", childList: " + childList); FLog.d(TAG, "completeRoot rootTag: " + rootTag + ", childList: " + childList);
} }
ReactShadowNode currentRootShadowNode = getRootNode(rootTag); ReactShadowNode currentRootShadowNode = getRootNode(rootTag);
Assertions.assertNotNull( Assertions.assertNotNull(
@ -302,7 +305,7 @@ public class FabricUIManager implements UIManager, JSHandler {
currentRootShadowNode = calculateDiffingAndCreateNewRootNode(currentRootShadowNode, childList); currentRootShadowNode = calculateDiffingAndCreateNewRootNode(currentRootShadowNode, childList);
if (DEBUG) { if (DEBUG) {
Log.d( FLog.d(
TAG, TAG,
"ReactShadowNodeHierarchy after diffing: " + currentRootShadowNode.getHierarchyInfo()); "ReactShadowNodeHierarchy after diffing: " + currentRootShadowNode.getHierarchyInfo());
} }
@ -339,16 +342,17 @@ public class FabricUIManager implements UIManager, JSHandler {
} }
if (DEBUG) { if (DEBUG) {
Log.d( FLog.d(
TAG, TAG,
"ReactShadowNodeHierarchy before calculateLayout: " + newRootShadowNode.getHierarchyInfo()); "ReactShadowNodeHierarchy before calculateLayout: " + newRootShadowNode.getHierarchyInfo());
} }
notifyOnBeforeLayoutRecursive(newRootShadowNode); notifyOnBeforeLayoutRecursive(newRootShadowNode);
newRootShadowNode.calculateLayout(); newRootShadowNode.calculateLayout();
if (DEBUG) { if (DEBUG) {
Log.d( FLog.d(
TAG, TAG,
"ReactShadowNodeHierarchy after calculateLayout: " + newRootShadowNode.getHierarchyInfo()); "ReactShadowNodeHierarchy after calculateLayout: " + newRootShadowNode.getHierarchyInfo());
} }
@ -425,7 +429,7 @@ public class FabricUIManager implements UIManager, JSHandler {
public void updateRootLayoutSpecs(int rootViewTag, int widthMeasureSpec, int heightMeasureSpec) { public void updateRootLayoutSpecs(int rootViewTag, int widthMeasureSpec, int heightMeasureSpec) {
ReactShadowNode rootNode = mRootShadowNodeRegistry.getNode(rootViewTag); ReactShadowNode rootNode = mRootShadowNodeRegistry.getNode(rootViewTag);
if (rootNode == null) { if (rootNode == null) {
Log.w(ReactConstants.TAG, "Tried to update non-existent root tag: " + rootViewTag); FLog.w(ReactConstants.TAG, "Tried to update non-existent root tag: " + rootViewTag);
return; return;
} }
updateRootView(rootNode, widthMeasureSpec, heightMeasureSpec); updateRootView(rootNode, widthMeasureSpec, heightMeasureSpec);
@ -439,7 +443,7 @@ public class FabricUIManager implements UIManager, JSHandler {
private synchronized void updateRootSize(int rootTag, int newWidth, int newHeight) { private synchronized void updateRootSize(int rootTag, int newWidth, int newHeight) {
ReactShadowNode rootNode = mRootShadowNodeRegistry.getNode(rootTag); ReactShadowNode rootNode = mRootShadowNodeRegistry.getNode(rootTag);
if (rootNode == null) { if (rootNode == null) {
Log.w( FLog.w(
ReactConstants.TAG, ReactConstants.TAG,
"Tried to update size of non-existent tag: " + rootTag); "Tried to update size of non-existent tag: " + rootTag);
return; return;
@ -509,7 +513,7 @@ public class FabricUIManager implements UIManager, JSHandler {
// a RuntimeException // a RuntimeException
context.handleException(new RuntimeException(t)); context.handleException(new RuntimeException(t));
} catch (Exception ex) { } catch (Exception ex) {
Log.e(TAG, "Exception while executing a Fabric method", t); FLog.e(TAG, "Exception while executing a Fabric method", t);
throw new RuntimeException(ex.getMessage(), t); throw new RuntimeException(ex.getMessage(), t);
} }
} }
@ -521,7 +525,7 @@ public class FabricUIManager implements UIManager, JSHandler {
long context = mJSContext.get(); long context = mJSContext.get();
long eventTarget = mBinding.createEventTarget(context, instanceHandle); long eventTarget = mBinding.createEventTarget(context, instanceHandle);
if (DEBUG) { if (DEBUG) {
Log.d( FLog.d(
TAG, TAG,
"Created EventTarget: " + eventTarget + " for tag: " + reactTag + " with instanceHandle: " + instanceHandle); "Created EventTarget: " + eventTarget + " for tag: " + reactTag + " with instanceHandle: " + instanceHandle);
} }
@ -547,7 +551,7 @@ public class FabricUIManager implements UIManager, JSHandler {
@DoNotStrip @DoNotStrip
public void invoke(long eventTarget, String name, WritableMap params) { public void invoke(long eventTarget, String name, WritableMap params) {
if (DEBUG) { if (DEBUG) {
Log.d( FLog.d(
TAG, TAG,
"Dispatching event for target: " + eventTarget); "Dispatching event for target: " + eventTarget);
} }

View File

@ -30,6 +30,7 @@ rn_android_library(
react_native_target("java/com/facebook/react/animation:animation"), react_native_target("java/com/facebook/react/animation:animation"),
react_native_target("java/com/facebook/react/bridge:bridge"), react_native_target("java/com/facebook/react/bridge:bridge"),
react_native_target("java/com/facebook/react/common:common"), react_native_target("java/com/facebook/react/common:common"),
react_native_target("java/com/facebook/react/common:common"),
react_native_target("java/com/facebook/react/module/annotations:annotations"), react_native_target("java/com/facebook/react/module/annotations:annotations"),
react_native_target("java/com/facebook/react/modules/core:core"), react_native_target("java/com/facebook/react/modules/core:core"),
react_native_target("java/com/facebook/react/modules/i18nmanager:i18nmanager"), react_native_target("java/com/facebook/react/modules/i18nmanager:i18nmanager"),

View File

@ -8,8 +8,11 @@ package com.facebook.react.uimanager;
import static java.lang.System.arraycopy; import static java.lang.System.arraycopy;
import android.util.Log; import com.facebook.common.logging.FLog;
import com.facebook.debug.holder.PrinterHolder;
import com.facebook.debug.tags.ReactDebugOverlayTags;
import com.facebook.infer.annotation.Assertions; import com.facebook.infer.annotation.Assertions;
import com.facebook.react.common.build.ReactBuildConfig;
import com.facebook.react.uimanager.annotations.ReactPropertyHolder; import com.facebook.react.uimanager.annotations.ReactPropertyHolder;
import com.facebook.yoga.YogaAlign; import com.facebook.yoga.YogaAlign;
import com.facebook.yoga.YogaBaselineFunction; import com.facebook.yoga.YogaBaselineFunction;
@ -59,7 +62,7 @@ import javax.annotation.Nullable;
@ReactPropertyHolder @ReactPropertyHolder
public class ReactShadowNodeImpl implements ReactShadowNode<ReactShadowNodeImpl> { public class ReactShadowNodeImpl implements ReactShadowNode<ReactShadowNodeImpl> {
private static final boolean DEBUG = true; private static final boolean DEBUG = ReactBuildConfig.DEBUG || PrinterHolder.getPrinter().shouldDisplayLogMessage(ReactDebugOverlayTags.FABRIC_UI_MANAGER);
private static final String TAG = ReactShadowNodeImpl.class.getSimpleName(); private static final String TAG = ReactShadowNodeImpl.class.getSimpleName();
private static final YogaConfig sYogaConfig; private static final YogaConfig sYogaConfig;
static { static {
@ -75,7 +78,7 @@ public class ReactShadowNodeImpl implements ReactShadowNode<ReactShadowNodeImpl>
Assertions.assertNotNull(oldReactShadowNode); Assertions.assertNotNull(oldReactShadowNode);
if (DEBUG) { if (DEBUG) {
Log.d( FLog.d(
TAG, TAG,
"YogaNode started cloning: oldYogaNode: " + oldReactShadowNode + " - parent: " "YogaNode started cloning: oldYogaNode: " + oldReactShadowNode + " - parent: "
+ parentReactShadowNode + " index: " + childIndex); + parentReactShadowNode + " index: " + childIndex);