title: Print python stdout to stdout
body: <p>This is a little tricky to explain, so I apologize in advance.</p>
  
  <p>I have a command line application written in Python. It logs to stderr and stdout; the logging filters are configured as follows:</p>
  
  <pre><code>class StdErrFilter(logging.Filter):
      def filter(self,record):
          return 1 if record.levelno &gt;= 30 else 0
  
  class StdOutFilter(logging.Filter):
      def filter(self,record):
          return 1 if record.levelno &lt;= 20 and record.levelno &gt; 10 else 0 
  </code></pre>
  
  <p>and the function that sets up logging looks like this:</p>
  
  <pre><code>def setup_logging(logger_name):
      logger = logging.getLogger(logger_name)
      logger.setLevel(logging.DEBUG)
  
      formatter = logging.Formatter(fmt=LOG_FMT)
  
      err_handler = logging.StreamHandler(sys.__stderr__)
      err_handler.addFilter(StdErrFilter())
      err_handler.setFormatter(formatter)
      logger.addHandler(err_handler)
  
      out_handler = logging.StreamHandler(sys.__stdout__)
      out_handler.addFilter(StdOutFilter())
      out_handler.setFormatter(formatter)
      logger.addHandler(out_handler)
  
      return logger
  </code></pre>
  
  <p>When the application is invoked directly it works as I'd expect, i.e. <code>info()</code> and below print to stdout, and <code>warn()</code> and above print to stderr. However, when the exact same call is made inside a bash script, info and below don't print to the terminal, but stderr still works as expected. I can make the script pipe stdout to a file, but not to the terminal. Any ideas what's going on?</p>
  
  <p><strong>EDIT</strong> I should have shown the bash script as well. There's some other logic related to the building the args for the Python app in there, but the actual call is near the bottom in the <code>for</code> loop. Note that the Python app is an executable module.</p>
  
  <pre><code>#!/bin/bash
  
  # provide one argument, the directory to search for ".xml" files.
  dir_to_index=$1
  
  FIND=/usr/bin/find
  PYTHON=/usr/bin/python
  
  SOLR="http://localhost:8983/solr/pul-development" 
  
  BIN="$( cd "$( dirname "${BASH_SOURCE[0]}" )" &amp;&amp; pwd )"
  
  marc_to_solr=$BIN/../marc_to_solr
  PYTHONPATH=$marc_to_solr:$PYTHONPATH
  
  db_config=$BIN/../etc/database.ini
  config=db_config=$BIN/../etc/config.ini
  
  for f in `$FIND $dir_to_index -name "*.xml"`; do
      echo "File: $f"
      cmd="$PYTHON -m marc_to_solr -d $db_config -s $SOLR -c etc/config.ini -i $f"
      `$cmd`
  done
  </code></pre>