mirror of
https://github.com/avatao-content/baseimage-tutorial-framework
synced 2024-11-22 18:31:33 +00:00
Improve color scheme
This commit is contained in:
parent
dc62508a7b
commit
f6a369496d
@ -7,14 +7,13 @@ from logging import DEBUG, getLogger, Handler, Formatter, Filter
|
|||||||
|
|
||||||
|
|
||||||
class Color:
|
class Color:
|
||||||
GREY = '\033[30;1m'
|
RED = '\033[31m'
|
||||||
RED = '\033[31m'
|
GREEN = '\033[32m'
|
||||||
BOLDRED = '\033[31;1m'
|
YELLOW = '\033[33m'
|
||||||
BOLDGREEN = '\033[32;1m'
|
BLUE = '\033[34m'
|
||||||
YELLOW = '\033[33;1m'
|
CYAN = '\033[36m'
|
||||||
CYAN = '\033[36m'
|
WHITE = '\033[37m'
|
||||||
BOLDWHITE = '\033[37;1m'
|
RESET = '\033[0m'
|
||||||
RESET = '\033[0m'
|
|
||||||
|
|
||||||
|
|
||||||
@dataclass
|
@dataclass
|
||||||
@ -67,11 +66,11 @@ class LogHandler(Handler):
|
|||||||
|
|
||||||
class LogFormatter(Formatter):
|
class LogFormatter(Formatter):
|
||||||
severity_to_color = {
|
severity_to_color = {
|
||||||
'CRITICAL' : Color.BOLDRED,
|
'CRITICAL' : Color.RED,
|
||||||
'ERROR' : Color.RED,
|
'ERROR' : Color.RED,
|
||||||
'WARNING' : Color.YELLOW,
|
'WARNING' : Color.YELLOW,
|
||||||
'INFO' : Color.BOLDGREEN,
|
'INFO' : Color.GREEN,
|
||||||
'DEBUG' : Color.BOLDWHITE,
|
'DEBUG' : Color.BLUE,
|
||||||
'NOTSET' : Color.CYAN
|
'NOTSET' : Color.CYAN
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -80,7 +79,7 @@ class LogFormatter(Formatter):
|
|||||||
super().__init__()
|
super().__init__()
|
||||||
|
|
||||||
def format(self, record):
|
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:
|
if record.args:
|
||||||
tuple_args = (record.args,) if isinstance(record.args, dict) else 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))
|
clean_args = tuple((self.trim(arg) for arg in tuple_args))
|
||||||
@ -89,7 +88,7 @@ class LogFormatter(Formatter):
|
|||||||
message = record.msg
|
message = record.msg
|
||||||
trace = '\n'+''.join(format_exception(*record.exc_info)) if record.exc_info else ''
|
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'{self.severity_to_color[record.levelname]}{record.module}:'
|
||||||
f'{record.levelname.lower()}{Color.RESET}] {message}{trace}')
|
f'{record.levelname.lower()}{Color.RESET}] {message}{trace}')
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user