Skip to content

Instantly share code, notes, and snippets.

@mxchinegod
Last active June 8, 2023 14:09
Show Gist options
  • Save mxchinegod/955694a8f87ba9aa769e1c6aef8bad31 to your computer and use it in GitHub Desktop.
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
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