title: Printing to STDOUT and log file while removing ANSI color codes
body: <p>I have the following functions for colorizing my screen messages:</p>
  
  <pre><code>def error(string):
      return '\033[31;1m' + string + '\033[0m'
  
  def standout(string):
      return '\033[34;1m' + string + '\033[0m'
  </code></pre>
  
  <p>I use them as follows:</p>
  
  <pre><code>print error('There was a problem with the program')
  print "This is normal " + standout("and this stands out")
  </code></pre>
  
  <p>I want to log the output to a file (in addition to STDOUT) WITHOUT the ANSI color codes, hopefully without having to add a second "logging" line to each <code>print</code> statement.</p>
  
  <p>The reason is that if you simply <code>python program.py &gt; out</code> then the file <code>out</code> will have the ANSI color codes, which look terrible if you open in a plain text editor.</p>
  
  <p>Any advice?</p>