ソースを参照

Prevent setting the default logger multiple times

This would result in each log line being printed multiple times.

Signed-off-by: Stan Janssen <stan.janssen@elaad.nl>
Stan Janssen 4 年 前
コミット
b14cff5497
1 ファイル変更7 行追加5 行削除
  1. 7 5
      openleadr/__init__.py

+ 7 - 5
openleadr/__init__.py

@@ -30,8 +30,10 @@ def enable_default_logging(level=logging.INFO):
     import sys
     import logging
     logger = logging.getLogger('openleadr')
-    logger.setLevel(level)
-
-    logging_handler = logging.StreamHandler(stream=sys.stdout)
-    logging_handler.setLevel(logging.DEBUG)
-    logger.addHandler(logging_handler)
+    handler_names = [handler.name for handler in logger.handlers]
+    if 'openleadr_default_handler' not in handler_names:
+        logger.setLevel(level)
+        logging_handler = logging.StreamHandler(stream=sys.stdout)
+        logging_handler.set_name('openleadr_default_handler')
+        logging_handler.setLevel(logging.DEBUG)
+        logger.addHandler(logging_handler)