if - elif
instead of the if - elif statements, use dict.get(key, default):
formatting = {
1: Color('{green}[GOOD]{/green}'),
2: Color('{cyan}[INFO]{/cyan}'),
3: Color('{yellow}[LOW]{/yellow}'),
4: Color('{magenta}[MEDIUM]{/magenta}'),
5: Color('{red}[HIGH]{/red}'),
6: Color('{red}[!!CRITICAL!!]{/red}'),
}
leader = formatting.get(severity, '[#]')
String formatting
if you use Python >= 3.6, use f-strings.
And instead of the long list of arguments, split it up in lines. I would at least refactor the strftime("%H:%M:%S", gmtime()) into a variable called time:
message = f'[{time}] [{self.domain}] {leader} {message}'
print(message)
if you also have to serve pre-3.6, this solution:
format_args = {
'time': strftime("%H:%M:%S", gmtime()),
'domain': self.domain,
'leader': leader,
'message': message,
}
template = '[{time}] [{self.domain}] {leader} {message}'
print(template.format(**format_args))
can help you limit the line length, while keeping the template clear.