Eric Bower
·
04 Oct 24
log-print-script.py
1import sys
2import json
3
4def main():
5 for line in sys.stdin:
6 try:
7 parsed = json.loads(line)
8 msg = parsed["msg"]
9 user = ""
10 if "user" in parsed:
11 user = parsed["user"]
12 host = ""
13 if "host" in parsed:
14 host = parsed["host"]
15 url = ""
16 if "url" in parsed:
17 url = parsed["url"]
18 status = ""
19 if "status" in parsed:
20 status = parsed["status"]
21 err = ""
22 if "err" in parsed:
23 err = parsed["err"]
24 print(f"{parsed['time']}\t{parsed['level']}\t{user}\t{parsed['service']}\t{msg}\t{err}\t{status}\t{host}\t{url}")
25 except Exception as err:
26 print(line)
27 print("err parsing json", err)
28
29if __name__ == "__main__":
30 main()