-BLACK, RED, GREEN, YELLOW, BLUE, MAGENTA, CYAN, WHITE, _NOTHING, DEFAULT = range(10)
-#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
-RESET_SEQ = "\033[0m"
-COLOR_SEQ = "\033[1;%dm"
-BOLD_SEQ = "\033[1m"
-COLOR_PATTERN = "%s%s%%s%s" % (COLOR_SEQ, COLOR_SEQ, RESET_SEQ)
-LEVEL_COLOR_MAPPING = {
- logging.DEBUG_SQL: (WHITE, MAGENTA),
- logging.DEBUG_RPC: (BLUE, WHITE),
- logging.DEBUG: (BLUE, DEFAULT),
- logging.INFO: (GREEN, DEFAULT),
- logging.TEST: (WHITE, BLUE),
- logging.WARNING: (YELLOW, DEFAULT),
- logging.ERROR: (RED, DEFAULT),
- logging.CRITICAL: (WHITE, RED),
-}
-
-class DBFormatter(logging.Formatter):
- def format(self, record):
- record.dbname = getattr(threading.current_thread(), 'dbname', '?')
- return logging.Formatter.format(self, record)
-
-class ColoredFormatter(DBFormatter):
- def format(self, record):
- fg_color, bg_color = LEVEL_COLOR_MAPPING[record.levelno]
- record.levelname = COLOR_PATTERN % (30 + fg_color, 40 + bg_color, record.levelname)
- return DBFormatter.format(self, record)
-