Last active
June 8, 2023 14:09
-
-
Save mxchinegod/955694a8f87ba9aa769e1c6aef8bad31 to your computer and use it in GitHub Desktop.
Convenient Error wrapper for any Python code where supervised error context is strings
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
def fancy_message(tag, body): | |
tags = [ | |
("FATAL", "☠️", "\033[91m"), # Red color for FATAL | |
("WARN", "🚨", "\033[93m"), # Yellow color for WARN | |
("INFO", "ℹ️", "\033[94m"), # Blue color for INFO | |
("WAIT", "☕️", "\033[96m") # Cyan color for WAIT | |
] | |
matching_tags = [x for x in tags if x[0] == tag.upper()] | |
if matching_tags: | |
tag_text = matching_tags[0][0] | |
emoji = matching_tags[0][1] | |
color_code = matching_tags[0][2] | |
print(f'{color_code}{emoji} {tag_text}: {body}\033[0m') # Reset color after the text | |
else: | |
print(f'Unknown tag: {tag}') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment