android: devkit log
This commit is contained in:
parent
281d3d7425
commit
8a5443b46a
@ -1,7 +1,18 @@
|
|||||||
package pub.doric.devkit;
|
package pub.doric.devkit;
|
||||||
|
|
||||||
|
import android.util.Log;
|
||||||
|
|
||||||
|
import androidx.annotation.Nullable;
|
||||||
|
|
||||||
|
import com.google.gson.JsonObject;
|
||||||
|
|
||||||
|
import java.io.PrintWriter;
|
||||||
|
import java.io.StringWriter;
|
||||||
|
|
||||||
|
import pub.doric.DoricContext;
|
||||||
import pub.doric.devkit.remote.DoricRemoteJSExecutor;
|
import pub.doric.devkit.remote.DoricRemoteJSExecutor;
|
||||||
import pub.doric.engine.DoricJSEngine;
|
import pub.doric.engine.DoricJSEngine;
|
||||||
|
import pub.doric.utils.DoricLog;
|
||||||
|
|
||||||
public class DoricDebugJSEngine extends DoricJSEngine {
|
public class DoricDebugJSEngine extends DoricJSEngine {
|
||||||
|
|
||||||
@ -16,4 +27,41 @@ public class DoricDebugJSEngine extends DoricJSEngine {
|
|||||||
protected void initJSEngine() {
|
protected void initJSEngine() {
|
||||||
mDoricJSE = new DoricRemoteJSExecutor(statusCallback);
|
mDoricJSE = new DoricRemoteJSExecutor(statusCallback);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onException(@Nullable DoricContext context, Exception e) {
|
||||||
|
Log.e(DoricJSEngine.class.getSimpleName(), "In source file: " + (context != null ? context.getSource() : "Unknown"));
|
||||||
|
e.printStackTrace();
|
||||||
|
|
||||||
|
JsonObject jsonObject = new JsonObject();
|
||||||
|
jsonObject.addProperty("source", "In source file: " + (context != null ? context.getSource() : "Unknown"));
|
||||||
|
|
||||||
|
StringWriter stringWriter = new StringWriter();
|
||||||
|
e.printStackTrace(new PrintWriter(stringWriter));
|
||||||
|
jsonObject.addProperty("exception", stringWriter.toString());
|
||||||
|
DevKit.getInstance().sendDevCommand(IDevKit.Command.EXCEPTION, jsonObject);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onLog(int type, String message) {
|
||||||
|
String typeString = "DEFAULT";
|
||||||
|
switch (type) {
|
||||||
|
case Log.ERROR:
|
||||||
|
DoricLog.suffix_e("_js", message);
|
||||||
|
typeString = "ERROR";
|
||||||
|
break;
|
||||||
|
case Log.WARN:
|
||||||
|
DoricLog.suffix_w("_js", message);
|
||||||
|
typeString = "WARN";
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
DoricLog.suffix_d("_js", message);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
JsonObject jsonObject = new JsonObject();
|
||||||
|
jsonObject.addProperty("type", typeString);
|
||||||
|
jsonObject.addProperty("message", message);
|
||||||
|
DevKit.getInstance().sendDevCommand(IDevKit.Command.LOG, jsonObject);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -5,7 +5,7 @@ import com.google.gson.JsonObject;
|
|||||||
public interface IDevKit {
|
public interface IDevKit {
|
||||||
|
|
||||||
enum Command {
|
enum Command {
|
||||||
DEBUG, HOT_RELOAD
|
DEBUG, HOT_RELOAD, EXCEPTION, LOG
|
||||||
}
|
}
|
||||||
|
|
||||||
void connectDevKit(String url);
|
void connectDevKit(String url);
|
||||||
|
Reference in New Issue
Block a user