diff --git a/app/src/main/java/info/nightscout/androidaps/MainActivity.java b/app/src/main/java/info/nightscout/androidaps/MainActivity.java index d6cf1bcd28..419004a64d 100644 --- a/app/src/main/java/info/nightscout/androidaps/MainActivity.java +++ b/app/src/main/java/info/nightscout/androidaps/MainActivity.java @@ -34,9 +34,6 @@ import com.google.android.material.tabs.TabLayout; import com.joanzapata.iconify.Iconify; import com.joanzapata.iconify.fonts.FontAwesomeModule; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - import javax.inject.Inject; import dagger.android.AndroidInjection; @@ -53,7 +50,8 @@ import info.nightscout.androidaps.events.EventPreferenceChange; import info.nightscout.androidaps.events.EventRebuildTabs; import info.nightscout.androidaps.interfaces.PluginBase; import info.nightscout.androidaps.interfaces.PluginType; -import info.nightscout.androidaps.logging.L; +import info.nightscout.androidaps.logging.AAPSLogger; +import info.nightscout.androidaps.logging.LTag; import info.nightscout.androidaps.plugins.aps.loop.LoopPlugin; import info.nightscout.androidaps.plugins.bus.RxBus; import info.nightscout.androidaps.plugins.constraints.versionChecker.VersionCheckerUtilsKt; @@ -71,7 +69,6 @@ import io.reactivex.android.schedulers.AndroidSchedulers; import io.reactivex.disposables.CompositeDisposable; public class MainActivity extends NoSplashAppCompatActivity implements HasAndroidInjector { - private static Logger log = LoggerFactory.getLogger(L.CORE); @Inject DispatchingAndroidInjector androidInjector; @@ -85,6 +82,9 @@ public class MainActivity extends NoSplashAppCompatActivity implements HasAndroi @Inject SmsCommunicatorPlugin smsCommunicatorPlugin; + @Inject + AAPSLogger aapsLogger; + @Override public void onCreate(Bundle savedInstanceState) { AndroidInjection.inject(this); @@ -327,7 +327,7 @@ public class MainActivity extends NoSplashAppCompatActivity implements HasAndroi ((TextView) alertDialog.findViewById(android.R.id.message)).setMovementMethod(LinkMovementMethod.getInstance()); return true; case R.id.nav_exit: - log.debug("Exiting"); + aapsLogger.debug(LTag.CORE, "Exiting"); RxBus.INSTANCE.send(new EventAppExit()); finish(); System.runFinalization(); diff --git a/app/src/main/java/info/nightscout/androidaps/MainApp.java b/app/src/main/java/info/nightscout/androidaps/MainApp.java index 5ff629fb9a..b39f7b1c5e 100644 --- a/app/src/main/java/info/nightscout/androidaps/MainApp.java +++ b/app/src/main/java/info/nightscout/androidaps/MainApp.java @@ -33,7 +33,9 @@ import info.nightscout.androidaps.dependencyInjection.DaggerAppComponent; import info.nightscout.androidaps.interfaces.PluginBase; import info.nightscout.androidaps.interfaces.PluginType; import info.nightscout.androidaps.interfaces.PumpInterface; +import info.nightscout.androidaps.logging.AAPSLogger; import info.nightscout.androidaps.logging.L; +import info.nightscout.androidaps.logging.LTag; import info.nightscout.androidaps.plugins.aps.loop.LoopPlugin; import info.nightscout.androidaps.plugins.aps.openAPSAMA.OpenAPSAMAPlugin; import info.nightscout.androidaps.plugins.aps.openAPSMA.OpenAPSMAPlugin; @@ -121,12 +123,20 @@ public class MainApp extends DaggerApplication { public static boolean devBranch; public static boolean engineeringMode; - @Inject ConfigBuilderPlugin configBuilderPlugin; + @Inject + AAPSLogger aapsLogger; - @Inject InsulinOrefFreePeakPlugin insulinOrefFreePeakPlugin; - @Inject InsulinOrefRapidActingPlugin insulinOrefRapidActingPlugin; - @Inject InsulinOrefUltraRapidActingPlugin insulinOrefUltraRapidActingPlugin; - @Inject SmsCommunicatorPlugin smsCommunicatorPlugin; + @Inject + ConfigBuilderPlugin configBuilderPlugin; + + @Inject + InsulinOrefFreePeakPlugin insulinOrefFreePeakPlugin; + @Inject + InsulinOrefRapidActingPlugin insulinOrefRapidActingPlugin; + @Inject + InsulinOrefUltraRapidActingPlugin insulinOrefUltraRapidActingPlugin; + @Inject + SmsCommunicatorPlugin smsCommunicatorPlugin; @Override public void onCreate() { @@ -433,8 +443,8 @@ public class MainApp extends DaggerApplication { @Override public void onTerminate() { - if (L.isEnabled(L.CORE)) - log.debug("onTerminate"); + + aapsLogger.debug(LTag.CORE, "onTerminate"); if (timeDateOrTZChangeReceiver != null) unregisterReceiver(timeDateOrTZChangeReceiver); diff --git a/app/src/main/java/info/nightscout/androidaps/dependencyInjection/AppModule.kt b/app/src/main/java/info/nightscout/androidaps/dependencyInjection/AppModule.kt index 9d51eda0a5..faa789adbf 100644 --- a/app/src/main/java/info/nightscout/androidaps/dependencyInjection/AppModule.kt +++ b/app/src/main/java/info/nightscout/androidaps/dependencyInjection/AppModule.kt @@ -6,7 +6,11 @@ import dagger.Binds import dagger.Module import dagger.Provides import dagger.android.ContributesAndroidInjector +import info.nightscout.androidaps.BuildConfig import info.nightscout.androidaps.MainApp +import info.nightscout.androidaps.logging.AAPSLogger +import info.nightscout.androidaps.logging.AAPSLoggerDebug +import info.nightscout.androidaps.logging.AAPSLoggerProduction import info.nightscout.androidaps.plugins.configBuilder.ConstraintChecker import info.nightscout.androidaps.plugins.configBuilder.ProfileFunction import info.nightscout.androidaps.plugins.configBuilder.ProfileFunctionImplementation @@ -46,6 +50,16 @@ class AppModule { return ResourceHelperImplementation(mainApp) } + @Provides + @Singleton + fun provideAAPSLogger(): AAPSLogger { + return if (BuildConfig.DEBUG) { + AAPSLoggerDebug() + } else { + AAPSLoggerProduction() + } + } + @Module interface AppBindings { diff --git a/app/src/main/java/info/nightscout/androidaps/interfaces/ConstraintsInterface.kt.ignore b/app/src/main/java/info/nightscout/androidaps/interfaces/ConstraintsInterface.kt.ignore deleted file mode 100644 index 93af086b7a..0000000000 --- a/app/src/main/java/info/nightscout/androidaps/interfaces/ConstraintsInterface.kt.ignore +++ /dev/null @@ -1,62 +0,0 @@ -package info.nightscout.androidaps.interfaces - -import info.nightscout.androidaps.data.Profile - -interface ConstraintsInterface { - - fun isLoopInvocationAllowed(value: Constraint): Constraint { - return value - } - - fun isClosedLoopAllowed(value: Constraint): Constraint { - return value - } - - fun isAutosensModeEnabled(value: Constraint): Constraint { - return value - } - - fun isAMAModeEnabled(value: Constraint): Constraint { - return value - } - - fun isSMBModeEnabled(value: Constraint): Constraint { - return value - } - - fun isUAMEnabled(value: Constraint): Constraint { - return value - } - - fun isAdvancedFilteringEnabled(value: Constraint): Constraint { - return value - } - - fun isSuperBolusEnabled(value: Constraint): Constraint { - return value - } - - fun applyBasalConstraints(absoluteRate: Constraint, profile: Profile): Constraint { - return absoluteRate - } - - fun applyBasalPercentConstraints(percentRate: Constraint, profile: Profile): Constraint { - return percentRate - } - - fun applyBolusConstraints(insulin: Constraint): Constraint { - return insulin - } - - fun applyExtendedBolusConstraints(insulin: Constraint): Constraint { - return insulin - } - - fun applyCarbsConstraints(carbs: Constraint): Constraint { - return carbs - } - - fun applyMaxIOBConstraints(maxIob: Constraint): Constraint { - return maxIob - } -} \ No newline at end of file diff --git a/app/src/main/java/info/nightscout/androidaps/logging/AAPSLogger.kt b/app/src/main/java/info/nightscout/androidaps/logging/AAPSLogger.kt new file mode 100644 index 0000000000..e3f74fdb10 --- /dev/null +++ b/app/src/main/java/info/nightscout/androidaps/logging/AAPSLogger.kt @@ -0,0 +1,13 @@ +package info.nightscout.androidaps.logging + +/** + * Created by adrian on 2019-12-27. + */ + +interface AAPSLogger { + + fun debug(tag: LTag, message: String) + fun info(tag: LTag, message: String) + fun error(tag: LTag, message: String) + fun error(tag: LTag, message: String, throwable: Throwable) +} \ No newline at end of file diff --git a/app/src/main/java/info/nightscout/androidaps/logging/AAPSLoggerDebug.kt b/app/src/main/java/info/nightscout/androidaps/logging/AAPSLoggerDebug.kt new file mode 100644 index 0000000000..d512725176 --- /dev/null +++ b/app/src/main/java/info/nightscout/androidaps/logging/AAPSLoggerDebug.kt @@ -0,0 +1,28 @@ +package info.nightscout.androidaps.logging + +import android.util.Log + +/** + * Created by adrian on 2019-12-27. + */ + +class AAPSLoggerDebug : AAPSLogger { + + override fun debug(tag: LTag, message: String) { + Log.d(tag.tag, message) + } + + override fun info(tag: LTag, message: String) { + Log.i(tag.tag, message) + } + + override fun error(tag: LTag, message: String) { + Log.e(tag.tag, message) + + } + + override fun error(tag: LTag, message: String, throwable: Throwable) { + Log.e(tag.tag, message, throwable) + + } +} \ No newline at end of file diff --git a/app/src/main/java/info/nightscout/androidaps/logging/AAPSLoggerProduction.kt b/app/src/main/java/info/nightscout/androidaps/logging/AAPSLoggerProduction.kt new file mode 100644 index 0000000000..414fad2859 --- /dev/null +++ b/app/src/main/java/info/nightscout/androidaps/logging/AAPSLoggerProduction.kt @@ -0,0 +1,38 @@ +package info.nightscout.androidaps.logging + +import org.slf4j.LoggerFactory + +/** + * Created by adrian on 2019-12-27. + */ + +class AAPSLoggerProduction : AAPSLogger { + + override fun debug(tag: LTag, message: String) { + if (L.isEnabled(tag.tag)) { + LoggerFactory.getLogger(tag.tag).debug(message) + + } + } + + override fun info(tag: LTag, message: String) { + if (L.isEnabled(tag.tag)) { + LoggerFactory.getLogger(tag.tag).info(message) + + } + } + + override fun error(tag: LTag, message: String) { + if (L.isEnabled(tag.tag)) { + LoggerFactory.getLogger(tag.tag).error(message) + + } + } + + override fun error(tag: LTag, message: String, throwable: Throwable) { + if (L.isEnabled(tag.tag)) { + LoggerFactory.getLogger(tag.tag).error(message, throwable) + + } + } +} \ No newline at end of file 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 3e3dfae6e9..2ec1473c08 100644 --- a/app/src/main/java/info/nightscout/androidaps/logging/L.kt +++ b/app/src/main/java/info/nightscout/androidaps/logging/L.kt @@ -118,4 +118,32 @@ 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"), + SMS("SMS"), } \ No newline at end of file diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/configBuilder/ConfigBuilderPlugin.java b/app/src/main/java/info/nightscout/androidaps/plugins/configBuilder/ConfigBuilderPlugin.java index 04fad732b4..076d29382b 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/configBuilder/ConfigBuilderPlugin.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/configBuilder/ConfigBuilderPlugin.java @@ -3,8 +3,6 @@ package info.nightscout.androidaps.plugins.configBuilder; import androidx.annotation.Nullable; import org.jetbrains.annotations.NotNull; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; import java.util.ArrayList; @@ -24,7 +22,8 @@ import info.nightscout.androidaps.interfaces.PluginType; import info.nightscout.androidaps.interfaces.ProfileInterface; import info.nightscout.androidaps.interfaces.PumpInterface; import info.nightscout.androidaps.interfaces.SensitivityInterface; -import info.nightscout.androidaps.logging.L; +import info.nightscout.androidaps.logging.AAPSLogger; +import info.nightscout.androidaps.logging.LTag; import info.nightscout.androidaps.plugins.bus.RxBus; import info.nightscout.androidaps.plugins.insulin.InsulinOrefRapidActingPlugin; import info.nightscout.androidaps.plugins.profile.local.LocalProfilePlugin; @@ -39,9 +38,8 @@ import info.nightscout.androidaps.utils.SP; */ @Singleton public class ConfigBuilderPlugin extends PluginBase { - private Logger log = LoggerFactory.getLogger(L.CONFIGBUILDER); - private static ConfigBuilderPlugin configBuilderPlugin; + private final AAPSLogger aapsLogger; // TODO move to plugin base /** @@ -78,7 +76,10 @@ public class ConfigBuilderPlugin extends PluginBase { * Lazy dependencies in this constructor. * */ @Inject - public ConfigBuilderPlugin(Lazy insulinOrefRapidActingPlugin) { + public ConfigBuilderPlugin( + Lazy insulinOrefRapidActingPlugin, + AAPSLogger aapsLogger + ) { super(new PluginDescription() .mainType(PluginType.GENERAL) .fragmentClass(ConfigBuilderFragment.class.getName()) @@ -90,6 +91,7 @@ public class ConfigBuilderPlugin extends PluginBase { .description(R.string.description_config_builder) ); this.insulinOrefRapidActingPlugin = insulinOrefRapidActingPlugin; + this.aapsLogger = aapsLogger; configBuilderPlugin = this; // TODO: only while transitioning to Dagger } @@ -122,8 +124,7 @@ public class ConfigBuilderPlugin extends PluginBase { public void storeSettings(String from) { if (pluginList != null) { - if (L.isEnabled(L.CONFIGBUILDER)) - log.debug("Storing settings from: " + from); + aapsLogger.debug(LTag.CONFIGBUILDER, "Storing settings from: " + from); verifySelectionInCategories(); @@ -146,19 +147,16 @@ public class ConfigBuilderPlugin extends PluginBase { private void savePref(PluginBase p, PluginType type, boolean storeVisible) { String settingEnabled = "ConfigBuilder_" + type.name() + "_" + p.getClass().getSimpleName() + "_Enabled"; SP.putBoolean(settingEnabled, p.isEnabled(type)); - if (L.isEnabled(L.CONFIGBUILDER)) - log.debug("Storing: " + settingEnabled + ":" + p.isEnabled(type)); + aapsLogger.debug(LTag.CONFIGBUILDER, "Storing: " + settingEnabled + ":" + p.isEnabled(type)); if (storeVisible) { String settingVisible = "ConfigBuilder_" + type.name() + "_" + p.getClass().getSimpleName() + "_Visible"; SP.putBoolean(settingVisible, p.isFragmentVisible()); - if (L.isEnabled(L.CONFIGBUILDER)) - log.debug("Storing: " + settingVisible + ":" + p.isFragmentVisible()); + aapsLogger.debug(LTag.CONFIGBUILDER, "Storing: " + settingVisible + ":" + p.isFragmentVisible()); } } private void loadSettings() { - if (L.isEnabled(L.CONFIGBUILDER)) - log.debug("Loading stored settings"); + aapsLogger.debug(LTag.CONFIGBUILDER, "Loading stored settings"); for (PluginBase p : pluginList) { PluginType type = p.getType(); loadPref(p, type, true); @@ -178,8 +176,7 @@ public class ConfigBuilderPlugin extends PluginBase { else if (p.getType() == type && (p.pluginDescription.enableByDefault || p.pluginDescription.alwaysEnabled)) { p.setPluginEnabled(type, true); } - if (L.isEnabled(L.CONFIGBUILDER)) - log.debug("Loaded: " + settingEnabled + ":" + p.isEnabled(type)); + aapsLogger.debug(LTag.CONFIGBUILDER, "Loaded: " + settingEnabled + ":" + p.isEnabled(type)); if (loadVisible) { String settingVisible = "ConfigBuilder_" + type.name() + "_" + p.getClass().getSimpleName() + "_Visible"; if (SP.contains(settingVisible)) @@ -187,8 +184,7 @@ public class ConfigBuilderPlugin extends PluginBase { else if (p.getType() == type && p.pluginDescription.visibleByDefault) { p.setFragmentVisible(type, true); } - if (L.isEnabled(L.CONFIGBUILDER)) - log.debug("Loaded: " + settingVisible + ":" + p.isFragmentVisible()); + aapsLogger.debug(LTag.CONFIGBUILDER, "Loaded: " + settingVisible + ":" + p.isFragmentVisible()); } } @@ -196,11 +192,9 @@ public class ConfigBuilderPlugin extends PluginBase { private void upgradeSettings() { if (!SP.contains("ConfigBuilder_1_NSProfilePlugin_Enabled")) return; - if (L.isEnabled(L.CONFIGBUILDER)) - log.debug("Upgrading stored settings"); + aapsLogger.debug(LTag.CONFIGBUILDER, "Upgrading stored settings"); for (PluginBase p : pluginList) { - if (L.isEnabled(L.CONFIGBUILDER)) - log.debug("Processing " + p.getName()); + aapsLogger.debug(LTag.CONFIGBUILDER, "Processing " + p.getName()); for (int type = 1; type < 11; type++) { PluginType newType; switch (type) { @@ -291,21 +285,20 @@ public class ConfigBuilderPlugin extends PluginBase { } public void logPluginStatus() { - if (L.isEnabled(L.CONFIGBUILDER)) - for (PluginBase p : pluginList) { - log.debug(p.getName() + ":" + - (p.isEnabled(PluginType.GENERAL) ? " GENERAL" : "") + - (p.isEnabled(PluginType.TREATMENT) ? " TREATMENT" : "") + - (p.isEnabled(PluginType.SENSITIVITY) ? " SENSITIVITY" : "") + - (p.isEnabled(PluginType.PROFILE) ? " PROFILE" : "") + - (p.isEnabled(PluginType.APS) ? " APS" : "") + - (p.isEnabled(PluginType.PUMP) ? " PUMP" : "") + - (p.isEnabled(PluginType.CONSTRAINTS) ? " CONSTRAINTS" : "") + - (p.isEnabled(PluginType.LOOP) ? " LOOP" : "") + - (p.isEnabled(PluginType.BGSOURCE) ? " BGSOURCE" : "") + - (p.isEnabled(PluginType.INSULIN) ? " INSULIN" : "") - ); - } + for (PluginBase p : pluginList) { + aapsLogger.debug(LTag.CONFIGBUILDER, p.getName() + ":" + + (p.isEnabled(PluginType.GENERAL) ? " GENERAL" : "") + + (p.isEnabled(PluginType.TREATMENT) ? " TREATMENT" : "") + + (p.isEnabled(PluginType.SENSITIVITY) ? " SENSITIVITY" : "") + + (p.isEnabled(PluginType.PROFILE) ? " PROFILE" : "") + + (p.isEnabled(PluginType.APS) ? " APS" : "") + + (p.isEnabled(PluginType.PUMP) ? " PUMP" : "") + + (p.isEnabled(PluginType.CONSTRAINTS) ? " CONSTRAINTS" : "") + + (p.isEnabled(PluginType.LOOP) ? " LOOP" : "") + + (p.isEnabled(PluginType.BGSOURCE) ? " BGSOURCE" : "") + + (p.isEnabled(PluginType.INSULIN) ? " INSULIN" : "") + ); + } } private void verifySelectionInCategories() { @@ -320,8 +313,7 @@ public class ConfigBuilderPlugin extends PluginBase { if (activeInsulin == null) { activeInsulin = insulinOrefRapidActingPlugin.get(); insulinOrefRapidActingPlugin.get().setPluginEnabled(PluginType.INSULIN, true); - if (L.isEnabled(L.CONFIGBUILDER)) - log.debug("Defaulting InsulinOrefRapidActingPlugin"); + aapsLogger.debug(LTag.CONFIGBUILDER, "Defaulting InsulinOrefRapidActingPlugin"); } this.setFragmentVisiblities(((PluginBase) activeInsulin).getName(), pluginsInCategory, PluginType.INSULIN); @@ -331,8 +323,7 @@ public class ConfigBuilderPlugin extends PluginBase { if (activeSensitivity == null) { activeSensitivity = SensitivityOref0Plugin.getPlugin(); SensitivityOref0Plugin.getPlugin().setPluginEnabled(PluginType.SENSITIVITY, true); - if (L.isEnabled(L.CONFIGBUILDER)) - log.debug("Defaulting SensitivityOref0Plugin"); + aapsLogger.debug(LTag.CONFIGBUILDER, "Defaulting SensitivityOref0Plugin"); } this.setFragmentVisiblities(((PluginBase) activeSensitivity).getName(), pluginsInCategory, PluginType.SENSITIVITY); @@ -348,8 +339,7 @@ public class ConfigBuilderPlugin extends PluginBase { if (activePump == null) { activePump = VirtualPumpPlugin.getPlugin(); VirtualPumpPlugin.getPlugin().setPluginEnabled(PluginType.PUMP, true); - if (L.isEnabled(L.CONFIGBUILDER)) - log.debug("Defaulting VirtualPumpPlugin"); + aapsLogger.debug(LTag.CONFIGBUILDER, "Defaulting VirtualPumpPlugin"); } this.setFragmentVisiblities(((PluginBase) activePump).getName(), pluginsInCategory, PluginType.PUMP); @@ -407,8 +397,7 @@ public class ConfigBuilderPlugin extends PluginBase { private void setFragmentVisiblities(String activePluginName, ArrayList pluginsInCategory, PluginType pluginType) { - if (L.isEnabled(L.CONFIGBUILDER)) - log.debug("Selected interface: " + activePluginName); + aapsLogger.debug(LTag.CONFIGBUILDER, "Selected interface: " + activePluginName); for (PluginBase p : pluginsInCategory) { if (!p.getName().equals(activePluginName)) { p.setFragmentVisible(pluginType, false); diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/general/smsCommunicator/SmsCommunicatorPlugin.kt b/app/src/main/java/info/nightscout/androidaps/plugins/general/smsCommunicator/SmsCommunicatorPlugin.kt index b2b6515b7d..425217e15f 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/general/smsCommunicator/SmsCommunicatorPlugin.kt +++ b/app/src/main/java/info/nightscout/androidaps/plugins/general/smsCommunicator/SmsCommunicatorPlugin.kt @@ -22,7 +22,9 @@ import info.nightscout.androidaps.interfaces.Constraint import info.nightscout.androidaps.interfaces.PluginBase import info.nightscout.androidaps.interfaces.PluginDescription 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.loop.LoopPlugin import info.nightscout.androidaps.plugins.bus.RxBus.send import info.nightscout.androidaps.plugins.bus.RxBus.toObservable @@ -53,7 +55,8 @@ import javax.inject.Singleton class SmsCommunicatorPlugin @Inject constructor( val configBuilderPlugin: ConfigBuilderPlugin, val resourceHelper: ResourceHelper, - val constraintChecker: ConstraintChecker + val constraintChecker: ConstraintChecker, + val aapsLogger: AAPSLogger ) : PluginBase(PluginDescription() .mainType(PluginType.GENERAL) .fragmentClass(SmsCommunicatorFragment::class.java.name) @@ -62,8 +65,6 @@ class SmsCommunicatorPlugin @Inject constructor( .preferencesId(R.xml.pref_smscommunicator) .description(R.string.description_sms_communicator) ) { - - private val log = LoggerFactory.getLogger(L.SMS) private val disposable = CompositeDisposable() var allowedNumbers: MutableList = ArrayList() var messageToConfirm: AuthRequest? = null @@ -149,7 +150,7 @@ class SmsCommunicatorPlugin @Inject constructor( for (number in substrings) { val cleaned = number.replace("\\s+".toRegex(), "") allowedNumbers.add(cleaned) - log.debug("Found allowed number: $cleaned") + aapsLogger.debug(LTag.SMS,"Found allowed number: $cleaned") } } } @@ -181,11 +182,11 @@ class SmsCommunicatorPlugin @Inject constructor( fun processSms(receivedSms: Sms) { if (!isEnabled(PluginType.GENERAL)) { - log.debug("Ignoring SMS. Plugin disabled.") + aapsLogger.debug(LTag.SMS,"Ignoring SMS. Plugin disabled.") return } if (!isAllowedNumber(receivedSms.phoneNumber)) { - log.debug("Ignoring SMS from: " + receivedSms.phoneNumber + ". Sender not allowed") + aapsLogger.debug(LTag.SMS,"Ignoring SMS from: " + receivedSms.phoneNumber + ". Sender not allowed") receivedSms.ignored = true messages.add(receivedSms) send(EventSmsCommunicatorUpdateGui()) @@ -193,7 +194,7 @@ class SmsCommunicatorPlugin @Inject constructor( } val pump = configBuilderPlugin.activePump ?: return messages.add(receivedSms) - log.debug(receivedSms.toString()) + aapsLogger.debug(LTag.SMS,receivedSms.toString()) val splitted = receivedSms.text.split(Regex("\\s+")).toTypedArray() val remoteCommandsAllowed = SP.getBoolean(R.string.key_smscommunicator_remotecommandsallowed, false) if (splitted.isNotEmpty() && isCommand(splitted[0].toUpperCase(Locale.getDefault()), receivedSms.phoneNumber)) { @@ -858,7 +859,7 @@ class SmsCommunicatorPlugin @Inject constructor( val smsManager = SmsManager.getDefault() sms.text = stripAccents(sms.text) try { - if (L.isEnabled(L.SMS)) log.debug("Sending SMS to " + sms.phoneNumber + ": " + sms.text) + aapsLogger.debug(LTag.SMS,"Sending SMS to " + sms.phoneNumber + ": " + sms.text) if (sms.text.toByteArray().size <= 140) smsManager.sendTextMessage(sms.phoneNumber, null, sms.text, null, null) else { val parts = smsManager.divideMessage(sms.text) diff --git a/app/src/main/java/info/nightscout/androidaps/services/DataService.java b/app/src/main/java/info/nightscout/androidaps/services/DataService.java index f24129f036..3153b2c4bd 100644 --- a/app/src/main/java/info/nightscout/androidaps/services/DataService.java +++ b/app/src/main/java/info/nightscout/androidaps/services/DataService.java @@ -1,6 +1,5 @@ package info.nightscout.androidaps.services; -import android.app.IntentService; import android.content.Intent; import android.os.Bundle; import android.provider.Telephony; @@ -19,8 +18,10 @@ import info.nightscout.androidaps.R; import info.nightscout.androidaps.db.CareportalEvent; import info.nightscout.androidaps.events.EventNsFood; import info.nightscout.androidaps.events.EventNsTreatment; +import info.nightscout.androidaps.logging.AAPSLogger; import info.nightscout.androidaps.logging.BundleLogger; import info.nightscout.androidaps.logging.L; +import info.nightscout.androidaps.logging.LTag; import info.nightscout.androidaps.plugins.bus.RxBus; import info.nightscout.androidaps.plugins.general.nsclient.data.NSDeviceStatus; import info.nightscout.androidaps.plugins.general.nsclient.data.NSMbg; @@ -44,7 +45,6 @@ import info.nightscout.androidaps.utils.sharedPreferences.SP; public class DataService extends DaggerIntentService { - private Logger log = LoggerFactory.getLogger(L.DATASERVICE); public DataService() { super("DataService"); @@ -53,15 +53,17 @@ public class DataService extends DaggerIntentService { @Inject SmsCommunicatorPlugin smsCommunicatorPlugin; + @Inject + AAPSLogger aapsLogger; + @Inject SP sp; @Override protected void onHandleIntent(final Intent intent) { - if (L.isEnabled(L.DATASERVICE)) { - log.debug("onHandleIntent " + intent); - log.debug("onHandleIntent " + BundleLogger.log(intent.getExtras())); - } + aapsLogger.debug(LTag.DATASERVICE, "onHandleIntent " + intent); + aapsLogger.debug(LTag.DATASERVICE, "onHandleIntent " + BundleLogger.log(intent.getExtras())); + boolean acceptNSData = !sp.getBoolean(R.string.key_ns_upload_only, false); Bundle bundles = intent.getExtras(); @@ -111,8 +113,7 @@ public class DataService extends DaggerIntentService { smsCommunicatorPlugin.handleNewData(intent); } - if (L.isEnabled(L.DATASERVICE)) - log.debug("onHandleIntent exit " + intent); + aapsLogger.debug(LTag.DATASERVICE, "onHandleIntent exit " + intent); DataReceiver.completeWakefulIntent(intent); } @@ -124,8 +125,7 @@ public class DataService extends DaggerIntentService { private void handleNewDataFromNSClient(Intent intent) { Bundle bundles = intent.getExtras(); if (bundles == null) return; - if (L.isEnabled(L.DATASERVICE)) - log.debug("Got intent: " + intent.getAction()); + aapsLogger.debug(LTag.DATASERVICE, "Got intent: " + intent.getAction()); if (intent.getAction().equals(Intents.ACTION_NEW_TREATMENT) || intent.getAction().equals(Intents.ACTION_CHANGED_TREATMENT)) { @@ -143,7 +143,7 @@ public class DataService extends DaggerIntentService { } } } catch (JSONException e) { - log.error("Unhandled exception", e); + aapsLogger.error(LTag.DATASERVICE, "Unhandled exception", e); } } @@ -164,7 +164,7 @@ public class DataService extends DaggerIntentService { } } } catch (JSONException e) { - log.error("Unhandled exception", e); + aapsLogger.error(LTag.DATASERVICE, "Unhandled exception", e); } } @@ -185,7 +185,7 @@ public class DataService extends DaggerIntentService { } } } catch (Exception e) { - log.error("Unhandled exception", e); + aapsLogger.error(LTag.DATASERVICE, "Unhandled exception", e); } } } @@ -210,7 +210,7 @@ public class DataService extends DaggerIntentService { double carbs = JsonHelper.safeGetDouble(json, "carbs"); String eventType = JsonHelper.safeGetString(json, "eventType"); if (eventType == null) { - log.debug("Wrong treatment. Ignoring : " + json.toString()); + aapsLogger.debug(LTag.DATASERVICE, "Wrong treatment. Ignoring : " + json.toString()); return; } if (insulin > 0 || carbs > 0) { @@ -258,8 +258,7 @@ public class DataService extends DaggerIntentService { NSMbg nsMbg = new NSMbg(mbgJson); CareportalEvent careportalEvent = new CareportalEvent(nsMbg); MainApp.getDbHelper().createOrUpdate(careportalEvent); - if (L.isEnabled(L.DATASERVICE)) - log.debug("Adding/Updating new MBG: " + careportalEvent.toString()); + aapsLogger.debug(LTag.DATASERVICE, "Adding/Updating new MBG: " + careportalEvent.toString()); } }