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)