Added task breadcrumbs

This commit is contained in:
M66B
2019-08-22 08:44:22 +02:00
parent 4a3d266318
commit da65d6f264
3 changed files with 23 additions and 8 deletions

View File

@@ -35,7 +35,9 @@ import androidx.lifecycle.OnLifecycleEvent;
import androidx.localbroadcastmanager.content.LocalBroadcastManager;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
@@ -44,6 +46,7 @@ import java.util.concurrent.Executors;
// Results will not be delivered to destroyed fragments
public abstract class SimpleTask<T> implements LifecycleObserver {
private boolean log = true;
private boolean count = true;
private int executing = 0;
@@ -54,6 +57,11 @@ public abstract class SimpleTask<T> implements LifecycleObserver {
static final String ACTION_TASK_COUNT = BuildConfig.APPLICATION_ID + ".ACTION_TASK_COUNT";
public SimpleTask<T> setLog(boolean log) {
this.log = log;
return this;
}
public SimpleTask<T> setCount(boolean count) {
this.count = count;
return this;
@@ -158,9 +166,16 @@ public abstract class SimpleTask<T> implements LifecycleObserver {
Log.e(ex);
} finally {
try {
if (ex == null)
if (ex == null) {
if (log && BuildConfig.BETA_RELEASE) {
Log.i("Crumb " + name);
Map<String, String> crumb = new HashMap<>();
crumb.put("name", name);
Log.breadcrumb("task", crumb);
}
onExecuted(args, (T) data);
else
} else
onException(args, ex);
} catch (Throwable ex) {
onException(args, ex);