Skip to content

Instantly share code, notes, and snippets.

@yongjhih
Created October 16, 2019 21:57
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save yongjhih/9a203147eda126a407e2ed6cb841cae3 to your computer and use it in GitHub Desktop.
Save yongjhih/9a203147eda126a407e2ed6cb841cae3 to your computer and use it in GitHub Desktop.
class EmbraceLogTree extends LogTree {
static const V = "V";
static const D = "D";
static const I = "I";
static const W = "W";
static const E = "E";
static const List<String> DEFAULT = [V, D, I, W, E];
List<String> logLevels;
EmbraceLogTree({this.logLevels = DEFAULT});
@override
log(String level, String msg,
{String tag, dynamic ex, StackTrace stacktrace}) {
var logTag = tag ?? LogTree.getTag();
var _message = "";
if (ex != null) {
var tmpStacktrace =
stacktrace?.toString()?.split('\n') ?? LogTree.getStacktrace();
var stackTraceMessage =
tmpStacktrace.map((stackLine) => "\t$stackLine").join("\n");
_message = "$level\t$logTag:\t $msg \n${ex.toString()}\n$stackTraceMessage";
} else {
_message = "$level\t$logTag:\t $msg";
}
switch (level) {
case V: {
Embrace.logInfo(_message);
break;
}
case D: {
Embrace.logInfo(_message);
break;
}
case I: {
Embrace.logInfo(_message);
break;
}
case W: {
Embrace.logWarning(_message);
break;
}
case E: {
Embrace.logError(_message);
break;
}
}
}
@override
List<String> getLevels() {
return logLevels;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment