From 0abf26d60ce05528838a72284b2b2960bb2fc3a5 Mon Sep 17 00:00:00 2001 From: Mark Qvist Date: Mon, 19 Dec 2022 02:06:41 +0100 Subject: [PATCH] Added option to enable debug logging --- sbapp/main.py | 9 ++++++++- sbapp/services/sidebandservice.py | 4 ++++ sbapp/sideband/core.py | 14 ++++++++++++++ sbapp/ui/layouts.py | 18 +++++++++++++++++- 4 files changed, 43 insertions(+), 2 deletions(-) diff --git a/sbapp/main.py b/sbapp/main.py index c89ddb6..0084162 100644 --- a/sbapp/main.py +++ b/sbapp/main.py @@ -1267,6 +1267,10 @@ class SidebandApp(MDApp): self.sideband.config["lxmf_sync_limit"] = self.root.ids.settings_lxmf_sync_limit.active self.sideband.save_configuration() + def save_debug(sender=None, event=None): + self.sideband.config["debug"] = self.root.ids.settings_debug.active + self.sideband.save_configuration() + def save_print_command(sender=None, event=None): if not sender.focus: in_cmd = self.root.ids.settings_print_command.text @@ -1345,7 +1349,6 @@ class SidebandApp(MDApp): self.root.ids.settings_lxmf_sync_interval.value = self.sideband.config["lxmf_sync_interval"] sync_interval_change(save=False) - if self.sideband.config["lxmf_sync_limit"] == None or self.sideband.config["lxmf_sync_limit"] == False: sync_limit = False else: @@ -1353,6 +1356,10 @@ class SidebandApp(MDApp): self.root.ids.settings_lxmf_sync_limit.active = sync_limit self.root.ids.settings_lxmf_sync_limit.bind(active=save_lxmf_sync_limit) + + self.root.ids.settings_debug.active = self.sideband.config["debug"] + self.root.ids.settings_debug.bind(active=save_debug) + self.settings_ready = True def close_settings_action(self, sender=None): diff --git a/sbapp/services/sidebandservice.py b/sbapp/services/sidebandservice.py index 478d3a9..c19ca4b 100644 --- a/sbapp/services/sidebandservice.py +++ b/sbapp/services/sidebandservice.py @@ -128,6 +128,10 @@ class SidebandService(): self.sideband = SidebandCore(self, is_service=True, android_app_dir=self.app_dir, verbose=__debug_build__) self.sideband.service_context = self.android_service self.sideband.owner_service = self + + if self.sideband.config["debug"]: + Logger.setLevel(LOG_LEVELS["debug"]) + self.sideband.start() self.update_connectivity_type() diff --git a/sbapp/sideband/core.py b/sbapp/sideband/core.py index 9c15fe1..5ccac51 100644 --- a/sbapp/sideband/core.py +++ b/sbapp/sideband/core.py @@ -122,6 +122,7 @@ class SidebandCore(): self.identity_path = self.app_dir+"/app_storage/primary_identity" self.db_path = self.app_dir+"/app_storage/sideband.db" self.lxmf_storage = self.app_dir+"/app_storage/" + self.log_dir = self.app_dir+"/app_storage/" self.tmp_dir = self.app_dir+"/app_storage/tmp" self.exports_dir = self.app_dir+"/exports" @@ -137,6 +138,9 @@ class SidebandCore(): self.__load_config() self.first_run = False + if self.config["debug"]: + self.log_verbose = True + if not os.path.isdir(self.tmp_dir): os.makedirs(self.tmp_dir) else: @@ -203,6 +207,7 @@ class SidebandCore(): self.config = {} # Settings + self.config["debug"] = False self.config["display_name"] = "Anonymous Peer" self.config["notifications_on"] = True self.config["dark_ui"] = False @@ -300,6 +305,8 @@ class SidebandCore(): config_file.close() # Migration actions from earlier config formats + if not "debug" in self.config: + self.config["debug"] = False if not "dark_ui" in self.config: self.config["dark_ui"] = True if not "lxmf_periodic_sync" in self.config: @@ -1389,6 +1396,13 @@ class SidebandCore(): self.reticulum = RNS.Reticulum(configdir=self.rns_configdir, loglevel=selected_level) if RNS.vendor.platformutils.get_platform() == "android": + if self.config["debug"]: + self.reticulum.logdest = RNS.LOG_FILE + if not self.reticulum.is_connected_to_shared_instance: + self.reticulum.logfile = self.log_dir+"sideband_service.log" + else: + self.reticulum.logfile = self.log_dir+"sideband_core.log" + if not self.reticulum.is_connected_to_shared_instance: RNS.log("Running as master or standalone instance, adding interfaces") diff --git a/sbapp/ui/layouts.py b/sbapp/ui/layouts.py index b9e38c5..0c17304 100644 --- a/sbapp/ui/layouts.py +++ b/sbapp/ui/layouts.py @@ -1085,7 +1085,7 @@ MDNavigationLayout: height: dp(48) MDLabel: - text: "Announce At App Startup" + text: "Announce Automatically" font_style: "H6" MDSwitch: @@ -1189,6 +1189,22 @@ MDNavigationLayout: disabled: True active: False + MDBoxLayout: + orientation: "horizontal" + size_hint_y: None + padding: [0,0,dp(24),dp(0)] + height: dp(48) + + MDLabel: + text: "Debug Logging" + font_style: "H6" + + MDSwitch: + id: settings_debug + pos_hint: {"center_y": 0.3} + disabled: False + active: False + MDScreen: name: "hardware_screen"