From 66e3cfd3b445e381985641a0a6c6ad3fbe7d2599 Mon Sep 17 00:00:00 2001 From: aggieNick02 Date: Thu, 26 Sep 2024 12:30:43 -0500 Subject: [PATCH 1/3] Fix log files not containing any newlines ever (affects FileHandler and RotatingFileHandler) --- adafruit_logging.py | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/adafruit_logging.py b/adafruit_logging.py index dc3c652..6bf8de2 100644 --- a/adafruit_logging.py +++ b/adafruit_logging.py @@ -331,7 +331,7 @@ def emit(self, record: LogRecord) -> None: :param record: The record (message object) to be logged """ - self.stream.write(self.format(record)) + super().emit(record) self.stream.flush() @@ -431,9 +431,7 @@ def emit(self, record: LogRecord) -> None: and (self._backupCount > 0) ): self.doRollover() - self.stream.write(self.format(record)) - self.stream.flush() - + super().emit(record) class NullHandler(Handler): """Provide an empty log handler. From 633045a39746750c021b9632bcb977b76fa58e5a Mon Sep 17 00:00:00 2001 From: aggieNick02 Date: Thu, 26 Sep 2024 12:42:32 -0500 Subject: [PATCH 2/3] fix formatting --- adafruit_logging.py | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/adafruit_logging.py b/adafruit_logging.py index 6bf8de2..d70c306 100644 --- a/adafruit_logging.py +++ b/adafruit_logging.py @@ -200,9 +200,9 @@ def format(self, record: LogRecord) -> str: if "{asctime}" in self.fmt or "%(asctime)s" in self.fmt: now = time.localtime() # pylint: disable=line-too-long - vals[ - "asctime" - ] = f"{now.tm_year}-{now.tm_mon:02d}-{now.tm_mday:02d} {now.tm_hour:02d}:{now.tm_min:02d}:{now.tm_sec:02d}" + vals["asctime"] = ( + f"{now.tm_year}-{now.tm_mon:02d}-{now.tm_mday:02d} {now.tm_hour:02d}:{now.tm_min:02d}:{now.tm_sec:02d}" + ) if self.defaults: for key, val in self.defaults.items(): @@ -433,6 +433,7 @@ def emit(self, record: LogRecord) -> None: self.doRollover() super().emit(record) + class NullHandler(Handler): """Provide an empty log handler. From bbef817f2ff82243949378479b29505ad2ee8cc5 Mon Sep 17 00:00:00 2001 From: aggieNick02 Date: Thu, 26 Sep 2024 12:50:41 -0500 Subject: [PATCH 3/3] one more attempt at fixing formatting --- adafruit_logging.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/adafruit_logging.py b/adafruit_logging.py index d70c306..28d1021 100644 --- a/adafruit_logging.py +++ b/adafruit_logging.py @@ -200,9 +200,9 @@ def format(self, record: LogRecord) -> str: if "{asctime}" in self.fmt or "%(asctime)s" in self.fmt: now = time.localtime() # pylint: disable=line-too-long - vals["asctime"] = ( - f"{now.tm_year}-{now.tm_mon:02d}-{now.tm_mday:02d} {now.tm_hour:02d}:{now.tm_min:02d}:{now.tm_sec:02d}" - ) + vals[ + "asctime" + ] = f"{now.tm_year}-{now.tm_mon:02d}-{now.tm_mday:02d} {now.tm_hour:02d}:{now.tm_min:02d}:{now.tm_sec:02d}" if self.defaults: for key, val in self.defaults.items():