title: Python logger - multiple logger instances with multiple levels - best practice
body: <p>I have the following requirements:</p>
  
  <ol>
  <li>To have one global logger which you can configure (setup level, additional handlers,..)</li>
  <li>To have per module logger which you can configure (setup level, additional handlers,..)</li>
  </ol>
  
  <p>In other words we need more logs with different configuration</p>
  
  <p>Therefore I did the following</p>
  
  <ol>
  <li>create method to setup logger:</li>
  </ol>
  
  <pre><code>def setup_logger(module_name=None, level=logging.INFO, add_stdout_logger=True):
  
     print("Clear all loggers")
     for _handler in logging.root.handlers:
         logging.root.removeHandler(_handler)
  
     if add_stdout_logger:
         print("Add stdout logger")
         stdout_handler = logging.StreamHandler(sys.stdout)
         stdout_handler.setLevel(level)
         stdout_handler.setFormatter(logging.Formatter(fmt='%(asctime)-11s [%(levelname)s] [%(name)s] %(message)s'))
         logging.root.addHandler(stdout_handler)
  
  
     print("Set root level log")
     logging.root.setLevel(level)
  
     if module_name:
         return logging.getLogger(module_name)
     else:
         return logging.getLogger('global')
  </code></pre>
  
  <p>Then I create logger as following:</p>
  
  <pre><code>logger_global = setup_logger(level=logging.DEBUG)
  logger_module_1 = setup_logger(module_name='module1', level=logging.INFO)
  logger_module_2 = setup_logger(module_name='module2', level=logging.DEBUG)
  
  logger_global.debug("This is global log and will be visible because it is setup to DEBUG log")
  
  logger_module_1.debug("This is logger_module_1 log and will NOT be visible because it is setup to INFO log") 
  
  logger_module_2.debug("This is logger_module_2 log and will be visible because it is setup to DEBUG log")
  </code></pre>
  
  <p>Before I will try what works and what not and test it more deeply I want to ask you if this is good practice to do it or do you have any other recommendation how to achieve our requrements?</p>
  
  <p>Thanks for help </p>