1
0

logging: basics

This commit is contained in:
SomberNight
2019-04-26 18:52:26 +02:00
parent 4d64e132d7
commit 3385a94753
68 changed files with 681 additions and 563 deletions

View File

@@ -3,9 +3,10 @@ from struct import pack
from electrum import ecc
from electrum.i18n import _
from electrum.util import PrintError, UserCancelled
from electrum.util import UserCancelled
from electrum.keystore import bip39_normalize_passphrase
from electrum.bip32 import BIP32Node, convert_bip32_path_to_list_of_uint32
from electrum.logging import Logger
class GuiMixin(object):
@@ -93,7 +94,7 @@ class GuiMixin(object):
return self.proto.CharacterAck(**char_info)
class KeepKeyClientBase(GuiMixin, PrintError):
class KeepKeyClientBase(GuiMixin, Logger):
def __init__(self, handler, plugin, proto):
assert hasattr(self, 'tx_api') # ProtocolMixin already constructed?
@@ -104,6 +105,7 @@ class KeepKeyClientBase(GuiMixin, PrintError):
self.types = plugin.types
self.msg = None
self.creating_wallet = False
Logger.__init__(self)
self.used()
def __str__(self):
@@ -137,7 +139,7 @@ class KeepKeyClientBase(GuiMixin, PrintError):
def timeout(self, cutoff):
'''Time out the client if the last operation was before cutoff.'''
if self.last_operation < cutoff:
self.print_error("timed out")
self.logger.info("timed out")
self.clear_session()
@staticmethod
@@ -190,13 +192,13 @@ class KeepKeyClientBase(GuiMixin, PrintError):
def clear_session(self):
'''Clear the session to force pin (and passphrase if enabled)
re-entry. Does not leak exceptions.'''
self.print_error("clear session:", self)
self.logger.info(f"clear session: {self}")
self.prevent_timeouts()
try:
super(KeepKeyClientBase, self).clear_session()
except BaseException as e:
# If the device was removed it has the same effect...
self.print_error("clear_session: ignoring error", str(e))
self.logger.info(f"clear_session: ignoring error {e}")
def get_public_node(self, address_n, creating):
self.creating_wallet = creating
@@ -204,7 +206,7 @@ class KeepKeyClientBase(GuiMixin, PrintError):
def close(self):
'''Called when Our wallet was closed or the device removed.'''
self.print_error("closing client")
self.logger.info("closing client")
self.clear_session()
# Release the device
self.transport.close()

View File

@@ -108,7 +108,7 @@ class KeepKeyPlugin(HW_PluginBase):
return WebUsbTransport(device)
def _try_hid(self, device):
self.print_error("Trying to connect over USB...")
self.logger.info("Trying to connect over USB...")
if device.interface_number == 1:
pair = [None, device.path]
else:
@@ -119,15 +119,15 @@ class KeepKeyPlugin(HW_PluginBase):
except BaseException as e:
# see fdb810ba622dc7dbe1259cbafb5b28e19d2ab114
# raise
self.print_error("cannot connect at", device.path, str(e))
self.logger.info(f"cannot connect at {device.path} {e}")
return None
def _try_webusb(self, device):
self.print_error("Trying to connect over WebUSB...")
self.logger.info("Trying to connect over WebUSB...")
try:
return self.webusb_transport(device)
except BaseException as e:
self.print_error("cannot connect at", device.path, str(e))
self.logger.info(f"cannot connect at {device.path} {e}")
return None
def create_client(self, device, handler):
@@ -137,10 +137,10 @@ class KeepKeyPlugin(HW_PluginBase):
transport = self._try_hid(device)
if not transport:
self.print_error("cannot connect to device")
self.logger.info("cannot connect to device")
return
self.print_error("connected to device at", device.path)
self.logger.info(f"connected to device at {device.path}")
client = self.client_class(transport, handler, self)
@@ -148,14 +148,14 @@ class KeepKeyPlugin(HW_PluginBase):
try:
client.ping('t')
except BaseException as e:
self.print_error("ping failed", str(e))
self.logger.info(f"ping failed {e}")
return None
if not client.atleast_version(*self.minimum_firmware):
msg = (_('Outdated {} firmware for device labelled {}. Please '
'download the updated firmware from {}')
.format(self.device, client.label(), self.firmware_URL))
self.print_error(msg)
self.logger.info(msg)
if handler:
handler.show_error(msg)
else:
@@ -215,7 +215,7 @@ class KeepKeyPlugin(HW_PluginBase):
except UserCancelled:
exit_code = 1
except BaseException as e:
traceback.print_exc(file=sys.stderr)
self.logger.exception('')
handler.show_error(str(e))
exit_code = 1
finally: