update logging formatter handling for consistent behavior with error messsages

Signed-off-by: Karl W Schulz <karl.schulz@amd.com>
Этот коммит содержится в:
Karl W Schulz
2024-03-14 17:26:47 -05:00
коммит произвёл Karl W. Schulz
родитель 04c0c8ad46
Коммит 69af2ffc83
2 изменённых файлов: 13 добавлений и 4 удалений
+11 -2
Просмотреть файл
@@ -51,6 +51,15 @@ class ColoredFormatter(logging.Formatter):
return logging.Formatter.format(self, record)
class PlainFormatter(logging.Formatter):
def format(self, record):
if record.levelno == logging.ERROR:
self._style._fmt = "%(levelname)s: %(message)s"
else:
self._style._fmt = "%(message)s"
return logging.Formatter.format(self, record)
# Setup console handler - provided as separate function to be called
# prior to argument parsing
def setup_console_handler():
@@ -61,9 +70,9 @@ def setup_console_handler():
color = True
if color:
formatter = ColoredFormatter("%(levelname)s %(message)s")
formatter = ColoredFormatter("%(levelname)16s %(message)s")
else:
formatter = logging.Formatter("%(message)s")
formatter = PlainFormatter()
console_handler = logging.StreamHandler(sys.stdout)
console_handler.setFormatter(formatter)
+2 -2
Просмотреть файл
@@ -51,9 +51,9 @@ def demarcate(function):
def console_error(*argv, exit=True):
if len(argv) > 1:
logging.error("ERROR: " + f"[{argv[0]}] {argv[1]}")
logging.error(f"[{argv[0]}] {argv[1]}")
else:
logging.error("ERROR: " + f"{argv[0]}")
logging.error(f"{argv[0]}")
if exit:
sys.exit(1)