diff options
-rwxr-xr-x | errors2csv.py | 28 |
1 files changed, 28 insertions, 0 deletions
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) |