From 0c2d22936a62c2687169e1276623310441bee36a Mon Sep 17 00:00:00 2001 From: ElliottKasoar <45317199+ElliottKasoar@users.noreply.github.com> Date: Thu, 4 Apr 2024 14:06:04 +0100 Subject: [PATCH] Tidy log from code review comments Co-authored-by: Jacob Wilkins <46597752+oerc0122@users.noreply.github.com> --- janus_core/log.py | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/janus_core/log.py b/janus_core/log.py index 846c2339..ff01f14b 100644 --- a/janus_core/log.py +++ b/janus_core/log.py @@ -37,13 +37,13 @@ class YamlFormatter(logging.Formatter): # numpydoc ignore=PR02 Format log message to convert new lines into a yaml list. """ - FORMAT = ( - "\n- timestamp: %(asctime)s\n" - " level: %(levelname)s\n" - " message: %(message)s\n" - " trace: %(module)s\n" - " line: %(lineno)d\n" - ) + FORMAT = """ +- timestamp: %(asctime)s + level: %(levelname)s + message: %(message)s + trace: %(module)s + line: %(lineno)d +""" def __init__(self, *args, **kwargs) -> None: """ @@ -77,9 +77,10 @@ def format(self, record: logging.LogRecord) -> str: record.msg = record.msg.replace('"', "'") # Convert new lines into yaml list - msg = record.msg record.msg = "\n" + "\n".join( - f' - "{line.strip()}"' for line in msg.split("\n") if line.strip() + f' - "{line.strip()}"' + for line in record.msg.splitlines() + if line.strip() ) return super().format(record)