Logging cleanup

This commit is contained in:
Milos Kozak 2020-03-30 09:40:04 +02:00
parent ddd9110912
commit 71be72cd03
9 changed files with 60 additions and 118 deletions

View file

@ -37,8 +37,6 @@ import javax.inject.Inject
@RunWith(AndroidJUnit4::class) @RunWith(AndroidJUnit4::class)
class RealPumpTest { class RealPumpTest {
private val log = LoggerFactory.getLogger(L.CORE)
companion object { companion object {
const val R_PASSWORD = 1234 const val R_PASSWORD = 1234
const val R_SERIAL = "PBB00013LR_P" const val R_SERIAL = "PBB00013LR_P"
@ -120,12 +118,12 @@ class RealPumpTest {
preparePlugins() preparePlugins()
while (!pump.isInitialized) { while (!pump.isInitialized) {
log.debug("Waiting for initialization") //log.debug("Waiting for initialization")
SystemClock.sleep(1000) SystemClock.sleep(1000)
} }
while (true) { while (true) {
log.debug("Tick") //log.debug("Tick")
SystemClock.sleep(1000) SystemClock.sleep(1000)
} }
} }

View file

@ -7,59 +7,18 @@ object L {
private var logElements: MutableList<LogElement> = ArrayList() private var logElements: MutableList<LogElement> = ArrayList()
const val CORE = "CORE" 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 BGSOURCE = "BGSOURCE"
const val OVERVIEW = "OVERVIEW"
const val NOTIFICATION = "NOTIFICATION"
const val DATASERVICE = "DATASERVICE" const val DATASERVICE = "DATASERVICE"
const val DATABASE = "DATABASE" const val DATABASE = "DATABASE"
const val DATAFOOD = "DATAFOOD" const val DATAFOOD = "DATAFOOD"
const val DATATREATMENTS = "DATATREATMENTS" const val DATATREATMENTS = "DATATREATMENTS"
const val NSCLIENT = "NSCLIENT" const val NSCLIENT = "NSCLIENT"
const val TIDEPOOL = "TIDEPOOL"
const val CONSTRAINTS = "CONSTRAINTS"
const val PUMP = "PUMP" const val PUMP = "PUMP"
const val PUMPQUEUE = "PUMPQUEUE"
const val PUMPCOMM = "PUMPCOMM" const val PUMPCOMM = "PUMPCOMM"
const val PUMPBTCOMM = "PUMPBTCOMM" 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 { init {
logElements.add(LogElement(APS, defaultValue = true)) LTag.values().forEach { logElements.add(LogElement(it)) }
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))
} }
private fun findByName(name: String): LogElement { private fun findByName(name: String): LogElement {
@ -90,16 +49,10 @@ object L {
var enabled: Boolean var enabled: Boolean
private var requiresRestart = false private var requiresRestart = false
internal constructor(name: String, defaultValue: Boolean) { internal constructor(tag:LTag) {
this.name = name this.name = tag.tag
this.defaultValue = defaultValue this.defaultValue = tag.defaultValue
enabled = SP.getBoolean(getSPName(), defaultValue) this.requiresRestart = tag.requiresRestart
}
internal constructor(name: String, defaultValue: Boolean, requiresRestart: Boolean) {
this.name = name
this.defaultValue = defaultValue
this.requiresRestart = requiresRestart
enabled = SP.getBoolean(getSPName(), defaultValue) enabled = SP.getBoolean(getSPName(), defaultValue)
} }
@ -120,33 +73,4 @@ object L {
enable(defaultValue) 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"),
} }

View file

@ -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")
}

View file

@ -366,7 +366,7 @@ import info.nightscout.androidaps.logging.StacktraceLoggerWrapper;
*/ */
public class DeviceStatus { public class DeviceStatus {
private static Logger log = StacktraceLoggerWrapper.getLogger(L.APS); private static Logger log = StacktraceLoggerWrapper.getLogger(L.NSCLIENT);
public String device = null; public String device = null;
public JSONObject pump = null; public JSONObject pump = null;

View file

@ -334,8 +334,7 @@ public class LoopPlugin extends PluginBase {
Profile profile = profileFunction.getProfile(); Profile profile = profileFunction.getProfile();
if (profile == null || !profileFunction.isProfileValid("Loop")) { 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))); rxBus.send(new EventLoopSetLastRunGui(resourceHelper.gs(R.string.noprofileselected)));
return; return;
} }

View file

@ -109,8 +109,7 @@ public class DetermineBasalAdapterMAJS {
// Parse the jsResult object to a JSON-String // Parse the jsResult object to a JSON-String
String result = NativeJSON.stringify(rhino, scope, jsResult, null, null).toString(); 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 { try {
determineBasalResultMA = new DetermineBasalResultMA(injector, jsResult, new JSONObject(result)); determineBasalResultMA = new DetermineBasalResultMA(injector, jsResult, new JSONObject(result));
} catch (JSONException e) { } catch (JSONException e) {

View file

@ -2,17 +2,14 @@ package info.nightscout.androidaps.plugins.iob.iobCobCalculator;
import org.json.JSONException; import org.json.JSONException;
import org.json.JSONObject; import org.json.JSONObject;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
import info.nightscout.androidaps.logging.L; import info.nightscout.androidaps.logging.LTag;
import info.nightscout.androidaps.logging.StacktraceLoggerWrapper;
/** /**
* Created by mike on 06.01.2017. * Created by mike on 06.01.2017.
*/ */
public class AutosensResult { public class AutosensResult {
private static Logger log = StacktraceLoggerWrapper.getLogger(L.AUTOSENS);
//default values to show when autosens algorithm is not called //default values to show when autosens algorithm is not called
public double ratio = 1d; public double ratio = 1d;
@ -30,7 +27,7 @@ public class AutosensResult {
ret.put("sensResult", sensResult); ret.put("sensResult", sensResult);
ret.put("ratio", ratio); ret.put("ratio", ratio);
} catch (JSONException e) { } catch (JSONException e) {
log.error("Unhandled exception", e); LoggerFactory.getLogger(LTag.CORE.getTag()).error("Unhandled exception", e);
} }
return ret; return ret;
} }

View file

@ -196,17 +196,15 @@ public class IobCobOref1Thread extends Thread {
try { try {
for (; past < 12; past++) { for (; past < 12; past++) {
AutosensData ad = autosensDataTable.valueAt(initialIndex + past); AutosensData ad = autosensDataTable.valueAt(initialIndex + past);
if (L.isEnabled(L.AUTOSENS)) { aapsLogger.debug(LTag.AUTOSENS, ">>>>> past=" + past + " ad=" + (ad != null ? ad.toString() : null));
aapsLogger.debug(">>>>> past=" + past + " ad=" + (ad != null ? ad.toString() : null)); if (ad == null) {
if (ad == null) { aapsLogger.debug(LTag.AUTOSENS, autosensDataTable.toString());
aapsLogger.debug(autosensDataTable.toString()); aapsLogger.debug(LTag.AUTOSENS, bucketed_data.toString());
aapsLogger.debug(bucketed_data.toString()); aapsLogger.debug(LTag.AUTOSENS, iobCobCalculatorPlugin.getBgReadings().toString());
aapsLogger.debug(iobCobCalculatorPlugin.getBgReadings().toString()); Notification notification = new Notification(Notification.SENDLOGFILES, resourceHelper.gs(R.string.sendlogfiles), Notification.LOW);
Notification notification = new Notification(Notification.SENDLOGFILES, resourceHelper.gs(R.string.sendlogfiles), Notification.LOW); rxBus.send(new EventNewNotification(notification));
rxBus.send(new EventNewNotification(notification)); sp.putBoolean("log_AUTOSENS", true);
sp.putBoolean("log_AUTOSENS", true); break;
break;
}
} }
// let it here crash on NPE to get more data as i cannot reproduce this bug // 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; double deviationSlope = (ad.avgDeviation - avgDeviation) / (ad.time - bgTime) * 1000 * 60 * 5;

View file

@ -21,7 +21,6 @@ import info.nightscout.androidaps.events.Event;
import info.nightscout.androidaps.interfaces.ActivePluginProvider; import info.nightscout.androidaps.interfaces.ActivePluginProvider;
import info.nightscout.androidaps.interfaces.PluginType; import info.nightscout.androidaps.interfaces.PluginType;
import info.nightscout.androidaps.logging.AAPSLogger; import info.nightscout.androidaps.logging.AAPSLogger;
import info.nightscout.androidaps.logging.L;
import info.nightscout.androidaps.logging.LTag; import info.nightscout.androidaps.logging.LTag;
import info.nightscout.androidaps.plugins.aps.openAPSSMB.SMBDefaults; import info.nightscout.androidaps.plugins.aps.openAPSSMB.SMBDefaults;
import info.nightscout.androidaps.plugins.bus.RxBusWrapper; import info.nightscout.androidaps.plugins.bus.RxBusWrapper;
@ -193,17 +192,15 @@ public class IobCobThread extends Thread {
try { try {
for (; past < 12; past++) { for (; past < 12; past++) {
AutosensData ad = autosensDataTable.valueAt(initialIndex + past); AutosensData ad = autosensDataTable.valueAt(initialIndex + past);
if (L.isEnabled(L.AUTOSENS)) { aapsLogger.debug(LTag.AUTOSENS, ">>>>> past=" + past + " ad=" + (ad != null ? ad.toString() : null));
aapsLogger.debug(">>>>> past=" + past + " ad=" + (ad != null ? ad.toString() : null)); if (ad == null) {
if (ad == null) { aapsLogger.debug(LTag.AUTOSENS, autosensDataTable.toString());
aapsLogger.debug(autosensDataTable.toString()); aapsLogger.debug(LTag.AUTOSENS, bucketed_data.toString());
aapsLogger.debug(bucketed_data.toString()); aapsLogger.debug(LTag.AUTOSENS, iobCobCalculatorPlugin.getBgReadings().toString());
aapsLogger.debug(iobCobCalculatorPlugin.getBgReadings().toString()); Notification notification = new Notification(Notification.SENDLOGFILES, resourceHelper.gs(R.string.sendlogfiles), Notification.LOW);
Notification notification = new Notification(Notification.SENDLOGFILES, resourceHelper.gs(R.string.sendlogfiles), Notification.LOW); rxBus.send(new EventNewNotification(notification));
rxBus.send(new EventNewNotification(notification)); sp.putBoolean("log_AUTOSENS", true);
sp.putBoolean("log_AUTOSENS", true); break;
break;
}
} }
// let it here crash on NPE to get more data as i cannot reproduce this bug // 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; double deviationSlope = (ad.avgDeviation - avgDeviation) / (ad.time - bgTime) * 1000 * 60 * 5;