title: Python logging (logutils) with QueueHandler and QueueListener
body: <p>Logging is needed for a multiprocess python app. Using queues appears to be the best solution. The logutils library provides this.</p>
  
  <p>Is it possible to set the log levels for two handler independently? For example, in the test below I would like STREAM 1 to have WARNING messages and STREAM 2 to have INFO messages. In the test log at the end of the code an INFO message is created that should not output to the console from STREAM 1 handler (WARNING). However, it outputs to both handlers.</p>
  
  <p>For reference, I have been using this page <a href="http://plumberjack.blogspot.co.uk/2010/09/improved-queuehandler-queuelistener.html" rel="noreferrer">http://plumberjack.blogspot.co.uk/2010/09/improved-queuehandler-queuelistener.html</a> by Vinay Sajip who is the author of the library.</p>
  
  <pre><code># System imports
  import logging
  import logging.handlers
  try:
      import Queue as queue
  except ImportError:
      import queue
  
  # Custom imports
  from logutils.queue import QueueHandler, QueueListener
  
  # Get queue
  q = queue.Queue(-1)
  
  # Setup stream handler 1 to output WARNING to console
  h1 = logging.StreamHandler()
  f1 = logging.Formatter('STREAM 1 WARNING: %(threadName)s: %(message)s')
  h1.setFormatter(f1)
  h1.setLevel(logging.WARNING) # NOT WORKING. This should log &gt;= WARNING
  
  # Setup stream handler 2 to output INFO to console
  h2 = logging.StreamHandler()
  f2 = logging.Formatter('STREAM 2 INFO: %(threadName)s: %(message)s')
  h2.setFormatter(f2)
  h2.setLevel(logging.INFO) # NOT WORKING. This should log &gt;= WARNING
  
  # Start queue listener using the stream handler above
  ql = QueueListener(q, h1, h2)
  ql.start()
  
  # Create log and set handler to queue handle
  root = logging.getLogger()
  root.setLevel(logging.DEBUG) # Log level = DEBUG
  qh = QueueHandler(q)
  root.addHandler(qh)
  
  root.info('Look out!') # Create INFO message
  
  ql.stop()
  </code></pre>