Skip to content

Instantly share code, notes, and snippets.

@hackersoup
Created January 29, 2017 21:59
Show Gist options
  • Save hackersoup/2833c4eccd8e77f09540422fbb64a2d1 to your computer and use it in GitHub Desktop.
Save hackersoup/2833c4eccd8e77f09540422fbb64a2d1 to your computer and use it in GitHub Desktop.
class Log:
WARNING = '[-]'
ERROR = '[!]'
INFO = '[*]'
GOOD = '[+]'
class Color:
# Regular colors
BLACK = '\033[30m'
RED = '\033[31m'
GREEN = '\033[32m'
YELLOW = '\033[33m'
BLUE = '\033[34m'
MAGENTA = '\033[35m'
CYAN = '\033[36m'
L_GRAY = '\033[37m'
DARK_GRAY = '\033[90m'
# Default term color
DEFAULT = '\033[39m'
# Light colors
L_RED = '\033[91m'
L_GREEN = '\033[92m'
L_YELLOW = '\033[93m'
L_BLUE = '\033[94m'
L_MAGENTA = '\033[95m'
L_CYAN = '\033[96m'
WHITE = '\033[97m'
def log(level, message):
if level == Log.INFO:
print level + ' ' + message
elif level == Log.ERROR:
print '{}{} {}{}'.format(Color.RED, level, message, Color.DEFAULT)
elif level == Log.WARNING:
print '{}{} {}{}'.format(Color.YELLOW, level, message, Color.DEFAULT)
elif level == Log.GOOD:
print '{}{} {}{}'.format(Color.GREEN, level, message, Color.DEFAULT)
else:
print '{}{} {}{}'.format(Color.L_MAGENTA, '[?]', message, Color.DEFAULT)
log(Log.WARNING, "This is just a test")
log(Log.ERROR, "The cake is a lie")
log(Log.INFO, "Contact with the test floor results in failure, followed by death.")
log(Log.GOOD, "I love you.")
log("WASD", "Unrecognized log level")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment