update logging formatter handling for consistent behavior with error messsages
Signed-off-by: Karl W Schulz <karl.schulz@amd.com>
이 커밋은 다음에 포함됨:
+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)
|
||||
|
||||
|
||||
새 이슈에서 참조
사용자 차단