Improve color scheme

This commit is contained in:
Kristóf Tóth 2019-07-04 17:27:25 +02:00
parent dc62508a7b
commit f6a369496d

View File

@ -7,13 +7,12 @@ from logging import DEBUG, getLogger, Handler, Formatter, Filter
class Color:
GREY = '\033[30;1m'
RED = '\033[31m'
BOLDRED = '\033[31;1m'
BOLDGREEN = '\033[32;1m'
YELLOW = '\033[33;1m'
GREEN = '\033[32m'
YELLOW = '\033[33m'
BLUE = '\033[34m'
CYAN = '\033[36m'
BOLDWHITE = '\033[37;1m'
WHITE = '\033[37m'
RESET = '\033[0m'
@ -67,11 +66,11 @@ class LogHandler(Handler):
class LogFormatter(Formatter):
severity_to_color = {
'CRITICAL' : Color.BOLDRED,
'CRITICAL' : Color.RED,
'ERROR' : Color.RED,
'WARNING' : Color.YELLOW,
'INFO' : Color.BOLDGREEN,
'DEBUG' : Color.BOLDWHITE,
'INFO' : Color.GREEN,
'DEBUG' : Color.BLUE,
'NOTSET' : Color.CYAN
}
@ -80,7 +79,7 @@ class LogFormatter(Formatter):
super().__init__()
def format(self, record):
date = datetime.utcfromtimestamp(record.created).strftime('%H:%M:%S')
time = datetime.utcfromtimestamp(record.created).strftime('%H:%M:%S')
if record.args:
tuple_args = (record.args,) if isinstance(record.args, dict) else record.args
clean_args = tuple((self.trim(arg) for arg in tuple_args))
@ -89,7 +88,7 @@ class LogFormatter(Formatter):
message = record.msg
trace = '\n'+''.join(format_exception(*record.exc_info)) if record.exc_info else ''
return (f'[{Color.GREY}{date}{Color.RESET}|>'
return (f'[{Color.WHITE}{time}{Color.RESET}|>'
f'{self.severity_to_color[record.levelname]}{record.module}:'
f'{record.levelname.lower()}{Color.RESET}] {message}{trace}')