AndroidAPS/app/src/main/java/info/nightscout/androidaps/logging/L.java

126 lines
4.3 KiB
Java
Raw Normal View History

2018-07-29 15:37:28 +02:00
package info.nightscout.androidaps.logging;
import java.util.ArrayList;
import java.util.List;
2019-02-26 20:38:27 +01:00
import info.nightscout.androidaps.utils.SP;
2018-07-29 15:37:28 +02:00
public class L {
public static class LogElement {
2018-08-02 15:19:13 +02:00
public String name;
2018-07-29 15:37:28 +02:00
boolean defaultValue;
2018-08-02 15:19:13 +02:00
public boolean enabled;
2018-07-29 15:37:28 +02:00
boolean requiresRestart = false;
LogElement(String name, boolean defaultValue) {
this.name = name;
this.defaultValue = defaultValue;
enabled = SP.getBoolean(getSPName(), defaultValue);
}
2018-07-30 17:04:43 +02:00
LogElement(String name, boolean defaultValue, boolean requiresRestart) {
2018-07-29 15:37:28 +02:00
this.name = name;
this.defaultValue = defaultValue;
this.requiresRestart = requiresRestart;
enabled = SP.getBoolean(getSPName(), defaultValue);
}
LogElement(boolean defaultValue) {
this.name = "NONEXISTING";
this.defaultValue = defaultValue;
enabled = defaultValue;
}
private String getSPName() {
return "log_" + name;
}
2018-07-30 17:04:43 +02:00
public void setEnabled(boolean enabled) {
this.enabled = enabled;
SP.putBoolean(getSPName(), enabled);
}
void resetToDefault() {
setEnabled(defaultValue);
}
2018-07-29 15:37:28 +02:00
}
private static List<LogElement> logElements;
static {
initialize();
}
private static LogElement findByName(String name) {
2018-07-30 17:04:43 +02:00
for (LogElement element : logElements) {
2018-07-29 15:37:28 +02:00
if (element.name.equals(name))
return element;
}
return new LogElement(false);
}
public static boolean isEnabled(String name) {
return findByName(name).enabled;
}
2018-07-30 17:04:43 +02:00
public static List<LogElement> getLogElements() {
return logElements;
}
public static void resetToDefaults() {
for (LogElement element : logElements) {
element.resetToDefault();
}
}
2018-07-29 15:37:28 +02:00
public static final String CORE = "CORE";
public static final String AUTOSENS = "AUTOSENS";
public static final String EVENTS = "EVENTS";
public static final String BGSOURCE = "BGSOURCE";
public static final String OVERVIEW = "OVERVIEW";
public static final String NOTIFICATION = "NOTIFICATION";
public static final String DATASERVICE = "DATASERVICE";
public static final String DATABASE = "DATABASE";
public static final String DATAFOOD = "DATAFOOD";
public static final String DATATREATMENTS = "DATATREATMENTS";
public static final String NSCLIENT = "NSCLIENT";
2018-09-11 14:56:42 +02:00
public static final String CONSTRAINTS = "CONSTRAINTS";
2018-07-29 15:37:28 +02:00
public static final String PUMP = "PUMP";
public static final String PUMPQUEUE = "PUMPQUEUE";
public static final String PUMPCOMM = "PUMPCOMM";
public static final String PUMPBTCOMM = "PUMPBTCOMM";
public static final String APS = "APS";
public static final String PROFILE = "PROFILE";
2018-07-30 15:46:20 +02:00
public static final String CONFIGBUILDER = "CONFIGBUILDER";
public static final String UI = "UI";
2018-10-13 16:50:47 +02:00
public static final String SMS = "SMS";
2018-07-29 15:37:28 +02:00
private static void initialize() {
logElements = new ArrayList<>();
2018-07-30 17:04:43 +02:00
logElements.add(new LogElement(APS, true));
2018-11-02 23:24:57 +01:00
logElements.add(new LogElement(AUTOSENS, false));
2018-07-29 15:37:28 +02:00
logElements.add(new LogElement(BGSOURCE, true));
2018-11-02 23:24:57 +01:00
logElements.add(new LogElement(CONFIGBUILDER, false));
2018-09-11 14:56:42 +02:00
logElements.add(new LogElement(CONSTRAINTS, true));
2018-07-30 17:04:43 +02:00
logElements.add(new LogElement(CORE, true));
2018-07-29 15:37:28 +02:00
logElements.add(new LogElement(DATABASE, true));
2018-11-02 23:24:57 +01:00
logElements.add(new LogElement(DATAFOOD, false));
2018-07-30 17:04:43 +02:00
logElements.add(new LogElement(DATASERVICE, true));
2018-07-29 15:37:28 +02:00
logElements.add(new LogElement(DATATREATMENTS, true));
2018-07-30 17:04:43 +02:00
logElements.add(new LogElement(EVENTS, false, true));
logElements.add(new LogElement(NOTIFICATION, true));
2018-07-29 15:37:28 +02:00
logElements.add(new LogElement(NSCLIENT, true));
2018-07-30 17:04:43 +02:00
logElements.add(new LogElement(OVERVIEW, true));
logElements.add(new LogElement(PROFILE, true));
2018-07-29 15:37:28 +02:00
logElements.add(new LogElement(PUMP, true));
logElements.add(new LogElement(PUMPBTCOMM, false));
2018-07-30 17:04:43 +02:00
logElements.add(new LogElement(PUMPCOMM, true));
logElements.add(new LogElement(PUMPQUEUE, true));
2018-10-13 16:50:47 +02:00
logElements.add(new LogElement(SMS, true));
logElements.add(new LogElement(UI, true));
2018-07-29 15:37:28 +02:00
}
}