From d7ff3c2798eeafb3e781190cbb5ec2a2275fa65c Mon Sep 17 00:00:00 2001 From: pedro Date: Wed, 27 Nov 2024 00:38:03 +0100 Subject: [PATCH] logger: improve error handling --- utils/logger.py | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/utils/logger.py b/utils/logger.py index 3a320ce..cb324a1 100644 --- a/utils/logger.py +++ b/utils/logger.py @@ -18,13 +18,13 @@ class CustomFormatter(logging.Formatter): color = PURPLE else: color = RESET - + record.levelname = f"{color}{record.levelname}{RESET}" if record.args: record.msg = self.highlight_args(record.msg, record.args, color) record.args = () - + # provide trace when DEBUG config if settings.DEBUG: import traceback @@ -33,5 +33,8 @@ class CustomFormatter(logging.Formatter): return super().format(record) def highlight_args(self, message, args, color): - highlighted_args = tuple(f"{color}{arg}{RESET}" for arg in args) - return message % highlighted_args + try: + highlighted_args = tuple(f"{color}{arg}{RESET}" for arg in args) + return message % highlighted_args + except (TypeError, ValueError): + return f"{color}{message}{RESET}"