Merge pull request #7953 from SomberNight/202208_logging_stderr_timestamps
logging: add a relative timestamp to stderr console logs
This commit is contained in:
@@ -36,17 +36,21 @@ file_formatter = LogFormatterForFiles(fmt="%(asctime)22s | %(levelname)8s | %(na
|
||||
|
||||
class LogFormatterForConsole(logging.Formatter):
|
||||
|
||||
def formatTime(self, record, datefmt=None):
|
||||
t = record.relativeCreated / 1000
|
||||
return f"{t:6.2f}"
|
||||
|
||||
def format(self, record):
|
||||
record = copy.copy(record) # avoid mutating arg
|
||||
record = _shorten_name_of_logrecord(record)
|
||||
if shortcut := getattr(record, 'custom_shortcut', None):
|
||||
record.name = f"{shortcut}/{record.name}"
|
||||
text = super().format(record)
|
||||
shortcut = getattr(record, 'custom_shortcut', None)
|
||||
if shortcut:
|
||||
text = text[:1] + f"/{shortcut}" + text[1:]
|
||||
return text
|
||||
|
||||
|
||||
# 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:
|
||||
|
||||
Reference in New Issue
Block a user