repos / ops

infra for pico services
git clone https://github.com/picosh/ops.git

commit
0f8c002
parent
f30b32f
author
Eric Bower
date
2024-10-04 14:11:03 +0000 UTC
feat: log print script
1 files changed,  +30, -0
A scripts/log-print-script.py
+30, -0
 1@@ -0,0 +1,30 @@
 2+import sys
 3+import json
 4+
 5+def main():
 6+    for line in sys.stdin:
 7+        try:
 8+            parsed = json.loads(line)
 9+            msg = parsed["msg"]
10+            user = ""
11+            if "user" in parsed:
12+                user = parsed["user"]
13+            host = ""
14+            if "host" in parsed:
15+                host = parsed["host"]
16+            url = ""
17+            if "url" in parsed:
18+                url = parsed["url"]
19+            status = ""
20+            if "status" in parsed:
21+                status = parsed["status"]
22+            err = ""
23+            if "err" in parsed:
24+                err = parsed["err"]
25+            print(f"{parsed['time']}\t{parsed['level']}\t{user}\t{parsed['service']}\t{msg}\t{err}\t{status}\t{host}\t{url}")
26+        except Exception as err:
27+            print(line)
28+            print("err parsing json", err)
29+
30+if __name__ == "__main__":
31+    main()