From 0563420996be0d4d88e7d135e06b6c9ade043e70 Mon Sep 17 00:00:00 2001 From: Milos Kozak Date: Tue, 11 Sep 2018 14:56:42 +0200 Subject: [PATCH] Constraints logging --- .../androidaps/interfaces/Constraint.java | 25 +++++++++++++++---- .../info/nightscout/androidaps/logging/L.java | 4 +-- .../ObjectivesPlugin.java | 6 ++--- 3 files changed, 25 insertions(+), 10 deletions(-) diff --git a/app/src/main/java/info/nightscout/androidaps/interfaces/Constraint.java b/app/src/main/java/info/nightscout/androidaps/interfaces/Constraint.java index 6a47a892db..f35036c539 100644 --- a/app/src/main/java/info/nightscout/androidaps/interfaces/Constraint.java +++ b/app/src/main/java/info/nightscout/androidaps/interfaces/Constraint.java @@ -13,7 +13,7 @@ import info.nightscout.androidaps.logging.L; */ public class Constraint { - private static Logger log = LoggerFactory.getLogger(L.APS); + private static Logger log = LoggerFactory.getLogger(L.CONSTRAINTS); T value; T originalValue; @@ -37,10 +37,14 @@ public class Constraint { public Constraint set(T value) { this.value = value; this.originalValue = value; + if (L.isEnabled(L.CONSTRAINTS)) + log.debug("Setting value " + value); return this; } public Constraint set(T value, String reason, Object from) { + if (L.isEnabled(L.CONSTRAINTS)) + log.debug("Setting value " + this.value + " -> " + value + " (" + reason + ")[" + from + "]"); this.value = value; addReason(reason, from); addMostLimingReason(reason, from); @@ -49,6 +53,8 @@ public class Constraint { public Constraint setIfDifferent(T value, String reason, Object from) { if (!this.value.equals(value)) { + if (L.isEnabled(L.CONSTRAINTS)) + log.debug("Setting because of different value " + this.value + " -> " + value + " (" + reason + ")[" + from + "]"); this.value = value; addReason(reason, from); addMostLimingReason(reason, from); @@ -58,6 +64,8 @@ public class Constraint { public Constraint setIfSmaller(T value, String reason, Object from) { if (value.compareTo(this.value) < 0) { + if (L.isEnabled(L.CONSTRAINTS)) + log.debug("Setting because of smaller value " + this.value + " -> " + value + " (" + reason + ")[" + from + "]"); this.value = value; mostLimiting.clear(); addMostLimingReason(reason, from); @@ -70,6 +78,8 @@ public class Constraint { public Constraint setIfGreater(T value, String reason, Object from) { if (value.compareTo(this.value) > 0) { + if (L.isEnabled(L.CONSTRAINTS)) + log.debug("Setting because of greater value " + this.value + " -> " + value + " (" + reason + ")[" + from + "]"); this.value = value; mostLimiting.clear(); addMostLimingReason(reason, from); @@ -80,13 +90,17 @@ public class Constraint { return this; } + private String translateFrom(Object from) { + return from.getClass().getSimpleName().replace("Plugin", ""); + } + public Constraint addReason(String reason, Object from) { - reasons.add(from.getClass().getSimpleName().replace("Plugin", "") + ": " + reason); + reasons.add(translateFrom(from) + ": " + reason); return this; } public Constraint addMostLimingReason(String reason, Object from) { - mostLimiting.add(from.getClass().getSimpleName().replace("Plugin", "") + ": " + reason); + mostLimiting.add(translateFrom(from) + ": " + reason); return this; } @@ -97,7 +111,7 @@ public class Constraint { if (count++ != 0) sb.append("\n"); sb.append(r); } - if (L.isEnabled(L.APS)) + if (L.isEnabled(L.CONSTRAINTS)) log.debug("Limiting origial value: " + originalValue + " to " + value + ". Reason: " + sb.toString()); return sb.toString(); } @@ -113,7 +127,8 @@ public class Constraint { if (count++ != 0) sb.append("\n"); sb.append(r); } - log.debug("Limiting origial value: " + originalValue + " to " + value + ". Reason: " + sb.toString()); + if (L.isEnabled(L.CONSTRAINTS)) + log.debug("Limiting origial value: " + originalValue + " to " + value + ". Reason: " + sb.toString()); return sb.toString(); } diff --git a/app/src/main/java/info/nightscout/androidaps/logging/L.java b/app/src/main/java/info/nightscout/androidaps/logging/L.java index 8b35eb8af6..c44d2516c2 100644 --- a/app/src/main/java/info/nightscout/androidaps/logging/L.java +++ b/app/src/main/java/info/nightscout/androidaps/logging/L.java @@ -86,7 +86,7 @@ public class L { public static final String DATAFOOD = "DATAFOOD"; public static final String DATATREATMENTS = "DATATREATMENTS"; public static final String NSCLIENT = "NSCLIENT"; - public static final String OBJECTIVES = "OBJECTIVES"; + public static final String CONSTRAINTS = "CONSTRAINTS"; public static final String PUMP = "PUMP"; public static final String PUMPQUEUE = "PUMPQUEUE"; public static final String PUMPCOMM = "PUMPCOMM"; @@ -102,6 +102,7 @@ public class L { logElements.add(new LogElement(AUTOSENS, true)); logElements.add(new LogElement(BGSOURCE, true)); logElements.add(new LogElement(CONFIGBUILDER, true)); + logElements.add(new LogElement(CONSTRAINTS, true)); logElements.add(new LogElement(CORE, true)); logElements.add(new LogElement(DATABASE, true)); logElements.add(new LogElement(DATAFOOD, true)); @@ -110,7 +111,6 @@ public class L { logElements.add(new LogElement(EVENTS, false, true)); logElements.add(new LogElement(NOTIFICATION, true)); logElements.add(new LogElement(NSCLIENT, true)); - logElements.add(new LogElement(OBJECTIVES, false)); logElements.add(new LogElement(OVERVIEW, true)); logElements.add(new LogElement(PROFILE, true)); logElements.add(new LogElement(PUMP, true)); diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/ConstraintsObjectives/ObjectivesPlugin.java b/app/src/main/java/info/nightscout/androidaps/plugins/ConstraintsObjectives/ObjectivesPlugin.java index e675adee69..aae2d1f029 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/ConstraintsObjectives/ObjectivesPlugin.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/ConstraintsObjectives/ObjectivesPlugin.java @@ -33,7 +33,7 @@ import info.nightscout.utils.SP; * Created by mike on 05.08.2016. */ public class ObjectivesPlugin extends PluginBase implements ConstraintsInterface { - private static Logger log = LoggerFactory.getLogger(L.OBJECTIVES); + private static Logger log = LoggerFactory.getLogger(L.CONSTRAINTS); private static ObjectivesPlugin objectivesPlugin; @@ -95,7 +95,7 @@ public class ObjectivesPlugin extends PluginBase implements ConstraintsInterface SP.putBoolean("Objectives" + "bgIsAvailableInNS", bgIsAvailableInNS); SP.putBoolean("Objectives" + "pumpStatusIsAvailableInNS", pumpStatusIsAvailableInNS); SP.putString("Objectives" + "manualEnacts", Integer.toString(manualEnacts)); - if (L.isEnabled(L.OBJECTIVES)) + if (L.isEnabled(L.CONSTRAINTS)) log.debug("Objectives stored"); MainApp.bus().post(new EventObjectivesSaved()); } @@ -108,7 +108,7 @@ public class ObjectivesPlugin extends PluginBase implements ConstraintsInterface } catch (Exception e) { log.error("Unhandled exception", e); } - if (L.isEnabled(L.OBJECTIVES)) + if (L.isEnabled(L.CONSTRAINTS)) log.debug("Objectives loaded"); }