Commit c34e33a7 authored by Roman Alifanov's avatar Roman Alifanov

made the log colorful

parent f0e11b51
...@@ -27,10 +27,30 @@ import gettext ...@@ -27,10 +27,30 @@ import gettext
import logging import logging
class ColorFormatter(logging.Formatter):
COLORS = {
'DEBUG': '\033[36m',
'INFO': '\033[32m',
'WARNING': '\033[33m',
'ERROR': '\033[31m',
'CRITICAL': '\033[37;41m'
}
RESET = '\033[0m'
def format(self, record):
color = self.COLORS.get(record.levelname, '')
message = super().format(record)
return f"{color}{message}{self.RESET}"
handler = logging.StreamHandler()
handler.setFormatter(ColorFormatter(
fmt="%(asctime)s | %(levelname)-8s | %(name)s | %(message)s",
datefmt="%Y-%m-%d %H:%M:%S"
))
logging.basicConfig( logging.basicConfig(
level=logging.DEBUG, level=logging.DEBUG,
format="%(asctime)s | %(levelname)-8s | %(name)s | %(message)s", handlers=[handler]
datefmt="%Y-%m-%d %H:%M:%S",
) )
pkgdatadir = '@pkgdatadir@' pkgdatadir = '@pkgdatadir@'
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment