Skip to content
Snippets Groups Projects
Commit ff0bc30c authored by Tamino Huxohl's avatar Tamino Huxohl
Browse files

modify logging to work with old and new format

parent d19afe1c
No related branches found
No related tags found
No related merge requests found
......@@ -86,22 +86,22 @@ class LogLine:
return f"{self.time.strftime(date_format)} - {self.loglevel:>7} - {self.message}"
def parse_line(logline):
def parse_line(logline, start_idx_message=3):
_split = logline.strip().split("-")
assert len(_split) >= 4, f"A logged line should consists of a least four elements with the format [TIME - LOGLEVEL - MESSAGE] but got [{logline.strip()}]"
assert len(_split) >= start_idx_message, f"A logged line should consists of a least {start_idx_message} elements with the format [TIME - LOGLEVEL - ... - MESSAGE] but got [{logline.strip()}]"
time_str = _split[0].strip()
time = datetime.strptime(time_str, date_format)
loglevel = _split[1].strip()
message = "-".join(_split[3:]).strip()
message = "-".join(_split[start_idx_message:]).strip()
return LogLine(time=time, loglevel=loglevel, message=message)
def parse_file(logfile: str) -> List[LogLine]:
def parse_file(logfile: str, start_idx_message: int = 3) -> List[LogLine]:
with open(logfile, mode="r") as f:
lines = f.readlines()
lines = map(parse_line, lines)
lines = map(lambda line: parse_line(line, start_idx_message), lines)
return list(lines)
if __name__ == "__main__":
......
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