From 34b594ea40aac5ab66e1fe06f09df14c28898f6e Mon Sep 17 00:00:00 2001 From: SomberNight Date: Fri, 7 Oct 2022 20:28:52 +0000 Subject: [PATCH] android: add setting to enable debug logs If enabled, we log to stderr, which can get inspected via logcat. Not user-friendly at all - but previously there was no way to get logs from a release build. closes https://github.com/spesmilo/electrum/issues/7409 --- electrum/gui/kivy/main_window.py | 5 +++++ electrum/gui/kivy/uix/dialogs/settings.py | 7 +++++++ electrum/gui/qml/components/Preferences.qml | 12 ++++++++++++ electrum/gui/qml/qeconfig.py | 16 ++++++++++++++++ electrum/logging.py | 3 +++ run_electrum | 1 - 6 files changed, 43 insertions(+), 1 deletion(-) diff --git a/electrum/gui/kivy/main_window.py b/electrum/gui/kivy/main_window.py index d27dc677b..a311a3ae2 100644 --- a/electrum/gui/kivy/main_window.py +++ b/electrum/gui/kivy/main_window.py @@ -208,6 +208,10 @@ class ElectrumWindow(App, Logger, EventListener): self.network.run_from_another_thread( self.network.stop_gossip()) + enable_debug_logs = BooleanProperty(False) + def on_enable_debug_logs(self, instance, x): + self.electrum_config.set_key('gui_enable_debug_logs', self.enable_debug_logs, True) + use_change = BooleanProperty(False) def on_use_change(self, instance, x): if self.wallet: @@ -435,6 +439,7 @@ class ElectrumWindow(App, Logger, EventListener): self.use_rbf = config.get('use_rbf', True) self.use_gossip = config.get('use_gossip', False) self.use_unconfirmed = not config.get('confirmed_only', False) + self.enable_debug_logs = config.get('gui_enable_debug_logs', False) # create triggers so as to minimize updating a max of 2 times a sec self._trigger_update_wallet = Clock.create_trigger(self.update_wallet, .5) diff --git a/electrum/gui/kivy/uix/dialogs/settings.py b/electrum/gui/kivy/uix/dialogs/settings.py index f362ea9e2..b9fe39b3a 100644 --- a/electrum/gui/kivy/uix/dialogs/settings.py +++ b/electrum/gui/kivy/uix/dialogs/settings.py @@ -102,6 +102,13 @@ Builder.load_string(''' title: _('Lightning Routing') + ': ' + self.status description: _("Use trampoline routing or gossip.") action: partial(root.routing_dialog, self) + CardSeparator + SettingsItem: + disabled: bool(app.electrum_config.get('verbosity')) and not app.enable_debug_logs + status: 'ON' if (bool(app.electrum_config.get('verbosity')) or app.enable_debug_logs) else 'OFF' + title: _('Enable debug logs') + ': ' + self.status + description: "(developer) Log to stderr, to inspect with logcat." + action: partial(root.boolean_dialog, 'enable_debug_logs', _('Debug Logs'), self.description) # disabled: there is currently only one coin selection policy #CardSeparator diff --git a/electrum/gui/qml/components/Preferences.qml b/electrum/gui/qml/components/Preferences.qml index 14cae42f2..f22681f40 100644 --- a/electrum/gui/qml/components/Preferences.qml +++ b/electrum/gui/qml/components/Preferences.qml @@ -235,6 +235,17 @@ Pane { } } + Switch { + id: enableDebugLogs + text: qsTr('Enable debug logs (for developers)') + Layout.columnSpan: 2 + onCheckedChanged: { + if (activeFocus) + Config.enableDebugLogs = checked + } + enabled: Config.canToggleDebugLogs + } + } } @@ -257,6 +268,7 @@ Pane { spendUnconfirmed.checked = Config.spendUnconfirmed lnRoutingType.currentIndex = Config.useGossip ? 0 : 1 useFallbackAddress.checked = Config.useFallbackAddress + enableDebugLogs.checked = Config.enableDebugLogs useRbf.checked = Config.useRbf } } diff --git a/electrum/gui/qml/qeconfig.py b/electrum/gui/qml/qeconfig.py index f6d9a2c50..c5e71c8a5 100644 --- a/electrum/gui/qml/qeconfig.py +++ b/electrum/gui/qml/qeconfig.py @@ -130,6 +130,22 @@ class QEConfig(AuthMixin, QObject): self.config.set_key('bolt11_fallback', use_fallback) self.useFallbackAddressChanged.emit() + enableDebugLogsChanged = pyqtSignal() + @pyqtProperty(bool, notify=enableDebugLogsChanged) + def enableDebugLogs(self): + gui_setting = self.config.get('gui_enable_debug_logs', False) + return gui_setting or bool(self.config.get('verbosity')) + + @pyqtProperty(bool, notify=enableDebugLogsChanged) + def canToggleDebugLogs(self): + gui_setting = self.config.get('gui_enable_debug_logs', False) + return not self.config.get('verbosity') or gui_setting + + @enableDebugLogs.setter + def enableDebugLogs(self, enable): + self.config.set_key('gui_enable_debug_logs', enable) + self.enableDebugLogsChanged.emit() + useRbfChanged = pyqtSignal() @pyqtProperty(bool, notify=useRbfChanged) def useRbf(self): diff --git a/electrum/logging.py b/electrum/logging.py index f1191a4fc..50f2fd083 100644 --- a/electrum/logging.py +++ b/electrum/logging.py @@ -314,6 +314,9 @@ def configure_logging(config: 'SimpleConfig', *, log_to_file: Optional[bool] = N verbosity = config.get('verbosity') verbosity_shortcuts = config.get('verbosity_shortcuts') + if not verbosity: + if config.get('gui_enable_debug_logs') or is_android_debug_apk(): + verbosity = '*' _configure_stderr_logging(verbosity=verbosity, verbosity_shortcuts=verbosity_shortcuts) if log_to_file is None: diff --git a/run_electrum b/run_electrum index b9b251607..0d04458d4 100755 --- a/run_electrum +++ b/run_electrum @@ -325,7 +325,6 @@ def main(): import importlib.util android_gui = 'kivy' if importlib.util.find_spec('kivy') else 'qml' config_options = { - 'verbosity': '*' if util.is_android_debug_apk() else '', 'cmd': 'gui', 'gui': android_gui, 'single_password':True,