From 28d4db569461c9a79be4b8971a6f69087eb63546 Mon Sep 17 00:00:00 2001 From: Mark Veidemanis Date: Sun, 6 Mar 2022 12:10:02 +0000 Subject: [PATCH] Clean up colored logging --- handler/util.py | 26 ++------------------------ 1 file changed, 2 insertions(+), 24 deletions(-) diff --git a/handler/util.py b/handler/util.py index 6e7a738..c906b68 100644 --- a/handler/util.py +++ b/handler/util.py @@ -6,11 +6,9 @@ import logging log = logging.getLogger("util") +# Color definitions BLACK, RED, GREEN, YELLOW, BLUE, MAGENTA, CYAN, WHITE = range(8) - -# The background is set with 40 plus the number of the color, and the foreground with 30 - -# These are the sequences need to get colored ouput +COLORS = {"WARNING": YELLOW, "INFO": WHITE, "DEBUG": BLUE, "CRITICAL": YELLOW, "ERROR": RED} RESET_SEQ = "\033[0m" COLOR_SEQ = "\033[1;%dm" BOLD_SEQ = "\033[1m" @@ -24,9 +22,6 @@ def formatter_message(message, use_color=True): return message -COLORS = {"WARNING": YELLOW, "INFO": WHITE, "DEBUG": BLUE, "CRITICAL": YELLOW, "ERROR": RED} - - class ColoredFormatter(logging.Formatter): def __init__(self, msg, use_color=True): logging.Formatter.__init__(self, msg) @@ -63,22 +58,6 @@ def get_logger(name): return log -class ColoredLogger(logging.Logger): - FORMAT = "[$BOLD%(name)-20s$RESET][%(levelname)-18s] %(message)s ($BOLD%(filename)s$RESET:%(lineno)d)" - COLOR_FORMAT = formatter_message(FORMAT, True) - - def __init__(self, name): - logging.Logger.__init__(self, name, logging.DEBUG) - - color_formatter = ColoredFormatter(self.COLOR_FORMAT) - - console = logging.StreamHandler() - console.setFormatter(color_formatter) - - self.addHandler(console) - return - - class Base(object): def __init__(self): name = self.__class__.__name__ @@ -130,7 +109,6 @@ def last_online_recent(date): date_parsed = datetime.strptime(date, "%Y-%m-%dT%H:%M:%S.%fZ") now = datetime.now() sec_ago_date = (now - date_parsed).total_seconds() - # self.log.debug("Seconds ago date for {date} ^ {now}: {x}", date=date, now=str(now), x=sec_ago_date) return sec_ago_date < 172800