Created
May 8, 2019 15:17
-
-
Save mnakama/b1d6920704fb6ed2c1f1005f3b67b3bc to your computer and use it in GitHub Desktop.
This file contains 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
#!/bin/python3 | |
import json | |
import sys | |
import traceback | |
# termcolor available via pypi | |
try: | |
from termcolor import colored | |
except Exception as e: | |
print(e, file=sys.stderr) | |
sevColor = { | |
'info': 'cyan', | |
'INFO': 'cyan', | |
'DEBUG': 'blue', | |
'WARN': 'yellow', | |
'ERROR': 'red', | |
} | |
def main(): | |
while True: | |
try: | |
line = input() | |
except EOFError: | |
return | |
try: | |
data = json.loads(line) | |
except ValueError as e: | |
print(line) | |
except: | |
traceback.print_exc() | |
else: | |
sev = data.get('severity') | |
text = '{:>5s}: {}'.format( | |
sev, | |
data.get('message', data.get('msg', line)), | |
) | |
try: | |
color = sevColor.get(sev, 'white') | |
print(colored(text, color)) | |
except (KeyError, NameError): | |
print(text) | |
if __name__ == '__main__': | |
main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment