Browse Source

Merge pull request #7953 from SomberNight/202208_logging_stderr_timestamps

logging: add a relative timestamp to stderr console logs
master
ghost43 3 years ago committed by GitHub
parent
commit
77981956d6
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 12
      electrum/logging.py

12
electrum/logging.py

@ -36,17 +36,21 @@ file_formatter = LogFormatterForFiles(fmt="%(asctime)22s | %(levelname)8s | %(na
class LogFormatterForConsole(logging.Formatter): class LogFormatterForConsole(logging.Formatter):
def formatTime(self, record, datefmt=None):
t = record.relativeCreated / 1000
return f"{t:6.2f}"
def format(self, record): def format(self, record):
record = copy.copy(record) # avoid mutating arg
record = _shorten_name_of_logrecord(record) record = _shorten_name_of_logrecord(record)
if shortcut := getattr(record, 'custom_shortcut', None):
record.name = f"{shortcut}/{record.name}"
text = super().format(record) text = super().format(record)
shortcut = getattr(record, 'custom_shortcut', None)
if shortcut:
text = text[:1] + f"/{shortcut}" + text[1:]
return text return text
# try to make console log lines short... no timestamp, short levelname, no "electrum." # try to make console log lines short... no timestamp, short levelname, no "electrum."
console_formatter = LogFormatterForConsole(fmt="%(levelname).1s | %(name)s | %(message)s") console_formatter = LogFormatterForConsole(fmt="%(asctime)s | %(levelname).1s | %(name)s | %(message)s")
def _shorten_name_of_logrecord(record: logging.LogRecord) -> logging.LogRecord: def _shorten_name_of_logrecord(record: logging.LogRecord) -> logging.LogRecord:

Loading…
Cancel
Save