From 1a7f5f284913f1cb50189c6c78abbc0ed96e623c Mon Sep 17 00:00:00 2001 From: Fnyasimi <41294948+Fnyasimi@users.noreply.github.com> Date: Tue, 8 Oct 2024 12:27:21 -0500 Subject: [PATCH] highlight the warning in red for easier visibility of missing params --- software/metax/Logging.py | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/software/metax/Logging.py b/software/metax/Logging.py index 3bb81dd..8155225 100644 --- a/software/metax/Logging.py +++ b/software/metax/Logging.py @@ -12,10 +12,21 @@ def configureLogging(level=5, target=sys.stderr): kludge=True logger.handlers.clear() + # create console handler and set level to info + RED = "\033[91m" + RESET = "\033[0m" + + # A custom logging formatter for warning + class CustomFormatter(logging.Formatter): + def format(self, record): + if record.levelno == logging.WARNING: + record.msg = f"{RED}{record.msg}{RESET}" + return super().format(record) + # create console handler and set level to info handler = logging.StreamHandler(target) handler.setLevel(level) - formatter = logging.Formatter("%(levelname)s - %(message)s") + formatter = CustomFormatter("%(levelname)s - %(message)s") handler.setFormatter(formatter) logger.addHandler(handler)