Clean up colored logging
This commit is contained in:
parent
34a182cbf5
commit
28d4db5694
|
@ -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
|
||||
|
||||
|
||||
|
|
Loading…
Reference in New Issue