Created
July 10, 2014 16:43
-
-
Save sapamja/48205ac7c9e3f75eae16 to your computer and use it in GitHub Desktop.
print color base on the level
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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