Skip to content

Commit

Permalink
highlight the warning in red for easier visibility of missing params
Browse files Browse the repository at this point in the history
  • Loading branch information
Fnyasimi authored Oct 8, 2024
1 parent 5c478f9 commit 1a7f5f2
Showing 1 changed file with 12 additions and 1 deletion.
13 changes: 12 additions & 1 deletion software/metax/Logging.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down

0 comments on commit 1a7f5f2

Please sign in to comment.