Skip to content

Instantly share code, notes, and snippets.

@willkg
Created April 19, 2019 13:57
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save willkg/7331563d4ecaf18a042d151f0b07f71f to your computer and use it in GitHub Desktop.
Save willkg/7331563d4ecaf18a042d151f0b07f71f to your computer and use it in GitHub Desktop.
make mozlog human readable
!/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