How do I ensure all git output is sent to a log file when called via Python?
<p>Part of my code:</p>

<pre><code>import subprocess
import logging
logging.basicConfig(filename='daily_backup_run.log', level=logging.DEBUG)

try:
  git_command = subprocess.Popen("git status", shell="true")
  git_status_output = git_command.stdout.readline()
except subprocess.CalledProcessError, e:
  git_status_output = e.output
logging.debug(' Output of git status: ' + git_status_output)
exit()
</code></pre>

<p>When I attempt to run this, my output is:</p>

<pre><code>[~/experiment_folder]# python git.py
Traceback (most recent call last):
  File "git.py", line 35, in ?
    except subprocess.CalledProcessError, e:
AttributeError: 'module' object has no attribute 'CalledProcessError'
fatal: Not a git repository (or any of the parent directories): .git
</code></pre>

<p>I am not concerned with the Python errors at the moment, but I need <em>all</em> output sent by git to go into the daily_backup_run.log - even the <code>fatal: Not a repo</code> error. How do I ensure this?</p>
