Browse Source

make "-v" (logging to stderr) work with commands

When running a command, file logging is disabled as every
command-invocation would create a new logfile. However if the user
explicitly sets "-v" on the commandline, there's no reason why that
shouldn't work.
patch-4
SomberNight 3 years ago
parent
commit
ffe36e2f56
No known key found for this signature in database GPG Key ID: B33B5F232C6271E9
  1. 20
      electrum/logging.py
  2. 1
      run_electrum

20
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)

1
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'):

Loading…
Cancel
Save