Commit b9042604 authored by Tjerk Vreeken's avatar Tjerk Vreeken

Check if root logger already has loggers

If users provide a logger to the root logger, do not add an extra one
(which will just result in messages being print out twice).

Typical way to set a root logger is logging.basicConfig(format='...')
parent 01550d14
......@@ -50,7 +50,7 @@ def run_optimization_problem(optimization_problem_class, base_folder='..', log_l
logger.addHandler(handler)
# Add stream handler if it does not already exist.
if not any((isinstance(h, logging.StreamHandler) for h in logger.handlers)):
if not logger.hasHandlers() and not any((isinstance(h, logging.StreamHandler) for h in logger.handlers)):
handler = logging.StreamHandler()
formatter = logging.Formatter('%(asctime)s %(levelname)s %(message)s')
handler.setFormatter(formatter)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment