def configure_logging(log_level, cli_args): root_logger = logging.getLogger().logger console_logger = logging.StreamHandler(sys.stdout) console_format = '%(levelname)s: @%(name)s : %(message)s' if sh.in_terminal(): console_logger.setFormatter(colorlog.TermFormatter(console_format)) else: console_logger.setFormatter(logging.Formatter(console_format)) root_logger.addHandler(console_logger) root_logger.setLevel(log_level)
def color_text(text, color, bold=False, underline=False, blink=False, always_color=False): text_attrs = list() if bold: text_attrs.append('bold') if underline: text_attrs.append('underline') if blink: text_attrs.append('blink') if sh.in_terminal() or always_color: return termcolor.colored(text, color, attrs=text_attrs) else: return text
def configure_logging(verbosity_level=1, dry_run=False): # Debug by default root_logger = logging.getLogger().logger root_logger.setLevel(logging.DEBUG) # Set our pretty logger console_logger = logging.StreamHandler(sys.stdout) console_format = '%(levelname)s: @%(name)s : %(message)s' if sh.in_terminal(): console_logger.setFormatter(colorlog.TermFormatter(console_format)) else: console_logger.setFormatter(logging.Formatter(console_format)) root_logger.addHandler(console_logger) # Adjust logging verbose level based on the command line switch. log_level = logging.INFO if verbosity_level >= 3: log_level = logging.DEBUG elif verbosity_level == 2 or dry_run: log_level = logging.AUDIT root_logger.setLevel(log_level)