diff --git a/electrum/logging.py b/electrum/logging.py index ea949645f..316a5c83d 100644 --- a/electrum/logging.py +++ b/electrum/logging.py @@ -9,10 +9,13 @@ import sys import pathlib import os import platform -from typing import Optional +from typing import Optional, TYPE_CHECKING import copy import subprocess +if TYPE_CHECKING: + from .simple_config import SimpleConfig + class LogFormatterForFiles(logging.Formatter): @@ -306,17 +309,18 @@ class Logger: return '' -def configure_logging(config): +def configure_logging(config: 'SimpleConfig', *, log_to_file: Optional[bool] = None) -> None: verbosity = config.get('verbosity') verbosity_shortcuts = config.get('verbosity_shortcuts') _configure_stderr_logging(verbosity=verbosity, verbosity_shortcuts=verbosity_shortcuts) - log_to_file = config.get('log_to_file', False) - is_android = 'ANDROID_DATA' in os.environ - if is_android: - from jnius import autoclass - build_config = autoclass("org.electrum.electrum.BuildConfig") - log_to_file |= bool(build_config.DEBUG) + if log_to_file is None: + log_to_file = config.get('log_to_file', False) + is_android = 'ANDROID_DATA' in os.environ + if is_android: + from jnius import autoclass + build_config = autoclass("org.electrum.electrum.BuildConfig") + log_to_file |= bool(build_config.DEBUG) if log_to_file: log_directory = pathlib.Path(config.path) / "logs" _configure_file_logging(log_directory) diff --git a/run_electrum b/run_electrum index 4dd1cc146..aa6f71456 100755 --- a/run_electrum +++ b/run_electrum @@ -454,6 +454,7 @@ def handle_cmd(*, cmdname: str, config: 'SimpleConfig', config_options: dict): sys_exit(1) else: # command line + configure_logging(config, log_to_file=False) # don't spam logfiles for each client-side RPC, but support "-v" cmd = known_commands[cmdname] wallet_path = config.get_wallet_path() if not config.get('offline'):