From 09f6cd2e68a7de837611c1c3d48b7a2436ddd31a Mon Sep 17 00:00:00 2001 From: pedro Date: Wed, 27 Nov 2024 00:52:20 +0100 Subject: [PATCH] utils/logger: ensure msgs are logged --- utils/logger.py | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/utils/logger.py b/utils/logger.py index cb324a1..4d7e5ce 100644 --- a/utils/logger.py +++ b/utils/logger.py @@ -22,8 +22,14 @@ class CustomFormatter(logging.Formatter): record.levelname = f"{color}{record.levelname}{RESET}" if record.args: - record.msg = self.highlight_args(record.msg, record.args, color) - record.args = () + try: + record.msg = record.msg % record.args + record.args = () + except (TypeError, ValueError): + record.msg = f"{color}{record.msg}{RESET}" + + # Highlight the final formatted message + record.msg = self.highlight_message(record.msg, color) # provide trace when DEBUG config if settings.DEBUG: @@ -33,8 +39,4 @@ class CustomFormatter(logging.Formatter): return super().format(record) def highlight_args(self, message, args, color): - try: - highlighted_args = tuple(f"{color}{arg}{RESET}" for arg in args) - return message % highlighted_args - except (TypeError, ValueError): - return f"{color}{message}{RESET}" + return f"{color}{message}{RESET}"