title: Logging to file and console with different handlers and formats
body: <p>I would like to have:</p>
  
  <ul>
  <li>a <em>main.log</em> file with all logs above DEBUG level to be captured from main and imported modules</li>
  <li>the console should show only ERROR level logs from main and its imported submodules. 
  
  <ul>
  <li>Note: I may have <em>no control on the error handling logs</em> of the imported submodules.</li>
  </ul></li>
  </ul>
  
  <p>Here is the <em>main.py</em> code for this:</p>
  
  <pre><code># main.py importing a submodule
  import logging
  
  import submodule
  
  logger = logging.getLogger(__name__)
  logger.setLevel(logging.DEBUG)
  
  # log to console
  c_handler = logging.StreamHandler()
  
  console_format = logging.Formatter("[%(levelname)s] %(message)s")
  c_handler.setFormatter(console_format)
  c_handler.setLevel = logging.INFO
  
  logger.addHandler(c_handler)
  
  logger.error("This is an error!!! Logged to console")
  
  # log to file from main
  logfile = "./logging/main.log"
  
  f_handler = logging.FileHandler(filename=logfile)
  
  f_format = logging.Formatter("%(asctime)s: %(name)-18s [%(levelname)-8s] %(message)s")
  f_handler.setFormatter(f_format)
  f_handler.setLevel = logging.DEBUG
  
  logger.addHandler(f_handler)
  
  logger.debug("This is a debug error. Not logged to console, but should log to file")
  </code></pre>
  
  <p>... and the <em>submodule.py</em> code ...</p>
  
  <pre><code># submodule.py
  import logging
  
  logger = logging.getLogger(__name__)
  logger.setLevel(logging.INFO)
  
  formatter = logging.Formatter('%(levelname)s:%(name)s:%(message)s')
  
  # log to console
  c_handler = logging.StreamHandler()
  c_handler.setFormatter(formatter)
  logger.addHandler(c_handler)
  
  logger.info("This is an info message from submodule, should be recorded in main.log!")
  logger.debug("This is a debug message from submodule, also should be recorded in main.log!!")
  </code></pre>
  
  <p>When I run <em>main.py</em>:</p>
  
  <ul>
  <li><code>[ERROR] This is an error!!! Logged to console</code> shows up correctly in the console</li>
  <li>But...
  
  <ul>
  <li>Console also shows...
  
  <ul>
  <li><code>INFO:submodule:This is an info message from submodule, should be recorded in main.log!</code> </li>
  <li><code>[DEBUG] This is a debug error. Not logged to console, but should log to file</code></li>
  </ul></li>
  <li>The <code>main.log file</code> only shows <code>yy-mm-dd hh:mm:ss: __main__           [DEBUG   ] This is a debug error. Not logged to console, but should log to file</code> only. It does not show logs from the submodule.py</li>
  </ul></li>
  </ul>
  
  <p>Appreciate knowing:</p>
  
  <ul>
  <li>Where am I going wrong?</li>
  <li>What would be the code correction needed?</li>
  </ul>
  
  <p><strong>EDIT:</strong> Based on @Dan D. suggestion changed <em>submodule.py</em> as follows:</p>
  
  <pre><code># submodule.py
  import logging
  
  logger = logging.getLogger(__name__)
  
  def logsomething():
      logger.info("This is an info message from submodule, should be recorded in main.log!")
      logger.debug("This is a debug message from submodule, also should be recorded in main.log!!")
  </code></pre>
  
  <p>... and the program logs to console and file appropriately.</p>
  
  <p>Q. If I want to change to message format for the <em>submodule.py</em> only, can this be done through <em>main.py</em>?</p>