@@ -0,0 +1,2017 @@
+import logging%0Aimport sys%0A%0ABLACK, RED, GREEN, YELLOW, BLUE, MAGENTA, CYAN, WHITE = range(8)%0A%0ACOLORS = %7B%0A    'WARNING': YELLOW,%0A    'INFO': WHITE,%0A    'DEBUG': BLUE,%0A    'CRITICAL': RED,%0A    'ERROR': RED,%0A    'FATAL': RED,%0A%7D%0A%0ARESET_SEQ = %22%5C033%5B0m%22%0ACOLOR_SEQ = %22%5C033%5B1;%25dm%22%0ABOLD_SEQ = %22%5C033%5B1m%22%0A%0ABASE_COLOR_FORMAT = %22%25(asctime)s %25(process)d%5C%0A %5B$BOLD%25(name)s$RESET%5D%5B%25(color_levelname)-17s%5D %25(message)s%22%0A%0ABASE_FORMAT = %22%25(asctime)s %25(process)d %5B%25(name)s%5D%5B%25(levelname)-6s%5D %25(message)s%22%0A%0A%0Adef supports_color():%0A    %22%22%22%0A    Returns True if the running system's terminal supports color, and False%0A    otherwise.%0A    %22%22%22%0A    unsupported_platform = (sys.platform in ('win32', 'Pocket PC'))%0A    # isatty is not always implemented%0A    is_a_tty = hasattr(sys.stdout, 'isatty') and sys.stdout.isatty()%0A    if unsupported_platform or not is_a_tty:%0A        return False%0A    return True%0A%0A%0Adef color_message(message):%0A    message = message.replace(%22$RESET%22, RESET_SEQ).replace(%22$BOLD%22, BOLD_SEQ)%0A    return message%0A%0A%0Aclass ColoredFormatter(logging.Formatter):%0A    %22%22%22%0A    A very basic logging formatter that not only applies color to the levels of%0A    the ouput but will also truncate the level names so that they do not alter%0A    the visuals of logging when presented on the terminal.%0A    %22%22%22%0A%0A    def __init__(self, msg):%0A        logging.Formatter.__init__(self, msg)%0A%0A    def format(self, record):%0A        levelname = record.levelname%0A        truncated_level = record.levelname%5B:6%5D%0A        levelname_color = COLOR_SEQ %25 (30 + COLORS%5Blevelname%5D) + truncated_level + RESET_SEQ%0A        record.color_levelname = levelname_color%0A        return logging.Formatter.format(self, record)%0A%0A%0Adef color_format():%0A    %22%22%22%0A    Main entry point to get a colored formatter, it will use the%0A    BASE_FORMAT by default and fall back to no colors if the system%0A    does not support it%0A    %22%22%22%0A    str_format = BASE_COLOR_FORMAT if supports_color() else BASE_FORMAT%0A    color_format = color_message(str_format)%0A    return ColoredFormatter(color_format)%0A

create a module with logging utilities