Skip to content
Snippets Groups Projects
Commit 9c2debab authored by Tamas Gal's avatar Tamas Gal :speech_balloon:
Browse files

Add gzip support for log analyser

parent 1bd6dc59
No related branches found
No related tags found
1 merge request!32Add gzip support for log analyser
Unreleased changes
------------------
* `log_analyser.py` now also parses gzipped log files
Version 2
---------
2.2.3 / 2022-11-20
~~~~~~~~~~~~~~~~~~
* Updates dependencies: km3pipe==9.13.5 which fixes the issue with the
......
......@@ -4,6 +4,7 @@
# Author: Tamas Gal <tgal@km3net.de>
# vim: ts=4 sw=4 et
from collections import defaultdict
import gzip
import sys
import re
import numpy as np
......@@ -75,9 +76,16 @@ def process_log_file(log_file):
"""
summary = defaultdict(lambda: defaultdict(int))
if log_file.endswith(".gz"):
opener = gzip.open
filemode = "rt"
else:
opener = open
filemode = "r"
n_lines_parsed = 0
n_lines_unparsed = 0
with open(log_file, "r") as fobj:
with opener(log_file, filemode) as fobj:
lines_chunk = fobj.readlines(BUFFER_SIZE)
while lines_chunk:
for line in lines_chunk:
......@@ -118,11 +126,11 @@ def process_log_file(log_file):
def main():
log_dir = "/logs/"
regexp = "^MSG_(.+)\.log$"
regexp = "^MSG_(.+)\.log"
while True:
for fname in os.listdir(log_dir):
plot_fpath = os.path.join(log_dir, os.path.splitext(fname)[0] + ".png")
plot_fpath = os.path.join(log_dir, os.path.splitext(fname.replace(".gz", ""))[0] + ".png")
log_fpath = os.path.join(log_dir, fname)
if re.match(regexp, fname) and not os.path.exists(plot_fpath):
print("-> Processing ", fname)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment