From 71be72cd03669b3a8a80777bd37d33fb0e77c8f6 Mon Sep 17 00:00:00 2001 From: Milos Kozak Date: Mon, 30 Mar 2020 09:40:04 +0200 Subject: [PATCH] Logging cleanup --- .../nightscout/androidaps/RealPumpTest.kt | 6 +- .../info/nightscout/androidaps/logging/L.kt | 86 ++----------------- .../nightscout/androidaps/logging/LTag.kt | 30 +++++++ .../plugins/aps/loop/DeviceStatus.java | 2 +- .../plugins/aps/loop/LoopPlugin.java | 3 +- .../openAPSMA/DetermineBasalAdapterMAJS.java | 3 +- .../iob/iobCobCalculator/AutosensResult.java | 7 +- .../iobCobCalculator/IobCobOref1Thread.java | 20 ++--- .../iob/iobCobCalculator/IobCobThread.java | 21 ++--- 9 files changed, 60 insertions(+), 118 deletions(-) create mode 100644 app/src/main/java/info/nightscout/androidaps/logging/LTag.kt diff --git a/app/src/androidTest/java/info/nightscout/androidaps/RealPumpTest.kt b/app/src/androidTest/java/info/nightscout/androidaps/RealPumpTest.kt index c188d59963..a327989975 100644 --- a/app/src/androidTest/java/info/nightscout/androidaps/RealPumpTest.kt +++ b/app/src/androidTest/java/info/nightscout/androidaps/RealPumpTest.kt @@ -37,8 +37,6 @@ import javax.inject.Inject @RunWith(AndroidJUnit4::class) class RealPumpTest { - private val log = LoggerFactory.getLogger(L.CORE) - companion object { const val R_PASSWORD = 1234 const val R_SERIAL = "PBB00013LR_P" @@ -120,12 +118,12 @@ class RealPumpTest { preparePlugins() while (!pump.isInitialized) { - log.debug("Waiting for initialization") + //log.debug("Waiting for initialization") SystemClock.sleep(1000) } while (true) { - log.debug("Tick") + //log.debug("Tick") SystemClock.sleep(1000) } } diff --git a/app/src/main/java/info/nightscout/androidaps/logging/L.kt b/app/src/main/java/info/nightscout/androidaps/logging/L.kt index ad13015378..4ae358ba02 100644 --- a/app/src/main/java/info/nightscout/androidaps/logging/L.kt +++ b/app/src/main/java/info/nightscout/androidaps/logging/L.kt @@ -7,59 +7,18 @@ object L { private var logElements: MutableList = ArrayList() const val CORE = "CORE" - const val AUTOSENS = "AUTOSENS" - const val AUTOMATION = "AUTOMATION" - const val EVENTS = "EVENTS" - const val GLUCOSE = "GLUCOSE" const val BGSOURCE = "BGSOURCE" - const val OVERVIEW = "OVERVIEW" - const val NOTIFICATION = "NOTIFICATION" const val DATASERVICE = "DATASERVICE" const val DATABASE = "DATABASE" const val DATAFOOD = "DATAFOOD" const val DATATREATMENTS = "DATATREATMENTS" const val NSCLIENT = "NSCLIENT" - const val TIDEPOOL = "TIDEPOOL" - const val CONSTRAINTS = "CONSTRAINTS" const val PUMP = "PUMP" - const val PUMPQUEUE = "PUMPQUEUE" const val PUMPCOMM = "PUMPCOMM" const val PUMPBTCOMM = "PUMPBTCOMM" - const val APS = "APS" - const val PROFILE = "PROFILE" - const val CONFIGBUILDER = "CONFIGBUILDER" - const val UI = "UI" - const val LOCATION = "LOCATION" - const val SMS = "SMS" - const val WEAR = "WEAR" init { - logElements.add(LogElement(APS, defaultValue = true)) - logElements.add(LogElement(AUTOMATION, defaultValue = true)) - logElements.add(LogElement(AUTOSENS, defaultValue = false)) - logElements.add(LogElement(BGSOURCE, defaultValue = true)) - logElements.add(LogElement(GLUCOSE, defaultValue = false)) - logElements.add(LogElement(CONFIGBUILDER, defaultValue = false)) - logElements.add(LogElement(CONSTRAINTS, defaultValue = true)) - logElements.add(LogElement(CORE, defaultValue = true)) - logElements.add(LogElement(DATABASE, defaultValue = true)) - logElements.add(LogElement(DATAFOOD, false)) - logElements.add(LogElement(DATASERVICE, true)) - logElements.add(LogElement(DATATREATMENTS, true)) - logElements.add(LogElement(EVENTS, false, requiresRestart = true)) - logElements.add(LogElement(LOCATION, true)) - logElements.add(LogElement(NOTIFICATION, true)) - logElements.add(LogElement(NSCLIENT, true)) - logElements.add(LogElement(TIDEPOOL, true)) - logElements.add(LogElement(OVERVIEW, true)) - logElements.add(LogElement(PROFILE, true)) - logElements.add(LogElement(PUMP, true)) - logElements.add(LogElement(PUMPBTCOMM, false)) - logElements.add(LogElement(PUMPCOMM, true)) - logElements.add(LogElement(PUMPQUEUE, true)) - logElements.add(LogElement(SMS, true)) - logElements.add(LogElement(UI, true)) - logElements.add(LogElement(WEAR, true)) + LTag.values().forEach { logElements.add(LogElement(it)) } } private fun findByName(name: String): LogElement { @@ -90,16 +49,10 @@ object L { var enabled: Boolean private var requiresRestart = false - internal constructor(name: String, defaultValue: Boolean) { - this.name = name - this.defaultValue = defaultValue - enabled = SP.getBoolean(getSPName(), defaultValue) - } - - internal constructor(name: String, defaultValue: Boolean, requiresRestart: Boolean) { - this.name = name - this.defaultValue = defaultValue - this.requiresRestart = requiresRestart + internal constructor(tag:LTag) { + this.name = tag.tag + this.defaultValue = tag.defaultValue + this.requiresRestart = tag.requiresRestart enabled = SP.getBoolean(getSPName(), defaultValue) } @@ -120,33 +73,4 @@ object L { enable(defaultValue) } } -} - -enum class LTag(val tag: String) { - CORE("CORE"), - AUTOSENS("AUTOSENS"), - AUTOMATION("AUTOMATION"), - EVENTS("EVENTS"), - GLUCOSE("GLUCOSE"), - BGSOURCE("BGSOURCE"), - OVERVIEW("OVERVIEW"), - NOTIFICATION("NOTIFICATION"), - DATASERVICE("DATASERVICE"), - DATABASE("DATABASE"), - DATAFOOD("DATAFOOD"), - DATATREATMENTS("DATATREATMENTS"), - NSCLIENT("NSCLIENT"), - TIDEPOOL("TIDEPOOL"), - CONSTRAINTS("CONSTRAINTS"), - PUMP("PUMP"), - PUMPQUEUE("PUMPQUEUE"), - PUMPCOMM("PUMPCOMM"), - PUMPBTCOMM("PUMPBTCOMM"), - APS("APS"), - PROFILE("PROFILE"), - CONFIGBUILDER("CONFIGBUILDER"), - UI("UI"), - LOCATION("LOCATION"), - WEAR("WEAR"), - SMS("SMS"), } \ No newline at end of file diff --git a/app/src/main/java/info/nightscout/androidaps/logging/LTag.kt b/app/src/main/java/info/nightscout/androidaps/logging/LTag.kt new file mode 100644 index 0000000000..775a789eb9 --- /dev/null +++ b/app/src/main/java/info/nightscout/androidaps/logging/LTag.kt @@ -0,0 +1,30 @@ +package info.nightscout.androidaps.logging + +enum class LTag(val tag: String, val defaultValue : Boolean = false, val requiresRestart: Boolean = false) { + CORE("CORE", defaultValue = false), + APS("APS", defaultValue = false), + AUTOSENS("AUTOSENS"), + AUTOMATION("AUTOMATION", defaultValue = false), + BGSOURCE("BGSOURCE", defaultValue = false), + CONFIGBUILDER("CONFIGBUILDER"), + CONSTRAINTS("CONSTRAINTS", defaultValue = false), + DATABASE("DATABASE", defaultValue = false), + DATAFOOD("DATAFOOD"), + DATASERVICE("DATASERVICE", defaultValue = false), + DATATREATMENTS("DATATREATMENTS", defaultValue = false), + EVENTS("EVENTS", defaultValue = false, requiresRestart = true), + GLUCOSE("GLUCOSE"), + LOCATION("LOCATION", defaultValue = false), + NOTIFICATION("NOTIFICATION", defaultValue = false), + NSCLIENT("NSCLIENT", defaultValue = false), + OVERVIEW("OVERVIEW", defaultValue = false), + PUMP("PUMP", defaultValue = false), + PUMPBTCOMM("PUMPBTCOMM"), + PUMPCOMM("PUMPCOMM", defaultValue = false), + PUMPQUEUE("PUMPQUEUE", defaultValue = false), + PROFILE("PROFILE", defaultValue = false), + SMS("SMS", defaultValue = false), + TIDEPOOL("TIDEPOOL"), + UI("UI", defaultValue = false), + WEAR("WEAR") +} \ No newline at end of file diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/aps/loop/DeviceStatus.java b/app/src/main/java/info/nightscout/androidaps/plugins/aps/loop/DeviceStatus.java index 5222926a9e..42f25cce8f 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/aps/loop/DeviceStatus.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/aps/loop/DeviceStatus.java @@ -366,7 +366,7 @@ import info.nightscout.androidaps.logging.StacktraceLoggerWrapper; */ public class DeviceStatus { - private static Logger log = StacktraceLoggerWrapper.getLogger(L.APS); + private static Logger log = StacktraceLoggerWrapper.getLogger(L.NSCLIENT); public String device = null; public JSONObject pump = null; diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/aps/loop/LoopPlugin.java b/app/src/main/java/info/nightscout/androidaps/plugins/aps/loop/LoopPlugin.java index 4493d51275..79c3f5cd33 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/aps/loop/LoopPlugin.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/aps/loop/LoopPlugin.java @@ -334,8 +334,7 @@ public class LoopPlugin extends PluginBase { Profile profile = profileFunction.getProfile(); if (profile == null || !profileFunction.isProfileValid("Loop")) { - if (L.isEnabled(L.APS)) - getAapsLogger().debug(LTag.APS, resourceHelper.gs(R.string.noprofileselected)); + getAapsLogger().debug(LTag.APS, resourceHelper.gs(R.string.noprofileselected)); rxBus.send(new EventLoopSetLastRunGui(resourceHelper.gs(R.string.noprofileselected))); return; } diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/aps/openAPSMA/DetermineBasalAdapterMAJS.java b/app/src/main/java/info/nightscout/androidaps/plugins/aps/openAPSMA/DetermineBasalAdapterMAJS.java index cc32ba807b..c7733d4eb7 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/aps/openAPSMA/DetermineBasalAdapterMAJS.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/aps/openAPSMA/DetermineBasalAdapterMAJS.java @@ -109,8 +109,7 @@ public class DetermineBasalAdapterMAJS { // Parse the jsResult object to a JSON-String String result = NativeJSON.stringify(rhino, scope, jsResult, null, null).toString(); - if (L.isEnabled(L.APS)) - aapsLogger.debug(LTag.APS, "Result: " + result); + aapsLogger.debug(LTag.APS, "Result: " + result); try { determineBasalResultMA = new DetermineBasalResultMA(injector, jsResult, new JSONObject(result)); } catch (JSONException e) { diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/iob/iobCobCalculator/AutosensResult.java b/app/src/main/java/info/nightscout/androidaps/plugins/iob/iobCobCalculator/AutosensResult.java index 3f478cc478..e1debef726 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/iob/iobCobCalculator/AutosensResult.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/iob/iobCobCalculator/AutosensResult.java @@ -2,17 +2,14 @@ package info.nightscout.androidaps.plugins.iob.iobCobCalculator; import org.json.JSONException; import org.json.JSONObject; -import org.slf4j.Logger; import org.slf4j.LoggerFactory; -import info.nightscout.androidaps.logging.L; -import info.nightscout.androidaps.logging.StacktraceLoggerWrapper; +import info.nightscout.androidaps.logging.LTag; /** * Created by mike on 06.01.2017. */ public class AutosensResult { - private static Logger log = StacktraceLoggerWrapper.getLogger(L.AUTOSENS); //default values to show when autosens algorithm is not called public double ratio = 1d; @@ -30,7 +27,7 @@ public class AutosensResult { ret.put("sensResult", sensResult); ret.put("ratio", ratio); } catch (JSONException e) { - log.error("Unhandled exception", e); + LoggerFactory.getLogger(LTag.CORE.getTag()).error("Unhandled exception", e); } return ret; } diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/iob/iobCobCalculator/IobCobOref1Thread.java b/app/src/main/java/info/nightscout/androidaps/plugins/iob/iobCobCalculator/IobCobOref1Thread.java index c3d6685538..505b9a799f 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/iob/iobCobCalculator/IobCobOref1Thread.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/iob/iobCobCalculator/IobCobOref1Thread.java @@ -196,17 +196,15 @@ public class IobCobOref1Thread extends Thread { try { for (; past < 12; past++) { AutosensData ad = autosensDataTable.valueAt(initialIndex + past); - if (L.isEnabled(L.AUTOSENS)) { - aapsLogger.debug(">>>>> past=" + past + " ad=" + (ad != null ? ad.toString() : null)); - if (ad == null) { - aapsLogger.debug(autosensDataTable.toString()); - aapsLogger.debug(bucketed_data.toString()); - aapsLogger.debug(iobCobCalculatorPlugin.getBgReadings().toString()); - Notification notification = new Notification(Notification.SENDLOGFILES, resourceHelper.gs(R.string.sendlogfiles), Notification.LOW); - rxBus.send(new EventNewNotification(notification)); - sp.putBoolean("log_AUTOSENS", true); - break; - } + aapsLogger.debug(LTag.AUTOSENS, ">>>>> past=" + past + " ad=" + (ad != null ? ad.toString() : null)); + if (ad == null) { + aapsLogger.debug(LTag.AUTOSENS, autosensDataTable.toString()); + aapsLogger.debug(LTag.AUTOSENS, bucketed_data.toString()); + aapsLogger.debug(LTag.AUTOSENS, iobCobCalculatorPlugin.getBgReadings().toString()); + Notification notification = new Notification(Notification.SENDLOGFILES, resourceHelper.gs(R.string.sendlogfiles), Notification.LOW); + rxBus.send(new EventNewNotification(notification)); + sp.putBoolean("log_AUTOSENS", true); + break; } // let it here crash on NPE to get more data as i cannot reproduce this bug double deviationSlope = (ad.avgDeviation - avgDeviation) / (ad.time - bgTime) * 1000 * 60 * 5; diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/iob/iobCobCalculator/IobCobThread.java b/app/src/main/java/info/nightscout/androidaps/plugins/iob/iobCobCalculator/IobCobThread.java index 950add8cbe..6e30d776b2 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/iob/iobCobCalculator/IobCobThread.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/iob/iobCobCalculator/IobCobThread.java @@ -21,7 +21,6 @@ import info.nightscout.androidaps.events.Event; import info.nightscout.androidaps.interfaces.ActivePluginProvider; import info.nightscout.androidaps.interfaces.PluginType; import info.nightscout.androidaps.logging.AAPSLogger; -import info.nightscout.androidaps.logging.L; import info.nightscout.androidaps.logging.LTag; import info.nightscout.androidaps.plugins.aps.openAPSSMB.SMBDefaults; import info.nightscout.androidaps.plugins.bus.RxBusWrapper; @@ -193,17 +192,15 @@ public class IobCobThread extends Thread { try { for (; past < 12; past++) { AutosensData ad = autosensDataTable.valueAt(initialIndex + past); - if (L.isEnabled(L.AUTOSENS)) { - aapsLogger.debug(">>>>> past=" + past + " ad=" + (ad != null ? ad.toString() : null)); - if (ad == null) { - aapsLogger.debug(autosensDataTable.toString()); - aapsLogger.debug(bucketed_data.toString()); - aapsLogger.debug(iobCobCalculatorPlugin.getBgReadings().toString()); - Notification notification = new Notification(Notification.SENDLOGFILES, resourceHelper.gs(R.string.sendlogfiles), Notification.LOW); - rxBus.send(new EventNewNotification(notification)); - sp.putBoolean("log_AUTOSENS", true); - break; - } + aapsLogger.debug(LTag.AUTOSENS, ">>>>> past=" + past + " ad=" + (ad != null ? ad.toString() : null)); + if (ad == null) { + aapsLogger.debug(LTag.AUTOSENS, autosensDataTable.toString()); + aapsLogger.debug(LTag.AUTOSENS, bucketed_data.toString()); + aapsLogger.debug(LTag.AUTOSENS, iobCobCalculatorPlugin.getBgReadings().toString()); + Notification notification = new Notification(Notification.SENDLOGFILES, resourceHelper.gs(R.string.sendlogfiles), Notification.LOW); + rxBus.send(new EventNewNotification(notification)); + sp.putBoolean("log_AUTOSENS", true); + break; } // let it here crash on NPE to get more data as i cannot reproduce this bug double deviationSlope = (ad.avgDeviation - avgDeviation) / (ad.time - bgTime) * 1000 * 60 * 5;