From 5a446c9ab51a015203a2f9ca8bb7e63429f9411b Mon Sep 17 00:00:00 2001 From: Johannes Mockenhaupt Date: Sat, 14 Oct 2017 15:24:41 +0200 Subject: [PATCH] Log posted events. --- .../info/nightscout/androidaps/Config.java | 1 + .../nightscout/androidaps/LoggingBus.java | 22 +++++++++++++++++++ .../info/nightscout/androidaps/MainApp.java | 4 +++- 3 files changed, 26 insertions(+), 1 deletion(-) create mode 100644 app/src/main/java/info/nightscout/androidaps/LoggingBus.java diff --git a/app/src/main/java/info/nightscout/androidaps/Config.java b/app/src/main/java/info/nightscout/androidaps/Config.java index abda0ca941..6bbc908188 100644 --- a/app/src/main/java/info/nightscout/androidaps/Config.java +++ b/app/src/main/java/info/nightscout/androidaps/Config.java @@ -40,6 +40,7 @@ public class Config { public static final boolean logPumpActions = true; public static final boolean logCongigBuilderActions = true; public static final boolean logAutosensData = false; + public static final boolean logEvents = true; // DanaR specific public static final boolean logDanaBTComm = true; diff --git a/app/src/main/java/info/nightscout/androidaps/LoggingBus.java b/app/src/main/java/info/nightscout/androidaps/LoggingBus.java new file mode 100644 index 0000000000..8b5664b511 --- /dev/null +++ b/app/src/main/java/info/nightscout/androidaps/LoggingBus.java @@ -0,0 +1,22 @@ +package info.nightscout.androidaps; + +import com.squareup.otto.Bus; + +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +class LoggingBus extends Bus { + private static Logger log = LoggerFactory.getLogger(LoggingBus.class); + + private final Bus delegate; + + public LoggingBus(Bus bus) { + delegate = bus; + } + + @Override + public void post(Object event) { + log.debug("Event posted: " + event); + super.post(event); + } +} diff --git a/app/src/main/java/info/nightscout/androidaps/MainApp.java b/app/src/main/java/info/nightscout/androidaps/MainApp.java index 209adfe1c4..3392a0193a 100644 --- a/app/src/main/java/info/nightscout/androidaps/MainApp.java +++ b/app/src/main/java/info/nightscout/androidaps/MainApp.java @@ -104,7 +104,9 @@ public class MainApp extends Application { log.info("Version: " + BuildConfig.VERSION_NAME); log.info("BuildVersion: " + BuildConfig.BUILDVERSION); - sBus = new Bus(ThreadEnforcer.ANY); + Bus bus = new Bus(ThreadEnforcer.ANY); + sBus = Config.logEvents ? new LoggingBus(bus) : bus; + sInstance = this; sResources = getResources();