summaryrefslogtreecommitdiff
path: root/bin/analyze-log.py
diff options
context:
space:
mode:
authorBirte Kristina Friesel <birte.friesel@uos.de>2023-12-11 10:39:38 +0100
committerBirte Kristina Friesel <birte.friesel@uos.de>2023-12-11 10:39:38 +0100
commit5adc034a6945065c0fc3dd5991936d0741a17d7d (patch)
tree85358818d56d0a097eb6c302ef2bf8eebcb68dcc /bin/analyze-log.py
parent13b9dfaad26758fca3b673c5e64ee266db82568c (diff)
move text log parser to util; add text log writer
Diffstat (limited to 'bin/analyze-log.py')
-rwxr-xr-xbin/analyze-log.py53
1 files changed, 4 insertions, 49 deletions
diff --git a/bin/analyze-log.py b/bin/analyze-log.py
index 55fc2db..80690fc 100755
--- a/bin/analyze-log.py
+++ b/bin/analyze-log.py
@@ -18,61 +18,16 @@ import sys
import re
-def kv_to_param(kv_str, cast):
- try:
- key, value = kv_str.split("=")
- value = cast(value)
- return key, value
- except ValueError:
- print(f"Invalid key-value pair: {kv_str}")
- raise
-
-
-def kv_to_param_f(kv_str):
- return kv_to_param(kv_str, dfatool.utils.soft_cast_float)
-
-
-def kv_to_param_i(kv_str):
- return kv_to_param(kv_str, dfatool.utils.soft_cast_int)
-
-
def parse_logfile(filename):
+ lf = dfatool.utils.Logfile()
+
if filename.endswith("xz"):
import lzma
with lzma.open(filename, "rt") as f:
- return parse_loghandle(f)
+ return lf.load(f)
with open(filename, "r") as f:
- return parse_loghandle(f)
-
-
-def parse_loghandle(handle):
- observations = list()
- for lineno, line in enumerate(handle):
- m = re.search(r"\[::\] *([^|]*?) *[|] *([^|]*?) *[|] *(.*)", line)
- if m:
- name_str = m.group(1)
- param_str = m.group(2)
- attr_str = m.group(3)
- try:
- param = dict(map(kv_to_param_i, param_str.split()))
- attr = dict(map(kv_to_param_f, attr_str.split()))
- observations.append(
- {
- "name": name_str,
- "param": param,
- "attribute": attr,
- }
- )
- except ValueError:
- print(
- f"Error parsing {filename}: invalid key-value pair in line {lineno+1}",
- file=sys.stderr,
- )
- print(f"Offending entry:\n{line}", file=sys.stderr)
- raise
-
- return observations
+ return lf.load(f)
def main():