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