Commit bef1c5c8 authored by justin's avatar justin Committed by GitHub

Merge pull request #627 from Firewayer/feature/Debuger_opt

Debugger增强优化
parents 19b1c101 4166c531
/*
* The MIT License (MIT)
*
*
* Copyright (c) 2019 Alibaba Group
*
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
......@@ -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