Make critical errors as red bold for logging to console

This commit is contained in:
Clemens Schwaighofer
2025-07-10 14:34:06 +09:00
parent 3e5a5accf7
commit 19d7e9b5ed
2 changed files with 10 additions and 3 deletions

View File

@@ -42,8 +42,8 @@ class CustomConsoleFormatter(logging.Formatter):
"INFO": Colors.green,
"WARNING": Colors.yellow,
"ERROR": Colors.red,
"CRITICAL": Colors.magenta,
"EXCEPTION": Colors.magenta_bold,
"CRITICAL": Colors.red_bold,
"EXCEPTION": Colors.magenta_bold, # will never be written to console
}
def format(self, record: logging.LogRecord) -> str:

View File

@@ -18,7 +18,7 @@ def main():
log_path=script_path.joinpath('log', 'test.log'),
log_name="Test Log",
log_settings={
"log_level_console": 'WARNING',
"log_level_console": 'DEBUG',
"log_level_file": 'DEBUG',
# "console_color_output_enabled": False,
}
@@ -59,6 +59,13 @@ def main():
except ValueError as e:
print(f"* ERROR: {e}")
try:
__test = 5 / 0
print(f"Divied: {__test}")
except ZeroDivisionError as e:
log.logger.critical("Divison through zero: %s", e)
log.exception("Divison through zero")
if __name__ == "__main__":
main()