2019-12-23 07:58:04 +00:00
|
|
|
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
|
|
|
|
|
2019-12-30 09:35:07 +00:00
|
|
|
if record.levelname in ["WARNING", "WARN"]:
|
2019-12-29 18:14:39 +00:00
|
|
|
color = colorama.Fore.LIGHTYELLOW_EX
|
2019-12-30 09:35:07 +00:00
|
|
|
elif record.levelname == "ERROR":
|
2019-12-23 07:58:04 +00:00
|
|
|
color = colorama.Fore.LIGHTRED_EX
|
2019-12-30 09:35:07 +00:00
|
|
|
elif record.levelname == "INFO":
|
2019-12-29 18:14:39 +00:00
|
|
|
color = colorama.Fore.LIGHTGREEN_EX
|
2019-12-30 09:35:07 +00:00
|
|
|
elif record.levelname == "CRITICAL":
|
2019-12-29 18:14:39 +00:00
|
|
|
color = colorama.Fore.LIGHTCYAN_EX
|
2019-12-23 07:58:04 +00:00
|
|
|
else:
|
|
|
|
color = colorama.Fore.WHITE
|
2019-12-29 18:14:39 +00:00
|
|
|
|
2019-12-23 07:58:04 +00:00
|
|
|
try:
|
2019-12-30 09:35:07 +00:00
|
|
|
print(color, end="", flush=True)
|
2019-12-23 07:58:04 +00:00
|
|
|
super().handle(record)
|
|
|
|
finally:
|
|
|
|
record.exc_info = info
|
|
|
|
record.exc_text = cache
|
2019-12-30 09:35:07 +00:00
|
|
|
print(colorama.Style.RESET_ALL, end="", flush=True)
|