feat:Doric cli show doric logs

This commit is contained in:
pengfeizhou
2021-02-05 19:36:25 +08:00
committed by osborn
parent d4c8d08660
commit ddc74a9027
7 changed files with 196 additions and 20 deletions

View File

@@ -9,9 +9,12 @@ import org.greenrobot.eventbus.EventBus;
import org.greenrobot.eventbus.Subscribe;
import org.greenrobot.eventbus.ThreadMode;
import pub.doric.Doric;
import pub.doric.DoricContext;
import pub.doric.DoricContextManager;
import pub.doric.DoricLibrary;
import pub.doric.DoricRegistry;
import pub.doric.devkit.event.ConnectExceptionEvent;
import pub.doric.devkit.event.EOFExceptionEvent;
import pub.doric.devkit.event.EnterDebugEvent;
@@ -31,6 +34,16 @@ public class DevKit implements IDevKit {
}
private DevKit() {
Doric.registerLibrary(new DoricLibrary() {
@Override
public void load(DoricRegistry registry) {
registry.registerMonitor(new DoricDevMonitor());
}
});
for (DoricContext context : DoricContextManager.aliveContexts()) {
context.getDriver().getRegistry().registerMonitor(new DoricDevMonitor());
break;
}
EventBus.getDefault().register(this);
}

View File

@@ -0,0 +1,70 @@
/*
* Copyright [2019] [Doric.Pub]
*
* 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 pub.doric.devkit;
import android.util.Log;
import com.google.gson.JsonObject;
import java.io.StringWriter;
import pub.doric.DoricContext;
import pub.doric.IDoricMonitor;
import pub.doric.utils.DoricLog;
/**
* @Description: pub.doric.devkit
* @Author: pengfei.zhou
* @CreateDate: 2/5/21
*/
public class DoricDevMonitor implements IDoricMonitor {
@Override
public void onException(DoricContext context, Exception e) {
if (!DoricDev.getInstance().isInDevMode()) {
return;
}
JsonObject jsonObject = new JsonObject();
jsonObject.addProperty("source", "In source file: " + (context != null ? context.getSource() : "Unknown"));
StringWriter stringWriter = new StringWriter();
jsonObject.addProperty("exception", stringWriter.toString());
DevKit.getInstance().sendDevCommand(IDevKit.Command.EXCEPTION, jsonObject);
}
@Override
public void onLog(int type, String message) {
if (!DoricDev.getInstance().isInDevMode()) {
return;
}
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);
}
}