Skip to content

Instantly share code, notes, and snippets.

@sapamja
Created July 10, 2014 16:43
Show Gist options
  • Select an option

  • Save sapamja/48205ac7c9e3f75eae16 to your computer and use it in GitHub Desktop.

Select an option

Save sapamja/48205ac7c9e3f75eae16 to your computer and use it in GitHub Desktop.
print color base on the level
class ColorScreen:
red = '\033[91m'
null = '\033[0m'
green = '\033[92m'
yellow = '\033[93m'
cyan = "\033[36m"
magenta = "\033[35m"
light_red = "\033[1;31m"
def __init__(self):
pass
from functools import partial
def log_template(level, msg):
color = {'INFO': 'green',
'WARNING': 'yellow',
'ERROR': 'red',
'NOTIFY': 'magenta'}[level]
if not isinstance(msg, str):
print("{}: {}".format(level, str(msg)), file=stdout)
else:
print(getattr(ColorScreen, color) + "%s: %s" % (level, msg) + ColorScreen.null, file=stdout)
ok = partial(log_template, "INFO")
error = partial(log_template, "ERROR")
warning = partial(log_template, "WARNING")
notify = partial(log_template, "NOTIFY")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment