forked from uncloud/uncloud
colored error output
This commit is contained in:
parent
e4d2c98fb5
commit
eea6c1568e
2 changed files with 12 additions and 0 deletions
|
@ -6,6 +6,8 @@ import importlib
|
||||||
import multiprocessing as mp
|
import multiprocessing as mp
|
||||||
import sys
|
import sys
|
||||||
|
|
||||||
|
import colorama
|
||||||
|
|
||||||
from logging.handlers import SysLogHandler
|
from logging.handlers import SysLogHandler
|
||||||
|
|
||||||
from ucloud.configure.main import configure_parser
|
from ucloud.configure.main import configure_parser
|
||||||
|
@ -24,11 +26,20 @@ class NoTracebackStreamHandler(logging.StreamHandler):
|
||||||
def handle(self, record):
|
def handle(self, record):
|
||||||
info, cache = record.exc_info, record.exc_text
|
info, cache = record.exc_info, record.exc_text
|
||||||
record.exc_info, record.exc_text = None, None
|
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:
|
try:
|
||||||
|
print(color)
|
||||||
super().handle(record)
|
super().handle(record)
|
||||||
finally:
|
finally:
|
||||||
record.exc_info = info
|
record.exc_info = info
|
||||||
record.exc_text = cache
|
record.exc_text = cache
|
||||||
|
print(colorama.Style.RESET_ALL)
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
sys.excepthook = exception_hook
|
sys.excepthook = exception_hook
|
||||||
|
|
1
setup.py
1
setup.py
|
@ -37,6 +37,7 @@ setup(name='ucloud',
|
||||||
'sshtunnel',
|
'sshtunnel',
|
||||||
'sphinx',
|
'sphinx',
|
||||||
'pynetbox',
|
'pynetbox',
|
||||||
|
'colorama',
|
||||||
'sphinx-rtd-theme',
|
'sphinx-rtd-theme',
|
||||||
'etcd3 @ https://github.com/kragniz/python-etcd3/tarball/master#egg=etcd3',
|
'etcd3 @ https://github.com/kragniz/python-etcd3/tarball/master#egg=etcd3',
|
||||||
],
|
],
|
||||||
|
|
Loading…
Reference in a new issue