colored error output
This commit is contained in:
parent
e4d2c98fb5
commit
eea6c1568e
|
@ -6,6 +6,8 @@ import importlib
|
|||
import multiprocessing as mp
|
||||
import sys
|
||||
|
||||
import colorama
|
||||
|
||||
from logging.handlers import SysLogHandler
|
||||
|
||||
from ucloud.configure.main import configure_parser
|
||||
|
@ -24,11 +26,20 @@ class NoTracebackStreamHandler(logging.StreamHandler):
|
|||
def handle(self, record):
|
||||
info, cache = record.exc_info, record.exc_text
|
||||
record.exc_info, record.exc_text = None, None
|
||||
|
||||
if record.levelname == 'WARNING':
|
||||
color = colorama.Fore.YELLOW
|
||||
elif record.levelname == 'ERROR':
|
||||
color = colorama.Fore.LIGHTRED_EX
|
||||
else:
|
||||
color = colorama.Fore.RED
|
||||
try:
|
||||
print(color)
|
||||
super().handle(record)
|
||||
finally:
|
||||
record.exc_info = info
|
||||
record.exc_text = cache
|
||||
print(colorama.Style.RESET_ALL)
|
||||
|
||||
if __name__ == '__main__':
|
||||
sys.excepthook = exception_hook
|
||||
|
|
Loading…
Reference in New Issue