diff --git a/framework/android/src/main/java/com/tencent/mtt/hippy/HippyEngineManagerImpl.java b/framework/android/src/main/java/com/tencent/mtt/hippy/HippyEngineManagerImpl.java index a17659a09c5..1507076c967 100644 --- a/framework/android/src/main/java/com/tencent/mtt/hippy/HippyEngineManagerImpl.java +++ b/framework/android/src/main/java/com/tencent/mtt/hippy/HippyEngineManagerImpl.java @@ -40,6 +40,7 @@ import com.tencent.mtt.hippy.common.Callback; import com.tencent.mtt.hippy.common.HippyJsException; import com.tencent.mtt.hippy.common.HippyMap; +import com.tencent.mtt.hippy.common.LogAdapter; import com.tencent.mtt.hippy.common.ThreadExecutor; import com.tencent.mtt.hippy.devsupport.DevServerCallBack; import com.tencent.mtt.hippy.devsupport.DevSupportManager; @@ -282,6 +283,11 @@ public FontAdapter getFontAdapter() { return mEngineContext.getGlobalConfigs().getFontScaleAdapter(); } + @Override + public LogAdapter getLogAdapter() { + return mEngineContext.getGlobalConfigs().getLogAdapter(); + } + @Override public ImageDecoderAdapter getImageDecoderAdapter() { return mEngineContext.getGlobalConfigs().getImageDecoderAdapter(); diff --git a/framework/android/src/main/java/com/tencent/mtt/hippy/adapter/HippyLogAdapter.java b/framework/android/src/main/java/com/tencent/mtt/hippy/adapter/HippyLogAdapter.java index 68247f12b46..ceea23bda95 100644 --- a/framework/android/src/main/java/com/tencent/mtt/hippy/adapter/HippyLogAdapter.java +++ b/framework/android/src/main/java/com/tencent/mtt/hippy/adapter/HippyLogAdapter.java @@ -16,15 +16,8 @@ package com.tencent.mtt.hippy.adapter; -import androidx.annotation.NonNull; +import com.tencent.mtt.hippy.common.LogAdapter; -public interface HippyLogAdapter { +public interface HippyLogAdapter extends LogAdapter { - int LOG_SEVERITY_DEBUG = -1; - int LOG_SEVERITY_INFO = 0; - int LOG_SEVERITY_WARNING = 1; - int LOG_SEVERITY_ERROR = 2; - int LOG_SEVERITY_FATAL = 3; - - void onReceiveLogMessage(int level, @NonNull String tag, @NonNull String msg); } diff --git a/modules/android/hippy_support/src/main/java/com/tencent/mtt/hippy/common/LogAdapter.java b/modules/android/hippy_support/src/main/java/com/tencent/mtt/hippy/common/LogAdapter.java new file mode 100644 index 00000000000..5ea1013f100 --- /dev/null +++ b/modules/android/hippy_support/src/main/java/com/tencent/mtt/hippy/common/LogAdapter.java @@ -0,0 +1,30 @@ +/* Tencent is pleased to support the open source community by making Hippy available. + * Copyright (C) 2018 THL A29 Limited, a Tencent company. All rights reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.tencent.mtt.hippy.common; + +import androidx.annotation.NonNull; + +public interface LogAdapter { + + int LOG_SEVERITY_DEBUG = -1; + int LOG_SEVERITY_INFO = 0; + int LOG_SEVERITY_WARNING = 1; + int LOG_SEVERITY_ERROR = 2; + int LOG_SEVERITY_FATAL = 3; + + void onReceiveLogMessage(int level, @NonNull String tag, @NonNull String msg); +} diff --git a/renderer/native/android/src/main/java/com/tencent/renderer/FrameworkProxy.java b/renderer/native/android/src/main/java/com/tencent/renderer/FrameworkProxy.java index c9557957d04..bb931f460ad 100644 --- a/renderer/native/android/src/main/java/com/tencent/renderer/FrameworkProxy.java +++ b/renderer/native/android/src/main/java/com/tencent/renderer/FrameworkProxy.java @@ -18,6 +18,7 @@ import androidx.annotation.NonNull; import androidx.annotation.Nullable; +import com.tencent.mtt.hippy.common.LogAdapter; import com.tencent.renderer.component.image.ImageDecoderAdapter; import com.tencent.renderer.component.text.FontAdapter; import com.tencent.vfs.VfsManager; @@ -31,6 +32,9 @@ public interface FrameworkProxy { @Nullable FontAdapter getFontAdapter(); + @Nullable + LogAdapter getLogAdapter(); + @NonNull VfsManager getVfsManager(); diff --git a/renderer/native/android/src/main/java/com/tencent/renderer/NativeRender.java b/renderer/native/android/src/main/java/com/tencent/renderer/NativeRender.java index b0671b18669..1969583193d 100644 --- a/renderer/native/android/src/main/java/com/tencent/renderer/NativeRender.java +++ b/renderer/native/android/src/main/java/com/tencent/renderer/NativeRender.java @@ -23,6 +23,7 @@ import androidx.annotation.Nullable; import com.tencent.mtt.hippy.HippyInstanceLifecycleEventListener; +import com.tencent.mtt.hippy.common.LogAdapter; import com.tencent.mtt.hippy.uimanager.RenderManager; import com.tencent.renderer.component.image.ImageDecoderAdapter; @@ -35,7 +36,7 @@ import java.util.Map; import java.util.concurrent.Executor; -public interface NativeRender extends RenderExceptionHandler { +public interface NativeRender extends RenderExceptionHandler, RenderLogHandler { @NonNull RenderManager getRenderManager(); diff --git a/renderer/native/android/src/main/java/com/tencent/renderer/NativeRenderDelegate.java b/renderer/native/android/src/main/java/com/tencent/renderer/NativeRenderDelegate.java index e9634d3fb47..40009a013aa 100644 --- a/renderer/native/android/src/main/java/com/tencent/renderer/NativeRenderDelegate.java +++ b/renderer/native/android/src/main/java/com/tencent/renderer/NativeRenderDelegate.java @@ -20,7 +20,7 @@ import java.util.List; -public interface NativeRenderDelegate extends RenderExceptionHandler { +public interface NativeRenderDelegate extends RenderExceptionHandler, RenderLogHandler { void createNode(int rootId, @NonNull List nodeList) throws NativeRenderException; diff --git a/renderer/native/android/src/main/java/com/tencent/renderer/NativeRenderer.java b/renderer/native/android/src/main/java/com/tencent/renderer/NativeRenderer.java index ea487a53522..42c6bec1029 100644 --- a/renderer/native/android/src/main/java/com/tencent/renderer/NativeRenderer.java +++ b/renderer/native/android/src/main/java/com/tencent/renderer/NativeRenderer.java @@ -36,6 +36,7 @@ import androidx.annotation.Nullable; import com.tencent.mtt.hippy.common.Callback; +import com.tencent.mtt.hippy.common.LogAdapter; import com.tencent.mtt.hippy.serialization.nio.reader.BinaryReader; import com.tencent.mtt.hippy.serialization.nio.reader.SafeHeapReader; import com.tencent.mtt.hippy.serialization.nio.writer.SafeHeapWriter; @@ -222,6 +223,11 @@ public FontAdapter getFontAdapter() { return (mFrameworkProxy != null) ? mFrameworkProxy.getFontAdapter() : null; } + @Nullable + public LogAdapter getLogAdapter() { + return (mFrameworkProxy != null) ? mFrameworkProxy.getLogAdapter() : null; + } + @Override @Nullable public Executor getBackgroundExecutor() { @@ -257,6 +263,14 @@ public void handleRenderException(@NonNull Exception exception) { } } + @Override + public void onReceiveRenderLogMessage(int level, @NonNull String tag, @NonNull String msg) { + LogAdapter logAdapter = getLogAdapter(); + if (logAdapter != null) { + logAdapter.onReceiveLogMessage(level, tag, msg); + } + } + @Override public int getEngineId() { if (mFrameworkProxy != null) { diff --git a/renderer/native/android/src/main/java/com/tencent/renderer/RenderLogHandler.java b/renderer/native/android/src/main/java/com/tencent/renderer/RenderLogHandler.java new file mode 100644 index 00000000000..3a16601bda7 --- /dev/null +++ b/renderer/native/android/src/main/java/com/tencent/renderer/RenderLogHandler.java @@ -0,0 +1,31 @@ +/* Tencent is pleased to support the open source community by making Hippy available. + * Copyright (C) 2018 THL A29 Limited, a Tencent company. All rights reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.tencent.renderer; + +import androidx.annotation.NonNull; +import com.tencent.mtt.hippy.common.LogAdapter; + +public interface RenderLogHandler { + /** + * Output render log to host + * + * @param level {@link LogAdapter} the render log level + * @param tag the render log tag + * @param msg the render log message + */ + void onReceiveRenderLogMessage(int level, @NonNull String tag, @NonNull String msg); +}