From ddb080861df8bb6bf706a2a7303553c84ebf2c30 Mon Sep 17 00:00:00 2001
From: Tamino Huxohl <thuxohl@techfak.uni-bielefeld.de>
Date: Fri, 21 Oct 2022 15:04:33 +0200
Subject: [PATCH] logging handles creation of multiple loggers with the same
 name correctly

---
 mu_map/logging.py | 8 ++++++--
 1 file changed, 6 insertions(+), 2 deletions(-)

diff --git a/mu_map/logging.py b/mu_map/logging.py
index fa12909..b1178b6 100644
--- a/mu_map/logging.py
+++ b/mu_map/logging.py
@@ -51,6 +51,10 @@ def rotate_log_file(filename: str):
 def get_logger(logfile: Optional[str] = None, loglevel: Optional[str] = None, name: Optional[str] = None):
     logger = getLogger() if name is None else getLogger(name)
 
+    if logger.hasHandlers():
+        # logger alrady exists, so refrain from adding more handlers
+        return logger
+
     if loglevel:
         _level = getattr(logging, loglevel)
         logger.setLevel(_level)
@@ -84,14 +88,14 @@ class LogLine:
 
 def parse_line(logline):
     _split = logline.strip().split("-")
-    assert len(_split) >= 3, f"A logged line should consists of a least three elements with the format [TIME - LOGLEVEL - MESSAGE] but got [{logline.strip()}]"
+    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()}]"
 
     time_str = _split[0].strip()
     time = datetime.strptime(time_str, date_format)
 
     loglevel = _split[1].strip()
 
-    message = "-".join(_split[2:]).strip()
+    message = "-".join(_split[3:]).strip()
     return LogLine(time=time, loglevel=loglevel, message=message)
 
 def parse_file(logfile: str) -> List[LogLine]:
-- 
GitLab