Commit 6e9b0a6a authored by Firewayer's avatar Firewayer Committed by Luke

Debugger

1.增加safeMode字段接口,设置为true后Debugger.exception不再Throw Exception, 默认为false。
2.增加Log实现接口,方便外部获取Boost相关log信息。
parent 496e857b
......@@ -26,15 +26,21 @@ package com.idlefish.flutterboost;
import android.util.Log;
import com.idlefish.flutterboost.log.AndroidLog;
import com.idlefish.flutterboost.log.ILog;
public class Debuger {
private static final String TAG = "FlutterBoost#";
private static final Debuger DEBUG = new Debuger();
private static boolean sSafeMode = false;
private static ILog sLog = new AndroidLog();
private Debuger(){ }
private Debuger() {
}
private void print(String info) {
if(isDebug()) {
Log.e(TAG, info);
if (isDebug()) {
sLog.e(TAG, info);
}
}
......@@ -43,26 +49,50 @@ public class Debuger {
}
public static void exception(String message) {
if(isDebug()) {
if (canThrowError()) {
throw new RuntimeException(message);
}else{
Log.e(TAG,"exception",new RuntimeException(message));
} else {
sLog.e(TAG, "exception", new RuntimeException(message));
}
}
public static void exception(Throwable t) {
if(isDebug()) {
if (canThrowError()) {
throw new RuntimeException(t);
}else{
Log.e(TAG,"exception",t);
} else {
sLog.e(TAG, "exception", t);
}
}
public static boolean isDebug(){
public static boolean isDebug() {
try {
return FlutterBoost.instance().platform().isDebug();
}catch (Throwable t){
} catch (Throwable t) {
return false;
}
}
/**
* 设置boost log接收实现,默认为Anroid自带Log
*
* @param log
*/
public static void setLog(ILog log) {
if (log != null) {
sLog = log;
}
}
/**
* 设置Debugger策略倾向,如tue,则优先保证程序稳定,false,可抛Error
*
* @param safeMode
*/
public static void setSafeMode(boolean safeMode) {
sSafeMode = safeMode;
}
private static boolean canThrowError() {
return isDebug() && !sSafeMode;
}
}
package com.idlefish.flutterboost.log;
import android.util.Log;
public class AndroidLog implements ILog {
@Override
public void d(String tag, String msg) {
Log.d(tag, msg);
}
@Override
public void d(String tag, String msg, Throwable throwable) {
Log.d(tag, msg, throwable);
}
@Override
public void e(String tag, String msg) {
Log.e(tag, msg);
}
@Override
public void e(String tag, String msg, Throwable throwable) {
Log.e(tag, msg, throwable);
}
@Override
public void i(String tag, String msg) {
Log.i(tag, msg);
}
@Override
public void i(String tag, String msg, Throwable throwable) {
Log.i(tag, msg, throwable);
}
@Override
public void v(String tag, String msg) {
Log.v(tag, msg);
}
@Override
public void v(String tag, String msg, Throwable throwable) {
Log.v(tag, msg, throwable);
}
@Override
public void w(String tag, String msg) {
Log.w(tag, msg);
}
@Override
public void w(String tag, String msg, Throwable throwable) {
Log.w(tag, msg, throwable);
}
@Override
public boolean isLogLevelEnabled(int level) {
return true;
}
}
package com.idlefish.flutterboost.log;
public interface ILog {
public enum LogLevelEnum {
VERBOSE(0, "V"), DEBUG(1, "D"), INFO(2, "I"), WARNING(3, "W"), ERROR(4, "E");
private String logLevelName;
private int loglevel;
LogLevelEnum(int loglevel, String name) {
this.loglevel = loglevel;
this.logLevelName = name;
}
public String getLogLevelName() {
return logLevelName;
}
public int getLoglevel() {
return loglevel;
}
}
void d(String tag, String msg);
void d(String tag, String msg, Throwable throwable);
void e(String tag, String msg);
void e(String tag, String msg, Throwable throwable);
void i(String tag, String msg);
void i(String tag, String msg, Throwable throwable);
void v(String tag, String msg);
void v(String tag, String msg, Throwable throwable);
void w(String tag, String msg);
void w(String tag, String msg, Throwable throwable);
boolean isLogLevelEnabled(int level);
}
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment