from termcolor import colored __all__ = ['log', 'warn', 'err', 'TestsError'] class TestsError(Exception): pass COLORS = { 'question': colored('[?]', 'yellow'), 'info': colored('[~]', 'green'), 'warning': colored('[!]', 'magenta'), 'error': colored('[X]', 'red'), } def warn(msg): log(msg, log_lvl='w') def err(msg): log(msg, log_lvl='e') def log(msg, log_lvl='i'): for lvl, text in COLORS.items(): if lvl.startswith(log_lvl): print(f'{text} {msg}') break else: ValueError('Unknown log level')