I have the following Python output class that I'm planning to use across a number of modules in a terminal application:
from colorclass import Color
from colorclass import disable_all_colors, enable_all_colors, is_enabled
from time import gmtime, strftime
class OutputHelper(object):
def __init__(self, color, domain):
if color:
disable_all_colors()
self.domain = domain
def Terminal(self, severity, message):
leader = ''
if severity == 1:
leader = Color('{green}[GOOD]{/green}')
elif severity == 2:
leader = Color('{cyan}[INFO]{/cyan}')
elif severity == 3:
leader = Color('{yellow}[LOW]{/yellow}')
elif severity == 4:
leader = Color('{magenta}[MEDIUM]{/magenta}')
elif severity == 5:
leader = Color('{red}[HIGH]{/red}')
elif severity == 6:
leader = Color('{red}[!!CRITICAL!!]{/red}')
else:
leader = '[#]'
print('[{}] [{}] {} {}'.format(strftime("%H:%M:%S", gmtime()), self.domain, leader, message))
The idea being that one module can raise multiple messages for a single domain. So usage would be similar to:
output = OutputHelper(arguments.nocolor, arguments.domains)
output.Terminal(1, 'All dependencies up to date')
output.Terminal(6, "Cryptojacking script identified: aaaa")
I'm sure there's better ways to design this, but I don't know what I don't know, and I'd value input and guidance!