Remove colors, remove sophisticated logging
Go back to simple
This commit is contained in:
parent
433a3b9817
commit
6682f127f1
2 changed files with 4 additions and 39 deletions
|
@ -6,9 +6,7 @@ import multiprocessing as mp
|
||||||
import sys
|
import sys
|
||||||
|
|
||||||
from logging.handlers import SysLogHandler
|
from logging.handlers import SysLogHandler
|
||||||
|
from uncloud.configure.main import configure_parser
|
||||||
from ucloud.common.logging import NoTracebackStreamHandler
|
|
||||||
from ucloud.configure.main import configure_parser
|
|
||||||
|
|
||||||
|
|
||||||
def exception_hook(exc_type, exc_value, exc_traceback):
|
def exception_hook(exc_type, exc_value, exc_traceback):
|
||||||
|
@ -31,13 +29,7 @@ if __name__ == '__main__':
|
||||||
syslog_formatter = logging.Formatter('%(pathname)s:%(lineno)d -- %(levelname)-8s %(message)s')
|
syslog_formatter = logging.Formatter('%(pathname)s:%(lineno)d -- %(levelname)-8s %(message)s')
|
||||||
syslog_handler.setFormatter(syslog_formatter)
|
syslog_handler.setFormatter(syslog_formatter)
|
||||||
|
|
||||||
stream_handler = NoTracebackStreamHandler()
|
|
||||||
stream_handler.setLevel(logging.INFO)
|
|
||||||
stream_formatter = logging.Formatter('%(message)s')
|
|
||||||
stream_handler.setFormatter(stream_formatter)
|
|
||||||
|
|
||||||
logger.addHandler(syslog_handler)
|
logger.addHandler(syslog_handler)
|
||||||
logger.addHandler(stream_handler)
|
|
||||||
|
|
||||||
arg_parser = argparse.ArgumentParser()
|
arg_parser = argparse.ArgumentParser()
|
||||||
subparsers = arg_parser.add_subparsers(dest="command")
|
subparsers = arg_parser.add_subparsers(dest="command")
|
||||||
|
@ -72,7 +64,7 @@ if __name__ == '__main__':
|
||||||
arguments = vars(args)
|
arguments = vars(args)
|
||||||
try:
|
try:
|
||||||
name = arguments.pop('command')
|
name = arguments.pop('command')
|
||||||
mod = importlib.import_module("ucloud.{}.main".format(name))
|
mod = importlib.import_module("uncloud.{}.main".format(name))
|
||||||
main = getattr(mod, "main")
|
main = getattr(mod, "main")
|
||||||
main(**arguments)
|
main(**arguments)
|
||||||
except Exception as err:
|
except Exception as err:
|
||||||
|
|
|
@ -1,27 +0,0 @@
|
||||||
import logging
|
|
||||||
import colorama
|
|
||||||
|
|
||||||
|
|
||||||
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 in ["WARNING", "WARN"]:
|
|
||||||
color = colorama.Fore.LIGHTYELLOW_EX
|
|
||||||
elif record.levelname == "ERROR":
|
|
||||||
color = colorama.Fore.LIGHTRED_EX
|
|
||||||
elif record.levelname == "INFO":
|
|
||||||
color = colorama.Fore.LIGHTGREEN_EX
|
|
||||||
elif record.levelname == "CRITICAL":
|
|
||||||
color = colorama.Fore.LIGHTCYAN_EX
|
|
||||||
else:
|
|
||||||
color = colorama.Fore.WHITE
|
|
||||||
|
|
||||||
try:
|
|
||||||
print(color, end="", flush=True)
|
|
||||||
super().handle(record)
|
|
||||||
finally:
|
|
||||||
record.exc_info = info
|
|
||||||
record.exc_text = cache
|
|
||||||
print(colorama.Style.RESET_ALL, end="", flush=True)
|
|
Loading…
Reference in a new issue