Created
April 19, 2019 13:57
-
-
Save willkg/7331563d4ecaf18a042d151f0b07f71f to your computer and use it in GitHub Desktop.
make mozlog human readable
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
!/usr/bin/env python | |
""" | |
This de-mozlogifies a log line by line to make it readable by humans. To use: | |
tail -f /path/to/mozlog.log | python demozlog.py | |
""" | |
import datetime | |
import json | |
import sys | |
SEVERITY = { | |
2: 'CRITICAL', | |
3: 'ERROR', | |
4: 'WARNING', | |
6: 'INFO', | |
7: 'DEBUG', | |
} | |
def ts_to_str(ts): | |
ts = float(ts) / 1e9 | |
return datetime.datetime.fromtimestamp(ts).isoformat() | |
while True: | |
line = sys.stdin.readline() | |
try: | |
data = json.loads(line) | |
print('%s %s %s: %s' % (ts_to_str(data['Timestamp']), SEVERITY[data['Severity']], data['Type'], data['Fields']['msg'])) | |
if data['Fields'].get('error'): | |
print('%s %s' % (data['Fields']['error'], data['Fields']['traceback'])) | |
except Exception: | |
if line: | |
print('sputter %s' % line) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment