From d9d13e4dfb040f6fb11b4cb48b4dbab81b765fd5 Mon Sep 17 00:00:00 2001 From: Mischa Untaga <99098079+MischaU8@users.noreply.github.com> Date: Wed, 17 Apr 2024 12:33:36 +0200 Subject: convert error log to csv --- errors2csv.py | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) create mode 100755 errors2csv.py diff --git a/errors2csv.py b/errors2csv.py new file mode 100755 index 0000000..3f18d0a --- /dev/null +++ b/errors2csv.py @@ -0,0 +1,28 @@ +#!/usr/bin/env python3 +import csv +import shlex + +unique_errors = set() + +with open('errors.txt', 'r') as f, open('errors.csv', 'w', newline='') as csvfile: + fieldnames = ['ERROR', 'MSG', 'STACK', 'STEP', 'ACTIVE', 'STATE', 'ACTION', 'ARGS', 'SETUP', 'DATA', 'DUMP'] + key_fieldsnames = ['ERROR', 'STATE', 'MSG'] + writer = csv.DictWriter(csvfile, fieldnames=fieldnames) + writer.writeheader() + + for line in f.readlines(): + line = line.strip() + if line.startswith("Loading"): + continue + # print(line) + data = {} + for keyval in shlex.split(line): + # print(keyval) + key, val = keyval.split("=", 2) + # print("key", key) + # print("val", val) + data[key] = val + error_key = "_".join([data.get(key, '') for key in key_fieldsnames]) + if error_key not in unique_errors: + unique_errors.add(error_key) + writer.writerow(data) -- cgit v1.2.3