Skip to content

Commit

Permalink
fix(android): concat log msg only in debug mode
Browse files Browse the repository at this point in the history
  • Loading branch information
siguangli2018 committed Mar 18, 2024
1 parent 6889560 commit c86272c
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,10 @@ public static void enableDebugLog(boolean debuggable) {
DEBUG_ENABLE = debuggable;
}

public static boolean isDebugMode() {
return DEBUG_ENABLE;
}

public static void d(String tag, String msg) {
if (DEBUG_ENABLE) {
Log.d(tag, msg);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -414,8 +414,10 @@ public void dispatchEvent(int rootId, int nodeId, @NonNull String eventName,
&& !mVirtualNodeManager.checkRegisteredEvent(rootId, nodeId, lowerCaseEventName)) {
return;
}
LogUtils.d(TAG, "dispatchEvent: id " + nodeId + ", eventName " + eventName
+ ", eventType " + eventType + ", params " + params + "\n ");
if (LogUtils.isDebugMode() && !eventName.equals(ChoreographerUtils.DO_FRAME)) {
LogUtils.d(TAG, "dispatchEvent: id " + nodeId + ", eventName " + eventName
+ ", eventType " + eventType + ", params " + params + "\n ");
}
mRenderProvider.dispatchEvent(rootId, nodeId, lowerCaseEventName, params, useCapture,
useBubble);
}
Expand Down Expand Up @@ -497,9 +499,11 @@ public void createNode(final int rootId, @NonNull List<Object> nodeList)
+ nodeIndex + ", className " + className);
}
final Map<String, Object> props = MapUtils.getMapValue(node, NODE_PROPS);
LogUtils.d(TAG, "createNode: id " + nodeId + ", pid " + nodePid
+ ", index " + nodeIndex + ", name " + className + "\n props " + props
+ "\n ");
if (LogUtils.isDebugMode()) {
LogUtils.d(TAG, "createNode: id " + nodeId + ", pid " + nodePid
+ ", index " + nodeIndex + ", name " + className + "\n props " + props
+ "\n ");
}
mVirtualNodeManager.createNode(rootId, nodeId, nodePid, nodeIndex, className, props);
// If multiple level are nested, the parent is outermost text node.
VirtualNode parent = mVirtualNodeManager.checkVirtualParent(rootId, nodeId);
Expand Down Expand Up @@ -562,9 +566,11 @@ public void updateNode(final int rootId, @NonNull List<Object> nodeList)
}
final Map<String, Object> diffProps = MapUtils.getMapValue(node, NODE_PROPS);
final List<Object> delProps = MapUtils.getListValue(node, NODE_DELETE_PROPS);
LogUtils.d(TAG,
"updateNode: id " + nodeId + ", diff " + diffProps + ", delete " + delProps
+ "\n ");
if (LogUtils.isDebugMode()) {
LogUtils.d(TAG,
"updateNode: id " + nodeId + ", diff " + diffProps + ", delete " + delProps
+ "\n ");
}
mVirtualNodeManager.updateNode(rootId, nodeId, diffProps, delProps);
// If multiple level are nested, the parent is outermost text node.
VirtualNode parent = mVirtualNodeManager.checkVirtualParent(rootId, nodeId);
Expand All @@ -585,7 +591,9 @@ public void updateNode(final int rootId, @NonNull List<Object> nodeList)
@Override
public void deleteNode(final int rootId, @NonNull int[] ids) throws NativeRenderException {
final List<UITaskExecutor> taskList = new ArrayList<>(ids.length);
LogUtils.d(TAG, "deleteNode " + Arrays.toString(ids) + "\n ");
if (LogUtils.isDebugMode()) {
LogUtils.d(TAG, "deleteNode " + Arrays.toString(ids) + "\n ");
}
for (final int nodeId : ids) {
// The node id should not be negative number.
if (nodeId < 0) {
Expand All @@ -610,14 +618,18 @@ public void deleteNode(final int rootId, @NonNull int[] ids) throws NativeRender
@Override
public void moveNode(final int rootId, final int[] ids, final int newPid, final int oldPid,
final int insertIndex) throws NativeRenderException {
LogUtils.d(TAG, "moveNode: ids " + Arrays.toString(ids) + ", newPid " +
newPid + ", oldPid " + oldPid + ", insertIndex " + insertIndex + "\n ");
if (LogUtils.isDebugMode()) {
LogUtils.d(TAG, "moveNode: ids " + Arrays.toString(ids) + ", newPid " +
newPid + ", oldPid " + oldPid + ", insertIndex " + insertIndex + "\n ");
}
addUITask(() -> mRenderManager.moveNode(rootId, ids, newPid, oldPid, insertIndex));
}

@Override
public void moveNode(final int rootId, final int pid, @NonNull final List<Object> list) {
LogUtils.d(TAG, "moveNode: pid " + pid + ", node list " + list + "\n ");
if (LogUtils.isDebugMode()) {
LogUtils.d(TAG, "moveNode: pid " + pid + ", node list " + list + "\n ");
}
VirtualNode parent = mVirtualNodeManager.getVirtualNode(rootId, pid);
if (parent == null) {
addUITask(() -> mRenderManager.moveNode(rootId, pid, list));
Expand Down Expand Up @@ -695,8 +707,10 @@ public void updateEventListener(final int rootId, @NonNull List<Object> eventLis
throw new NativeRenderException(INVALID_NODE_DATA_ERR,
TAG + ": updateEventListener: invalid negative id=" + nodeId);
}
LogUtils.d(TAG,
"updateEventListener: id " + nodeId + ", eventProps " + eventProps + "\n ");
if (LogUtils.isDebugMode()) {
LogUtils.d(TAG,
"updateEventListener: id " + nodeId + ", eventProps " + eventProps + "\n ");
}
mVirtualNodeManager.updateEventListener(rootId, nodeId, eventProps);
taskList.add(() -> mRenderManager.updateEventListener(rootId, nodeId, eventProps));
}
Expand Down Expand Up @@ -727,9 +741,11 @@ public void callUIFunction(final int rootId, final int nodeId, final long callba
throw new NativeRenderException(INVALID_NODE_DATA_ERR,
TAG + ": callUIFunction: invalid negative id=" + nodeId);
}
LogUtils.d(TAG,
"callUIFunction: id " + nodeId + ", functionName " + functionName + ", params"
+ params + "\n ");
if (LogUtils.isDebugMode()) {
LogUtils.d(TAG,
"callUIFunction: id " + nodeId + ", functionName " + functionName + ", params"
+ params + "\n ");
}
// If callbackId equal to 0 mean this call does not need to callback.
final UIPromise promise =
(callbackId == 0) ? null : new UIPromise(callbackId, functionName, rootId, nodeId,
Expand All @@ -749,7 +765,9 @@ public void doPromiseCallBack(int result, long callbackId, @NonNull String funct

@Override
public void endBatch(final int rootId) throws NativeRenderException {
LogUtils.d(TAG, "=============================endBatch " + rootId);
if (LogUtils.isDebugMode()) {
LogUtils.d(TAG, "=============================endBatch " + rootId);
}
Map<Integer, Layout> layoutToUpdate = mVirtualNodeManager.endBatch(rootId);
if (layoutToUpdate != null) {
for (Entry<Integer, Layout> entry : layoutToUpdate.entrySet()) {
Expand Down

0 comments on commit c86272c

Please sign in to comment.