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.
This commit is contained in:
@@ -9,10 +9,13 @@ import sys
|
|||||||
import pathlib
|
import pathlib
|
||||||
import os
|
import os
|
||||||
import platform
|
import platform
|
||||||
from typing import Optional
|
from typing import Optional, TYPE_CHECKING
|
||||||
import copy
|
import copy
|
||||||
import subprocess
|
import subprocess
|
||||||
|
|
||||||
|
if TYPE_CHECKING:
|
||||||
|
from .simple_config import SimpleConfig
|
||||||
|
|
||||||
|
|
||||||
class LogFormatterForFiles(logging.Formatter):
|
class LogFormatterForFiles(logging.Formatter):
|
||||||
|
|
||||||
@@ -306,17 +309,18 @@ class Logger:
|
|||||||
return ''
|
return ''
|
||||||
|
|
||||||
|
|
||||||
def configure_logging(config):
|
def configure_logging(config: 'SimpleConfig', *, log_to_file: Optional[bool] = None) -> None:
|
||||||
verbosity = config.get('verbosity')
|
verbosity = config.get('verbosity')
|
||||||
verbosity_shortcuts = config.get('verbosity_shortcuts')
|
verbosity_shortcuts = config.get('verbosity_shortcuts')
|
||||||
_configure_stderr_logging(verbosity=verbosity, verbosity_shortcuts=verbosity_shortcuts)
|
_configure_stderr_logging(verbosity=verbosity, verbosity_shortcuts=verbosity_shortcuts)
|
||||||
|
|
||||||
log_to_file = config.get('log_to_file', False)
|
if log_to_file is None:
|
||||||
is_android = 'ANDROID_DATA' in os.environ
|
log_to_file = config.get('log_to_file', False)
|
||||||
if is_android:
|
is_android = 'ANDROID_DATA' in os.environ
|
||||||
from jnius import autoclass
|
if is_android:
|
||||||
build_config = autoclass("org.electrum.electrum.BuildConfig")
|
from jnius import autoclass
|
||||||
log_to_file |= bool(build_config.DEBUG)
|
build_config = autoclass("org.electrum.electrum.BuildConfig")
|
||||||
|
log_to_file |= bool(build_config.DEBUG)
|
||||||
if log_to_file:
|
if log_to_file:
|
||||||
log_directory = pathlib.Path(config.path) / "logs"
|
log_directory = pathlib.Path(config.path) / "logs"
|
||||||
_configure_file_logging(log_directory)
|
_configure_file_logging(log_directory)
|
||||||
|
|||||||
@@ -454,6 +454,7 @@ def handle_cmd(*, cmdname: str, config: 'SimpleConfig', config_options: dict):
|
|||||||
sys_exit(1)
|
sys_exit(1)
|
||||||
else:
|
else:
|
||||||
# command line
|
# 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]
|
cmd = known_commands[cmdname]
|
||||||
wallet_path = config.get_wallet_path()
|
wallet_path = config.get_wallet_path()
|
||||||
if not config.get('offline'):
|
if not config.get('offline'):
|
||||||
|
|||||||
Reference in New Issue
Block a user