logging: make console log lines shorter
This commit is contained in:
@@ -322,7 +322,8 @@ class ElectrumWindow(QMainWindow, MessageBoxMixin, Logger):
|
|||||||
return self.top_level_window_recurse(override, test_func)
|
return self.top_level_window_recurse(override, test_func)
|
||||||
|
|
||||||
def diagnostic_name(self):
|
def diagnostic_name(self):
|
||||||
return '{}:{}'.format(self.__class__.__name__, self.wallet.diagnostic_name())
|
#return '{}:{}'.format(self.__class__.__name__, self.wallet.diagnostic_name())
|
||||||
|
return self.wallet.diagnostic_name()
|
||||||
|
|
||||||
def is_hidden(self):
|
def is_hidden(self):
|
||||||
return self.isMinimized() or self.isHidden()
|
return self.isMinimized() or self.isHidden()
|
||||||
|
|||||||
@@ -11,7 +11,7 @@ import platform
|
|||||||
from typing import Optional
|
from typing import Optional
|
||||||
|
|
||||||
|
|
||||||
class LogFormatter(logging.Formatter):
|
class LogFormatterForFiles(logging.Formatter):
|
||||||
|
|
||||||
def formatTime(self, record, datefmt=None):
|
def formatTime(self, record, datefmt=None):
|
||||||
# timestamps follow ISO 8601 UTC
|
# timestamps follow ISO 8601 UTC
|
||||||
@@ -21,9 +21,27 @@ class LogFormatter(logging.Formatter):
|
|||||||
return date.strftime(datefmt)
|
return date.strftime(datefmt)
|
||||||
|
|
||||||
|
|
||||||
LOG_FORMAT = "%(asctime)22s | %(levelname)8s | %(name)s | %(message)s"
|
file_formatter = LogFormatterForFiles(fmt="%(asctime)22s | %(levelname)8s | %(name)s | %(message)s")
|
||||||
console_formatter = LogFormatter(fmt=LOG_FORMAT)
|
|
||||||
file_formatter = LogFormatter(fmt=LOG_FORMAT)
|
|
||||||
|
class LogFormatterForConsole(logging.Formatter):
|
||||||
|
|
||||||
|
def format(self, record):
|
||||||
|
# strip the main module name from the logger name
|
||||||
|
if record.name.startswith("electrum."):
|
||||||
|
record.name = record.name[9:]
|
||||||
|
# manual map to shorten common module names
|
||||||
|
record.name = record.name.replace("interface.Interface", "interface", 1)
|
||||||
|
record.name = record.name.replace("network.Network", "network", 1)
|
||||||
|
record.name = record.name.replace("synchronizer.Synchronizer", "synchronizer", 1)
|
||||||
|
record.name = record.name.replace("verifier.SPV", "verifier", 1)
|
||||||
|
record.name = record.name.replace("gui.qt.main_window.ElectrumWindow", "gui.qt.main_window", 1)
|
||||||
|
return super().format(record)
|
||||||
|
|
||||||
|
|
||||||
|
# try to make console log lines short... no timestamp, short levelname, no "electrum."
|
||||||
|
console_formatter = LogFormatterForConsole(fmt="%(levelname).1s | %(name)s | %(message)s")
|
||||||
|
|
||||||
|
|
||||||
# enable logs universally (including for other libraries)
|
# enable logs universally (including for other libraries)
|
||||||
root_logger = logging.getLogger()
|
root_logger = logging.getLogger()
|
||||||
|
|||||||
@@ -132,7 +132,7 @@ class Synchronizer(SynchronizerBase):
|
|||||||
self.requested_histories = {}
|
self.requested_histories = {}
|
||||||
|
|
||||||
def diagnostic_name(self):
|
def diagnostic_name(self):
|
||||||
return '{}:{}'.format(self.__class__.__name__, self.wallet.diagnostic_name())
|
return self.wallet.diagnostic_name()
|
||||||
|
|
||||||
def is_up_to_date(self):
|
def is_up_to_date(self):
|
||||||
return (not self.requested_addrs
|
return (not self.requested_addrs
|
||||||
|
|||||||
@@ -342,13 +342,14 @@ def constant_time_compare(val1, val2):
|
|||||||
|
|
||||||
|
|
||||||
# decorator that prints execution time
|
# decorator that prints execution time
|
||||||
|
_profiler_logger = _logger.getChild('profiler')
|
||||||
def profiler(func):
|
def profiler(func):
|
||||||
def do_profile(args, kw_args):
|
def do_profile(args, kw_args):
|
||||||
name = func.__qualname__
|
name = func.__qualname__
|
||||||
t0 = time.time()
|
t0 = time.time()
|
||||||
o = func(*args, **kw_args)
|
o = func(*args, **kw_args)
|
||||||
t = time.time() - t0
|
t = time.time() - t0
|
||||||
_logger.debug(f"[profiler] {name} {t:,.4f}")
|
_profiler_logger.debug(f"{name} {t:,.4f}")
|
||||||
return o
|
return o
|
||||||
return lambda *args, **kw_args: do_profile(args, kw_args)
|
return lambda *args, **kw_args: do_profile(args, kw_args)
|
||||||
|
|
||||||
|
|||||||
@@ -63,7 +63,7 @@ class SPV(NetworkJobOnDefaultServer):
|
|||||||
await group.spawn(self.main)
|
await group.spawn(self.main)
|
||||||
|
|
||||||
def diagnostic_name(self):
|
def diagnostic_name(self):
|
||||||
return '{}:{}'.format(self.__class__.__name__, self.wallet.diagnostic_name())
|
return self.wallet.diagnostic_name()
|
||||||
|
|
||||||
async def main(self):
|
async def main(self):
|
||||||
self.blockchain = self.network.blockchain()
|
self.blockchain = self.network.blockchain()
|
||||||
|
|||||||
Reference in New Issue
Block a user