title: pipe python logging stdout stream output to grep
body: <p>I knew the reason for this a while back but I have since forgotten and 5 mins of googling hasn't revealed the answer. </p>
  
  <p>I have written a python script which has two handlers. One for files and one for streams. </p>
  
  <p>Everything works as I want.</p>
  
  <p>Now, I wanted to quickly grep for something in the output that was being printed to the terminal  but piping the script's output through grep doesn't appear to be working in that all of the output still get's printed to the terminal. </p>
  
  <p>I am using unix and python 2.7</p>
  
  <p>This is probably a duplicate question but I can't find the answer. </p>
  
  <p>Here's my setup of the logging module:</p>
  
  <pre><code>def setup_logger(verbosity):
      #logger = logging.getLogger(regress.app_name)
      logger = logging.getLogger('components')
      logger.setLevel(logging.DEBUG)
      # create file handler which logs even debug messages
      fh = logging.FileHandler(Config.logging_file_name, mode='w')
      fh.setLevel(logging.DEBUG)
      # create console handler with a higher log level
      ch = logging.StreamHandler()
      ch.setLevel({True:logging.DEBUG, False:logging.INFO}[verbosity])
      # create formatter and add it to the handlers
      file_formatter = logging.Formatter('%(asctime)s - %(pathname)s - %(funcName)s - %(name)s - %(levelname)s - %(lineno)s - %(message)s')
  
      console_formatter = logging.Formatter('%(filename)s - %(lineno)s - %(levelname)s - %(message)s')
      fh.setFormatter(file_formatter)
      ch.setFormatter(console_formatter)
      # add the handlers to the logger
      logger.addHandler(fh)
      logger.addHandler(ch)
  
      #logging.abort = abort
      #logging.abort("testing...")
      #logger.info("does this happen?")
  
      #logging.func = func
      #logging.func()
      #logger.func()
  </code></pre>
  
  <p>My invocation of the script looks like this:</p>
  
  <p><code>&lt;script_name&gt; &lt;script args&gt; | grep -i &lt;search_string&gt;</code></p>